java.lang.Object
gov.nih.mipav.view.renderer.WildMagic.ProstateFramework.liblinearsvm.Linear

public class Linear extends Object
Copyright (c) 2007-2014 The LIBLINEAR Project. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither name of copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Java port of liblinear 1.51

The usage should be pretty similar to the C version of liblinear.

Please consider reading the README file of liblinear.

The port was done by Benedikt Waldvogel (mail at bwaldvogel.de)

Version:
1.51
  • Field Details

    • FILE_CHARSET

      public static final Charset FILE_CHARSET
    • DEFAULT_LOCALE

      static final Locale DEFAULT_LOCALE
    • OUTPUT_MUTEX

      private static Object OUTPUT_MUTEX
    • DEBUG_OUTPUT

      private static PrintStream DEBUG_OUTPUT
    • NL

      static final String NL
      platform-independent new-line string
    • DEFAULT_RANDOM_SEED

      private static final long DEFAULT_RANDOM_SEED
      See Also:
    • random

      static Random random
  • Constructor Details

    • Linear

      public Linear()
  • Method Details

    • crossValidation

      public static void crossValidation(Problem prob, Parameter param, int nr_fold, int[] target)
      Parameters:
      target - predicted classes
    • groupClasses

      private static Linear.GroupClassesReturn groupClasses(Problem prob, int[] perm)
    • info

      static void info(String message)
    • info

      static void info(String format, Object... args)
    • atof

      public static double atof(String s)
      Parameters:
      s - the string to parse for the double value
      Throws:
      IllegalArgumentException - if s is empty or represents NaN or Infinity
      NumberFormatException - see Double.parseDouble(String)
    • atoi

      public static int atoi(String s) throws NumberFormatException
      Parameters:
      s - the string to parse for the integer value
      Throws:
      IllegalArgumentException - if s is empty
      NumberFormatException - see Integer.parseInt(String)
    • copyOf

      public static double[] copyOf(double[] original, int newLength)
      Java5 'backport' of Arrays.copyOf
    • copyOf

      public static int[] copyOf(int[] original, int newLength)
      Java5 'backport' of Arrays.copyOf
    • loadModel

      public static Model loadModel(Reader inputReader) throws IOException
      Loads the model from inputReader. It uses
      invalid reference
      Locale.ENGLISH
      for number formatting.

      Note: The inputReader is closed after reading or in case of an exception.

      Throws:
      IOException
    • loadModel

      public static Model loadModel(File modelFile) throws IOException
      Loads the model from the file with ISO-8859-1 charset. It uses
      invalid reference
      Locale.ENGLISH
      for number formatting.
      Throws:
      IOException
    • closeQuietly

      static void closeQuietly(Closeable c)
    • predict

      public static int predict(Model model, FeatureNode[] x)
    • predictProbability

      public static int predictProbability(Model model, FeatureNode[] x, double[] prob_estimates)
    • predictValues

      public static int predictValues(Model model, FeatureNode[] x, double[] dec_values)
    • printf

      static void printf(Formatter formatter, String format, Object... args) throws IOException
      Throws:
      IOException
    • saveModel

      public static void saveModel(Writer modelOutput, Model model) throws IOException
      Writes the model to the modelOutput. It uses
      invalid reference
      Locale.ENGLISH
      for number formatting.

      Note: The modelOutput is closed after reading or in case of an exception.

      Throws:
      IOException
    • saveModel

      public static void saveModel(File modelFile, Model model) throws IOException
      Writes the model to the file with ISO-8859-1 charset. It uses
      invalid reference
      Locale.ENGLISH
      for number formatting.
      Throws:
      IOException
    • GETI

      private static int GETI(byte[] y, int i)
    • solve_l2r_l1l2_svc

      private static void solve_l2r_l1l2_svc(Problem prob, double[] w, double eps, double Cp, double Cn, SolverType solver_type)
      A coordinate descent algorithm for L1-loss and L2-loss SVM dual problems
        min_\alpha  0.5(\alpha^T (Q + D)\alpha) - e^T \alpha,
          s.t.      0 invalid input: '<'= alpha_i invalid input: '<'= upper_bound_i,
      
        where Qij = yi yj xi^T xj and
        D is a diagonal matrix
      
       In L1-SVM case:
           upper_bound_i = Cp if y_i = 1
            upper_bound_i = Cn if y_i = -1
            D_ii = 0
       In L2-SVM case:
            upper_bound_i = INF
            D_ii = 1/(2*Cp) if y_i = 1
            D_ii = 1/(2*Cn) if y_i = -1
      
       Given:
       x, y, Cp, Cn
       eps is the stopping tolerance
      
       solution will be put in w
      
    • solve_l1r_l2_svc

      private static void solve_l1r_l2_svc(Problem prob_col, double[] w, double eps, double Cp, double Cn)
      A coordinate descent algorithm for L1-regularized L2-loss support vector classification
        min_w \sum |wj| + C \sum max(0, 1-yi w^T xi)^2,
      
       Given:
       x, y, Cp, Cn
       eps is the stopping tolerance
      
       solution will be put in w
      
    • solve_l1r_lr

      private static void solve_l1r_lr(Problem prob_col, double[] w, double eps, double Cp, double Cn)
      A coordinate descent algorithm for L1-regularized logistic regression problems
        min_w \sum |wj| + C \sum log(1+exp(-yi w^T xi)),
      
       Given:
       x, y, Cp, Cn
       eps is the stopping tolerance
      
       solution will be put in w
      
    • transpose

      static Problem transpose(Problem prob)
    • swap

      static void swap(double[] array, int idxA, int idxB)
    • swap

      static void swap(int[] array, int idxA, int idxB)
    • swap

      static void swap(IntArrayPointer array, int idxA, int idxB)
    • train

      public static Model train(Problem prob, Parameter param)
      Throws:
      IllegalArgumentException - if the feature nodes of prob are not sorted in ascending order
    • train_one

      private static void train_one(Problem prob, Parameter param, double[] w, double Cp, double Cn)
    • disableDebugOutput

      public static void disableDebugOutput()
    • enableDebugOutput

      public static void enableDebugOutput()
    • setDebugOutput

      public static void setDebugOutput(PrintStream debugOutput)
    • resetRandom

      public static void resetRandom()
      resets the PRNG this is i.a. needed for regression testing (eg. the Weka wrapper)