Class SVM

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class SVM
    extends AlgorithmBase
    • Constructor Detail

      • SVM

        public SVM()
    • Method Detail

      • learn_linear_SVM_on_double_data

        public void learn_linear_SVM_on_double_data()
      • vl_svmdataset_new

        public SVM.VlSvmDataset vl_svmdataset_new​(double[] data,
                                                  int dimension,
                                                  int numData)
        Parameters:
        dataType - of data (@c float and @c double supported).
        data - pointer to the data.
        dimension - the dimension of a data vector.
        numData - number of wrapped data vectors.
        Returns:
        new object. The function allocates and returns a new SVM dataset object wrapping the data pointed by @a data. Note that no copy is made of data, so the caller should keep the data allocated as the object exists.
      • vl_svm_new_with_dataset

        public SVM.VlSvm vl_svm_new_with_dataset​(SVM.VlSvmSolverType solver,
                                                 SVM.VlSvmDataset dataset,
                                                 double[] labels,
                                                 double lambda)
        Parameters:
        solver - type of SMV solver.
        dataset - SVM dataset object
        labels - training samples labels.
        lambda - regularizer parameter.
        Returns:
        the new object.
      • vl_homogeneouskernelmap_get_dimension

        public int vl_homogeneouskernelmap_get_dimension​(SVM.VlHomogeneousKernelMap self)
        Parameters:
        self - object.
        Returns:
        the map dimension (2 @c order +1).
      • vl_svmdataset_get_dimension

        public int vl_svmdataset_get_dimension​(SVM.VlSvmDataset self)
        Parameters:
        self - object.
        Returns:
        dimension of the wrapped data.
      • vl_svmdataset_get_num_data

        public int vl_svmdataset_get_num_data​(SVM.VlSvmDataset self)
        Parameters:
        self - object.
        Returns:
        number of wrapped data elements.
      • vl_svmdataset_get_inner_product_function

        public int vl_svmdataset_get_inner_product_function​(SVM.VlSvmDataset self)
        Parameters:
        self - object.
        Returns:
        a pointer to the inner product function to use with this data.
      • vl_svmdataset_get_accumulate_function

        public int vl_svmdataset_get_accumulate_function​(SVM.VlSvmDataset self)
        Parameters:
        self - object.
        Returns:
        a pointer to the accumulate function to use with this data.
      • vl_svm_new_with_abstract_data

        public SVM.VlSvm vl_svm_new_with_abstract_data​(SVM.VlSvmSolverType solver,
                                                       SVM.VlSvmDataset data,
                                                       int dimension,
                                                       int numData,
                                                       double[] labels,
                                                       double lambda)
        Parameters:
        solver - type of SMV solver.
        data - pointer to the data.
        dimension - dimension of the SVM model.
        numData - num training samples.
        labels - training samples labels.
        lambda - regularizer parameter.
        Returns:
        the new object. After calling this function, ::vl_svm_set_data_functions *must* be used to setup suitable callbacks for the inner product and accumulation operations (@see svm-data-abstraction).
      • vl_svm_set_data_functions

        public void vl_svm_set_data_functions​(SVM.VlSvm self,
                                              int inner,
                                              int acc)
        Parameters:
        self - object.
        inner - inner product function.
        acc - accumulate function. See @ref svm-data-abstraction.
      • vl_svm_train

        public void vl_svm_train​(SVM.VlSvm self)
        Parameters:
        self - object. The data on which the SVM operates is passed upon the cration of the ::VlSvm object. This function runs a solver to learn a corresponding model. See @ref svm-starting.
      • _vl_svm_sdca_train

        public void _vl_svm_sdca_train​(SVM.VlSvm self)
      • vl_rand_permute_indexes

        public void vl_rand_permute_indexes​(java.util.Random self,
                                            int[] array,
                                            int size)
        Parameters:
        self - random number generator.
        array - array of indexes.
        size - number of element in the array. The function uses *Algorithm P*, also known as *Knuth shuffle*.
      • accumulateFunction

        public void accumulateFunction​(int acc,
                                       SVM.VlSvmDataset self,
                                       int element,
                                       double[] model,
                                       double multiplier)
      • vl_svmdataset_accumulate

        public void vl_svmdataset_accumulate​(SVM.VlSvmDataset self,
                                             int element,
                                             double[] model,
                                             double multiplier)
      • vl_svmdataset_accumulate_hom

        public void vl_svmdataset_accumulate_hom​(SVM.VlSvmDataset self,
                                                 int element,
                                                 double[] model,
                                                 double multiplier)
      • vl_homogeneouskernelmap_evaluate

        public void vl_homogeneouskernelmap_evaluate​(SVM.VlHomogeneousKernelMap self,
                                                     double[] destination,
                                                     int stride,
                                                     double x)
      • frexp

        public double frexp​(double x,
                            int[] exponent)
      • inner_productFunction

        public double inner_productFunction​(int inp,
                                            SVM.VlSvmDataset self,
                                            int element,
                                            double[] model)
      • vl_svmdataset_inner_product

        public double vl_svmdataset_inner_product​(SVM.VlSvmDataset self,
                                                  int element,
                                                  double[] model)
      • vl_svmdataset_inner_product_hom

        public double vl_svmdataset_inner_product_hom​(SVM.VlSvmDataset self,
                                                      int element,
                                                      double[] model)
      • dca_updateFunction

        public double dca_updateFunction​(int update,
                                         double alpha,
                                         double inner,
                                         double norm2,
                                         double label)
      • vl_svm_hinge_dca_update

        public double vl_svm_hinge_dca_update​(double alpha,
                                              double inner,
                                              double norm2,
                                              double label)
      • vl_svm_hinge2_dca_update

        public double vl_svm_hinge2_dca_update​(double alpha,
                                               double inner,
                                               double norm2,
                                               double label)
      • vl_svm_l1_dca_update

        public double vl_svm_l1_dca_update​(double alpha,
                                           double inner,
                                           double norm2,
                                           double label)
      • vl_svm_l2_dca_update

        public double vl_svm_l2_dca_update​(double alpha,
                                           double inner,
                                           double norm2,
                                           double label)
      • vl_svm_logistic_dca_update

        public double vl_svm_logistic_dca_update​(double alpha,
                                                 double inner,
                                                 double norm2,
                                                 double label)
      • _vl_svm_update_statistics

        public void _vl_svm_update_statistics​(SVM.VlSvm self)
        Parameters:
        self - object.
      • lossFunction

        public double lossFunction​(int loss,
                                   double inner,
                                   double label)
      • vl_svm_hinge_loss

        public double vl_svm_hinge_loss​(double inner,
                                        double label)
      • vl_svm_hinge2_loss

        public double vl_svm_hinge2_loss​(double inner,
                                         double label)
      • vl_svm_l1_loss

        public double vl_svm_l1_loss​(double inner,
                                     double label)
      • vl_svm_l2_loss

        public double vl_svm_l2_loss​(double inner,
                                     double label)
      • vl_svm_logistic_loss

        public double vl_svm_logistic_loss​(double inner,
                                           double label)
      • conjugate_lossFunction

        public double conjugate_lossFunction​(int loss,
                                             double u,
                                             double label)
      • vl_svm_hinge_conjugate_loss

        public double vl_svm_hinge_conjugate_loss​(double u,
                                                  double label)
        Parameters:
        u - dual variable.
        label - label value.
        Returns:
        conjugate loss.
      • vl_svm_hinge2_conjugate_loss

        public double vl_svm_hinge2_conjugate_loss​(double u,
                                                   double label)
      • vl_svm_l1_conjugate_loss

        public double vl_svm_l1_conjugate_loss​(double u,
                                               double label)
      • vl_svm_l2_conjugate_loss

        public double vl_svm_l2_conjugate_loss​(double u,
                                               double label)
      • xlogx

        public double xlogx​(double x)
      • vl_svm_logistic_conjugate_loss

        public double vl_svm_logistic_conjugate_loss​(double u,
                                                     double label)
      • _vl_svm_sgd_train

        void _vl_svm_sgd_train​(SVM.VlSvm self)
      • loss_derivativeFunction

        public double loss_derivativeFunction​(int loss,
                                              double inner,
                                              double label)
      • vl_svm_hinge_loss_derivative

        public double vl_svm_hinge_loss_derivative​(double inner,
                                                   double label)
      • vl_svm_hinge2_loss_derivative

        public double vl_svm_hinge2_loss_derivative​(double inner,
                                                    double label)
      • vl_svm_l1_loss_derivative

        public double vl_svm_l1_loss_derivative​(double inner,
                                                double label)
      • vl_svm_l2_loss_derivative

        public double vl_svm_l2_loss_derivative​(double inner,
                                                double label)
      • vl_svm_logistic_loss_derivative

        public double vl_svm_logistic_loss_derivative​(double inner,
                                                      double label)
      • _vl_svm_evaluate

        public void _vl_svm_evaluate​(SVM.VlSvm self)
      • vl_svm_get_model

        public double[] vl_svm_get_model​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        model. This is the weight vector $\bw$.
      • vl_svm_get_bias

        public double vl_svm_get_bias​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        bias $b$. The value of the bias returned already include the effect of bias mutliplier.
      • vl_svm_delete

        public void vl_svm_delete​(SVM.VlSvm self)
        Parameters:
        self - object.
      • vl_svmdataset_delete

        void vl_svmdataset_delete​(SVM.VlSvmDataset self)
        Parameters:
        self - object to delete. The function frees the resources allocated by ::vl_svmdataset_new(). Notice that the wrapped data will *not* be freed as it is not owned by the object.
      • Dan_Ventura_sgd_linear_example

        public void Dan_Ventura_sgd_linear_example()
      • Dan_Ventura_sgd_nonlinear_example

        public void Dan_Ventura_sgd_nonlinear_example()
      • Dan_Ventura_sdca_linear_example

        public void Dan_Ventura_sdca_linear_example()
      • Dan_Ventura_sdca_nonlinear_example

        public void Dan_Ventura_sdca_nonlinear_example()
      • test_sgd_basic

        public void test_sgd_basic()
      • test_sdca_basic

        public void test_sdca_basic()
      • test_weights

        public void test_weights()
      • test_homkermap

        public void test_homkermap()
      • vl_svmtrain

        public void vl_svmtrain​(double[] model,
                                double[] bias,
                                double[] scores,
                                double[][] data,
                                SVM.VlSvmDataset dataset,
                                double[] labels,
                                double lambda,
                                SVM.VlSvmSolverType solver,
                                double biasMultiplier,
                                double biasLearningRate,
                                int maxNumIterations,
                                double epsilon,
                                SVM.VlSvmLossType loss,
                                boolean verbose,
                                double[] initialModel,
                                double initialBias,
                                double[] weights,
                                int startingIteration,
                                int diagnosticFrequency)
      • vl_homogeneouskernelmap_delete

        public void vl_homogeneouskernelmap_delete​(SVM.VlHomogeneousKernelMap self)
        Parameters:
        self - object. The function deletes the specified map object.
      • vl_svmdataset_set_homogeneous_kernel_map

        public void vl_svmdataset_set_homogeneous_kernel_map​(SVM.VlSvmDataset self,
                                                             SVM.VlHomogeneousKernelMap hom)
        Parameters:
        self - object.
        hom - homogeneous kernel map object to use. After changing the kernel map, the inner product and accumulator function should be queried again (::vl_svmdataset_get_inner_product_function adn ::vl_svmdataset_get_accumulate_function). Set this to @c NULL to avoid using a kernel map. Note that this does *not* transfer the ownership of the object to the function. Furthermore, ::VlSvmDataset holds to the object until it is destroyed or the object is replaced or removed by calling this function again.
      • vl_svmdataset_get_homogeneous_kernel_map

        public SVM.VlHomogeneousKernelMap vl_svmdataset_get_homogeneous_kernel_map​(SVM.VlSvmDataset self)
        Parameters:
        self - object.
        Returns:
        homogeneous kernel map object (or @c NULL if any).
      • vl_svm_get_scores

        public double[] vl_svm_get_scores​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        vector of scores. After training or during the diagnostic callback, this function can be used to retrieve the scores of the points, i.e. $\langle \bx_i, \bw \rangle + b$.
      • vl_svm_get_bias_learning_rate

        public double vl_svm_get_bias_learning_rate​(SVM.VlSvm self)
        Parameters:
        self - object
        Returns:
        bias learning rate.
      • vl_svm_get_diagnostic_frequency

        public int vl_svm_get_diagnostic_frequency​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        diagnostic frequency.
      • vl_svm_get_epsilon

        public double vl_svm_get_epsilon​(SVM.VlSvm self)
        Parameters:
        self - object
        Returns:
        epsilon threshold.
      • vl_svm_get_max_num_iterations

        public int vl_svm_get_max_num_iterations​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        maximum number of iterations.
      • vl_svm_get_num_data

        public int vl_svm_get_num_data​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        model number of data samples This is the dimensionality of the weight vector $\bw$.
      • vl_svm_get_dimension

        public int vl_svm_get_dimension​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        model dimension. This is the dimensionality of the weight vector $\bw$.
      • vl_svm_set_model

        void vl_svm_set_model​(SVM.VlSvm self,
                              double[] model)
        Parameters:
        self - object.
        model - model. The function *copies* the content of the vector @a model to the internal model buffer. This operation can be used for warm start with the SGD algorithm, but has undefined effect with the SDCA algorithm.
      • vl_svm_set_bias

        public void vl_svm_set_bias​(SVM.VlSvm self,
                                    double b)
        Parameters:
        self - object.
        b - bias. The function set the internal representation of the SVM bias to be equal to @a b (the bias multiplier is applied). The same remark that applies to ::vl_svm_set_model applies here too.
      • vl_svm_set_epsilon

        public void vl_svm_set_epsilon​(SVM.VlSvm self,
                                       double epsilon)
        Parameters:
        self - object
        epsilon - threshold (non-negative).
      • vl_svm_set_max_num_iterations

        public void vl_svm_set_max_num_iterations​(SVM.VlSvm self,
                                                  int n)
        Parameters:
        self - object.
        n - maximum number of iterations.
      • vl_svm_set_bias_multiplier

        public void vl_svm_set_bias_multiplier​(SVM.VlSvm self,
                                               double b)
        Parameters:
        self - object
        b - bias multiplier. The *bias multiplier* is the value of the constant feature appended to the data vectors to implement the bias (@ref svm-bias).
      • vl_svm_set_bias_learning_rate

        public void vl_svm_set_bias_learning_rate​(SVM.VlSvm self,
                                                  double rate)
        Parameters:
        self - object
        rate - bias learning rate (positive). This parameter applies only to the SGD solver.
      • vl_svm_set_diagnostic_frequency

        public void vl_svm_set_diagnostic_frequency​(SVM.VlSvm self,
                                                    int f)
        Parameters:
        self - object.
        f - diagnostic frequency (@c >= 1). A diagnostic round (to test for convergence and to printout information) is performed every @a f iterations.
      • vl_svm_set_iteration_number

        public void vl_svm_set_iteration_number​(SVM.VlSvm self,
                                                int n)
        Parameters:
        self - object.
        n - iteration number. If called before training, this can be used with SGD for a warm start, as the net effect is to slow down the learning rate.
      • vl_svm_set_weights

        public void vl_svm_set_weights​(SVM.VlSvm self,
                                       double[] weights)
        Parameters:
        self - object.
        weights - data weights.
      • vl_svm_set_loss_function

        public void vl_svm_set_loss_function​(SVM.VlSvm self,
                                             int f)
        Parameters:
        self - object.
        f - loss function callback. Note that setting up a loss requires specifying more than just one callback. See @ref svm-loss-functions for details.
      • vl_svm_set_loss_derivative_function

        public void vl_svm_set_loss_derivative_function​(SVM.VlSvm self,
                                                        int f)
      • vl_svm_set_conjugate_loss_function

        public void vl_svm_set_conjugate_loss_function​(SVM.VlSvm self,
                                                       int f)
      • vl_svm_set_dca_update_function

        public void vl_svm_set_dca_update_function​(SVM.VlSvm self,
                                                   int f)
      • diagnostic1

        public void diagnostic1​(SVM.VlSvm svm)
      • makeInfoStruct

        public void makeInfoStruct​(SVM.VlSvm svm)
      • vl_svm_get_lambda

        public double vl_svm_get_lambda​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        diagnostic frequency.
      • vl_svm_get_bias_multiplier

        public double vl_svm_get_bias_multiplier​(SVM.VlSvm self)
        Parameters:
        self - object.
        Returns:
        bias multiplier.
      • vl_homogeneouskernelmap_new

        public SVM.VlHomogeneousKernelMap vl_homogeneouskernelmap_new​(SVM.VlHomogeneousKernelType kernelType,
                                                                      double gamma,
                                                                      int order,
                                                                      double period,
                                                                      SVM.VlHomogeneousKernelMapWindowType windowType)
        Parameters:
        kernelType - type of homogeneous kernel.
        gamma - kernel homogeneity degree.
        order - approximation order.
        period - kernel period.
        windowType - type of window used to truncate the kernel.
        Returns:
        the new homogeneous kernel map. The function intializes a new homogeneous kernel map for the specified kernel type, homogeneity degree, approximation order, period, and truncation window. See @ref homkermap-fundamentals for details. The homogeneity degree @c gamma must be positive (the standard kernels are obtained by setting @c gamma to 1). When unsure, set
      • sinc

        public double sinc​(double x)
      • vl_homogeneouskernelmap_get_smooth_spectrum

        public double vl_homogeneouskernelmap_get_smooth_spectrum​(SVM.VlHomogeneousKernelMap self,
                                                                  double omega)
        Parameters:
        self - homogeneous kernel map.
        omega - sampling frequency.
        Returns:
        the spectrum sampled at @a omega after smoothing.
      • vl_homogeneouskernelmap_get_spectrum

        public double vl_homogeneouskernelmap_get_spectrum​(SVM.VlHomogeneousKernelMap self,
                                                           double omega)
        Parameters:
        self - homogeneous kernel map.
        omega - sampling frequency.
        Returns:
        the spectrum sampled at @a omega.
      • runAlgorithm

        public void runAlgorithm()
        Description copied from class: AlgorithmBase
        Actually runs the algorithm. Implemented by inheriting algorithms.
        Specified by:
        runAlgorithm in class AlgorithmBase