Package gov.nih.mipav.model.algorithms
Class SVM
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.SVM
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclass(package private) static enum(package private) static enumclassclass(package private) static enum(package private) static enum(package private) static enumclassNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal intfinal int(package private) doubleFields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid_vl_svm_evaluate(SVM.VlSvm self) void_vl_svm_sdca_train(SVM.VlSvm self) (package private) void_vl_svm_sgd_train(SVM.VlSvm self) voidvoidaccumulateFunction(int acc, SVM.VlSvmDataset self, int element, double[] model, double multiplier) doubleconjugate_lossFunction(int loss, double u, double label) voidvoidvoidvoiddoubledca_updateFunction(int update, double alpha, double inner, double norm2, double label) voiddiagnostic1(SVM.VlSvm svm) doublefrexp(double x, int[] exponent) doubleinner_productFunction(int inp, SVM.VlSvmDataset self, int element, double[] model) voiddoubleloss_derivativeFunction(int loss, double inner, double label) doublelossFunction(int loss, double inner, double label) voidmakeInfoStruct(SVM.VlSvm svm) voidActually runs the algorithm.setup()doublesinc(double x) voidvoidvoidvoidvoidvoidvl_homogeneouskernelmap_evaluate(SVM.VlHomogeneousKernelMap self, double[] destination, int stride, double x) intdoublevl_homogeneouskernelmap_get_smooth_spectrum(SVM.VlHomogeneousKernelMap self, double omega) doublevl_homogeneouskernelmap_get_spectrum(SVM.VlHomogeneousKernelMap self, double omega) vl_homogeneouskernelmap_new(SVM.VlHomogeneousKernelType kernelType, double gamma, int order, double period, SVM.VlHomogeneousKernelMapWindowType windowType) voidvl_rand_permute_indexes(Random self, int[] array, int size) voidvl_svm_delete(SVM.VlSvm self) doublevl_svm_get_bias(SVM.VlSvm self) doubledoubleintintdoublevl_svm_get_epsilon(SVM.VlSvm self) doublevl_svm_get_lambda(SVM.VlSvm self) intdouble[]vl_svm_get_model(SVM.VlSvm self) intvl_svm_get_num_data(SVM.VlSvm self) double[]vl_svm_get_scores(SVM.VlSvm self) vl_svm_get_solver(SVM.VlSvm self) (package private) SVM.VlSvmStatisticsdoublevl_svm_hinge_conjugate_loss(double u, double label) doublevl_svm_hinge_dca_update(double alpha, double inner, double norm2, double label) doublevl_svm_hinge_loss(double inner, double label) doublevl_svm_hinge_loss_derivative(double inner, double label) doublevl_svm_hinge2_conjugate_loss(double u, double label) doublevl_svm_hinge2_dca_update(double alpha, double inner, double norm2, double label) doublevl_svm_hinge2_loss(double inner, double label) doublevl_svm_hinge2_loss_derivative(double inner, double label) doublevl_svm_l1_conjugate_loss(double u, double label) doublevl_svm_l1_dca_update(double alpha, double inner, double norm2, double label) doublevl_svm_l1_loss(double inner, double label) doublevl_svm_l1_loss_derivative(double inner, double label) doublevl_svm_l2_conjugate_loss(double u, double label) doublevl_svm_l2_dca_update(double alpha, double inner, double norm2, double label) doublevl_svm_l2_loss(double inner, double label) doublevl_svm_l2_loss_derivative(double inner, double label) doublevl_svm_logistic_conjugate_loss(double u, double label) doublevl_svm_logistic_dca_update(double alpha, double inner, double norm2, double label) doublevl_svm_logistic_loss(double inner, double label) doublevl_svm_logistic_loss_derivative(double inner, double label) vl_svm_new_with_abstract_data(SVM.VlSvmSolverType solver, SVM.VlSvmDataset data, int dimension, int numData, double[] labels, double lambda) vl_svm_new_with_dataset(SVM.VlSvmSolverType solver, SVM.VlSvmDataset dataset, double[] labels, double lambda) voidvl_svm_set_bias(SVM.VlSvm self, double b) voidvl_svm_set_bias_learning_rate(SVM.VlSvm self, double rate) voidvl_svm_set_bias_multiplier(SVM.VlSvm self, double b) voidvl_svm_set_conjugate_loss_function(SVM.VlSvm self, int f) voidvl_svm_set_data_functions(SVM.VlSvm self, int inner, int acc) voidvl_svm_set_dca_update_function(SVM.VlSvm self, int f) voidvl_svm_set_diagnostic_frequency(SVM.VlSvm self, int f) voidvl_svm_set_epsilon(SVM.VlSvm self, double epsilon) voidvl_svm_set_iteration_number(SVM.VlSvm self, int n) voidvl_svm_set_loss(SVM.VlSvm self, SVM.VlSvmLossType loss) voidvl_svm_set_loss_derivative_function(SVM.VlSvm self, int f) voidvl_svm_set_loss_function(SVM.VlSvm self, int f) voidvl_svm_set_max_num_iterations(SVM.VlSvm self, int n) (package private) voidvl_svm_set_model(SVM.VlSvm self, double[] model) voidvl_svm_set_weights(SVM.VlSvm self, double[] weights) voidvl_svm_train(SVM.VlSvm self) voidvl_svmdataset_accumulate(SVM.VlSvmDataset self, int element, double[] model, double multiplier) voidvl_svmdataset_accumulate_hom(SVM.VlSvmDataset self, int element, double[] model, double multiplier) (package private) voidintintintintdoublevl_svmdataset_inner_product(SVM.VlSvmDataset self, int element, double[] model) doublevl_svmdataset_inner_product_hom(SVM.VlSvmDataset self, int element, double[] model) vl_svmdataset_new(double[] data, int dimension, int numData) vl_svmdataset_new(double[] data, int dimension, int numData, SVM.VlHomogeneousKernelMap hom) voidvoidvl_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) doublexlogx(double x) Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpenedMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
VL_EPSILON_D
double VL_EPSILON_D -
inner_product
public final int inner_product- See Also:
-
inner_product_hom
public final int inner_product_hom- See Also:
-
accumulate
public final int accumulate- See Also:
-
accumulate_hom
public final int accumulate_hom- See Also:
-
hinge_loss
public final int hinge_loss- See Also:
-
hinge2_loss
public final int hinge2_loss- See Also:
-
l1_loss
public final int l1_loss- See Also:
-
l2_loss
public final int l2_loss- See Also:
-
logistic_loss
public final int logistic_loss- See Also:
-
hinge_conjugate_loss
public final int hinge_conjugate_loss- See Also:
-
hinge2_conjugate_loss
public final int hinge2_conjugate_loss- See Also:
-
l1_conjugate_loss
public final int l1_conjugate_loss- See Also:
-
l2_conjugate_loss
public final int l2_conjugate_loss- See Also:
-
logistic_conjugate_loss
public final int logistic_conjugate_loss- See Also:
-
hinge_loss_derivative
public final int hinge_loss_derivative- See Also:
-
hinge2_loss_derivative
public final int hinge2_loss_derivative- See Also:
-
l1_loss_derivative
public final int l1_loss_derivative- See Also:
-
l2_loss_derivative
public final int l2_loss_derivative- See Also:
-
logistic_loss_derivative
public final int logistic_loss_derivative- See Also:
-
hinge_dca_update
public final int hinge_dca_update- See Also:
-
hinge2_dca_update
public final int hinge2_dca_update- See Also:
-
l1_dca_update
public final int l1_dca_update- See Also:
-
l2_dca_update
public final int l2_dca_update- See Also:
-
logistic_dca_update
public final int logistic_dca_update- See Also:
-
diagnostic1
public final int diagnostic1- See Also:
-
-
Constructor Details
-
SVM
public SVM()
-
-
Method Details
-
learn_linear_SVM_on_double_data
public void learn_linear_SVM_on_double_data() -
vl_svmdataset_new
- Parameters:
data- pointer to the data.dimension- the dimension of a data vector.numData- number of wrapped data vectors.dataType- of data (@c float and @c double supported).- 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_svmdataset_new
public SVM.VlSvmDataset vl_svmdataset_new(double[] data, int dimension, int numData, SVM.VlHomogeneousKernelMap hom) -
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 objectlabels- training samples labels.lambda- regularizer parameter.- Returns:
- the new object.
-
vl_homogeneouskernelmap_get_dimension
- Parameters:
self- object.- Returns:
- the map dimension (2 @c order +1).
-
vl_svmdataset_get_dimension
- Parameters:
self- object.- Returns:
- dimension of the wrapped data.
-
vl_svmdataset_get_num_data
- Parameters:
self- object.- Returns:
- number of wrapped data elements.
-
vl_svmdataset_get_inner_product_function
- Parameters:
self- object.- Returns:
- a pointer to the inner product function to use with this data.
-
vl_svmdataset_get_accumulate_function
- 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
- Parameters:
self- object.inner- inner product function.acc- accumulate function. See @ref svm-data-abstraction.
-
vl_svm_train
- 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
-
vl_rand_permute_indexes
- 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
-
vl_svmdataset_inner_product
-
vl_svmdataset_inner_product_hom
-
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
- 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
-
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
-
vl_svm_get_model
- Parameters:
self- object.- Returns:
- model. This is the weight vector $\bw$.
-
vl_svm_get_bias
- Parameters:
self- object.- Returns:
- bias $b$. The value of the bias returned already include the effect of bias mutliplier.
-
vl_svm_delete
- Parameters:
self- object.
-
vl_svmdataset_delete
- 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() -
setup
-
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
- 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
- Parameters:
self- object.- Returns:
- homogeneous kernel map object (or @c NULL if any).
-
vl_svm_get_scores
- 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
- Parameters:
self- object- Returns:
- bias learning rate.
-
vl_svm_get_diagnostic_frequency
- Parameters:
self- object.- Returns:
- diagnostic frequency.
-
vl_svm_get_epsilon
- Parameters:
self- object- Returns:
- epsilon threshold.
-
vl_svm_get_max_num_iterations
- Parameters:
self- object.- Returns:
- maximum number of iterations.
-
vl_svm_get_num_data
- Parameters:
self- object.- Returns:
- model number of data samples This is the dimensionality of the weight vector $\bw$.
-
vl_svm_get_dimension
- Parameters:
self- object.- Returns:
- model dimension. This is the dimensionality of the weight vector $\bw$.
-
vl_svm_set_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
- 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
- Parameters:
self- objectepsilon- threshold (non-negative).
-
vl_svm_set_max_num_iterations
- Parameters:
self- object.n- maximum number of iterations.
-
vl_svm_set_bias_multiplier
- Parameters:
self- objectb- 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
- Parameters:
self- objectrate- bias learning rate (positive). This parameter applies only to the SGD solver.
-
vl_svm_set_diagnostic_frequency
- 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
- 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
- Parameters:
self- object.weights- data weights.
-
vl_svm_set_loss
-
vl_svm_set_loss_function
- 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
-
vl_svm_set_conjugate_loss_function
-
vl_svm_set_dca_update_function
-
diagnostic1
-
makeInfoStruct
-
vl_svm_get_lambda
- Parameters:
self- object.- Returns:
- diagnostic frequency.
-
vl_svm_get_bias_multiplier
- Parameters:
self- object.- Returns:
- bias multiplier.
-
vl_svm_get_solver
- Parameters:
self- object.- Returns:
- SVM solver type.
-
vl_svm_get_statistics
- Parameters:
self- object.- Returns:
- statistics.
-
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
- Parameters:
self- homogeneous kernel map.omega- sampling frequency.- Returns:
- the spectrum sampled at @a omega.
-
runAlgorithm
public void runAlgorithm()Description copied from class:AlgorithmBaseActually runs the algorithm. Implemented by inheriting algorithms.- Specified by:
runAlgorithmin classAlgorithmBase
-