org.encog.ml.svm

## Class SVM

- java.lang.Object
- - org.encog.ml.BasicML
  - - org.encog.ml.svm.SVM

- All Implemented Interfaces:
    Serializable, MLClassification, MLError, MLInput, MLInputOutput, MLMethod, MLOutput, MLProperties, MLRegression

      public class SVM
      extends BasicML
      implements MLRegression, MLClassification, MLError

  This is a network that is backed by one or more Support Vector Machines (SVM). It is designed to function very similarly to an Encog neural network, and is largely interchangeable with an Encog neural network. The support vector machine supports several types. Regression is used when you want the network to predict a value, given the input. Function approximation is a good example of regression. Classification is used when you want the SVM to group the input data into one or more classes. Support Vector Machines typically have a single output. Neural networks can have multiple output neurons. To get around this issue, this class will create multiple SVM's if there is more than one output specified. Because a SVM is trained quite differently from a neural network, none of the neural network training classes will work. This class must be trained using SVMTrain.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_C` The default C.
    `static int` | `DEFAULT_CACHE_SIZE` The default cache size.
    `static int` | `DEFAULT_COEF0` The default COEF0.
    `static int` | `DEFAULT_DEGREE` The default degree.
    `static double` | `DEFAULT_EPS` The default EPS.
    `static double` | `DEFAULT_NU` The default NU.
    `static double` | `DEFAULT_P` The default P.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SVM()` Construct the SVM.
    `SVM(int theInputCount, boolean regression)` Construct an SVM network.
    `SVM(int theInputCount, SVMType svmType, KernelType kernelType)` Construct a SVM network.
    `SVM(svm_model theModel)` Construct a SVM from a model.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `calculateError(MLDataSet data)` Calculate the error for this SVM.
    `int` | `classify(MLData input)` Classify the input into a group.
    `MLData` | `compute(MLData input)` Compute the output for the given input.
    `int` | `getInputCount()`
    `KernelType` | `getKernelType()`
    `svm_model` | `getModel()`
    `int` | `getOutputCount()`
    `svm_parameter` | `getParams()`
    `SVMType` | `getSVMType()`
    `svm_node[]` | `makeSparse(MLData data)` Convert regular Encog MLData into the "sparse" data needed by an SVM.
    `void` | `setInputCount(int i)` Set the input count.
    `void` | `setModel(svm_model theModel)` Set the model.
    `void` | `updateProperties()` Not needed, no properties to update.

    - ### Methods inherited from class org.encog.ml.BasicML

      `getProperties, getPropertyDouble, getPropertyLong, getPropertyString, setProperty, setProperty, setProperty`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_DEGREE

          public static final int DEFAULT_DEGREE

      The default degree.
      See Also:
        Constant Field Values

    - #### DEFAULT_COEF0

          public static final int DEFAULT_COEF0

      The default COEF0.
      See Also:
        Constant Field Values

    - #### DEFAULT_NU

          public static final double DEFAULT_NU

      The default NU.
      See Also:
        Constant Field Values

    - #### DEFAULT_CACHE_SIZE

          public static final int DEFAULT_CACHE_SIZE

      The default cache size.
      See Also:
        Constant Field Values

    - #### DEFAULT_C

          public static final int DEFAULT_C

      The default C.
      See Also:
        Constant Field Values

    - #### DEFAULT_EPS

          public static final double DEFAULT_EPS

      The default EPS.
      See Also:
        Constant Field Values

    - #### DEFAULT_P

          public static final double DEFAULT_P

      The default P.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SVM

          public SVM()

      Construct the SVM.

    - #### SVM

          public SVM(int theInputCount,
             boolean regression)

      Construct an SVM network. For regression it will use an epsilon support vector. Both types will use an RBF kernel.
      Parameters:
        `theInputCount` - The input count.
        `regression` - True if this network is used for regression.

    - #### SVM

          public SVM(int theInputCount,
             SVMType svmType,
             KernelType kernelType)

      Construct a SVM network.
      Parameters:
        `theInputCount` - The input count.
        `svmType` - The type of SVM.
        `kernelType` - The SVM kernal type.

    - #### SVM

          public SVM(svm_model theModel)

      Construct a SVM from a model.
      Parameters:
        `theModel` - The model.

  - ### Method Detail

    - #### calculateError

          public double calculateError(MLDataSet data)

      Calculate the error for this SVM.
      Specified by:
        `calculateError` in interface `MLError`
      Parameters:
        `data` - The training set.
      Returns:
        The error percentage.

    - #### classify

          public int classify(MLData input)

      Classify the input into a group.
      Specified by:
        `classify` in interface `MLClassification`
      Parameters:
        `input` - The input data to classify.
      Returns:
        The group that the data was classified into.

    - #### compute

          public MLData compute(MLData input)

      Compute the output for the given input.
      Specified by:
        `compute` in interface `MLRegression`
      Parameters:
        `input` - The input to the SVM.
      Returns:
        The results from the SVM.

    - #### getInputCount

          public int getInputCount()

      Specified by:
        `getInputCount` in interface `MLInput`
      Returns:
        The input count.

    - #### getKernelType

          public KernelType getKernelType()

      Returns:
        The kernel type.

    - #### getModel

          public svm_model getModel()

      Returns:
        The SVM models for each output.

    - #### getOutputCount

          public int getOutputCount()

      Specified by:
        `getOutputCount` in interface `MLOutput`
      Returns:
        For a SVM, the output count is always one.

    - #### getParams

          public final svm_parameter getParams()

      Returns:
        The SVM params for each of the outputs.

    - #### getSVMType

          public SVMType getSVMType()

      Returns:
        The SVM type.

    - #### makeSparse

          public svm_node[] makeSparse(MLData data)

      Convert regular Encog MLData into the "sparse" data needed by an SVM.
      Parameters:
        `data` - The data to convert.
      Returns:
        The SVM sparse data.

    - #### setInputCount

          public void setInputCount(int i)

      Set the input count.
      Parameters:
        `i` - The new input count.

    - #### setModel

          public void setModel(svm_model theModel)

      Set the model.
      Parameters:
        `theModel` - The model.

    - #### updateProperties

          public void updateProperties()

      Not needed, no properties to update.
      Specified by:
        `updateProperties` in interface `MLProperties`
      Specified by:
        `updateProperties` in class `BasicML`

Copyright © 2014. All Rights Reserved.