name: SupportVectorModel : public StatisticalModelBase
synopsis:

>     g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_stat.a

>     #include <SupportVectorModel.h>

>     SupportVectorModel();
>     SupportVectorModel(const SupportVectorModel& arg);
>     boolean eq(const SupportVectorModel& arg) const;
>     boolean assign(const SupportVectorModel& arg);
>     boolean setNumSupportVectors(long number, ALGORITHM algorithm = DEF_ALGORITHM);
>     VectorFloat& getSupportVector(long index);
>     Kernel& getKernel(long index);
>     Float& getAlpha(long index);
>     float getDistance();
>     float getLogLikelihood(const VectorFloat& input);

quick start:

>     VectorFloat support_vector0(L"2.3, 4.5");
>     VectorFloat support_vector1(L"1.3, -2.4");
>     VectorFloat alphas(L"0.4, 0.6");
>     VectorFloat test_vector(L"0.1, 0.3");

>     SupportVectorModel svm;
>     svm.setNumSupportVectors(2);
>     svm.getSupportVector(0) = support_vector(0);
>     svm.getSupportVector(1) = support_vector(1);
>     svm.getAlphas(0) = alphas(0);
>     svm.getAlphas(1) = alphas(1);
>     svm.getLogLikelihood(test_vector);

description:
The SupportVectorModel class is used to compute distance of a vector from a hyperplane specified by support vector machine. The likelihood can be computed by the sigmoid transformation of the distance. The distance is defined as follows:

|  | where |  |

The interface provides access to several variants of the calculation, including a log likelihood measure.
dependencies:

- Vector
- Kernel
- Sigmoid
- StatisticalModelBase
- MemoryManager

public constants:

- define the class name:

      static const String CLASS_NAME;

- define static NameMap objects:

      static const NameMap ALGO_MAP = L"SINGLE_KERNEL, MULTIPLE_KERNEL";

      static const NameMap IMPL_MAP = L"SIGMOID, LOGISTIC, LOGSYM, TANH, SINUS, GAUSS, RANDOM";

- define i/o related constants:

      static const String DEF_PARAM;

      static const String PARAM_ALGORITHM;

      static const String PARAM_IMPLEMENTATION;

      static const String PARAM_SUPPORT_VECTORS;

      static const String PARAM_KERNELS;

      static const String PARAM_ALPHAS;

      static const String PARAM_BIAS;

      static const String PARAM_SIGMOID;

      static const String DEF_COMMENT_TAG;

error codes:

- error code indicating SupportVectorModel class general error:

      static const long ERR = 60350;

protected data:

- algorithm and implementation:

      ALGORITHM algorithm_d;

      IMPLEMENTATION implementation_d;

- support vectors, their kernels and alphas

      Vector<VectorFloat> support_vectors_d;

      Vector<Float> alphas_d;

      Vector<Kernel> kernels_d;

- distance to probability transformation function (currently sigmoid)

      Sigmoid sigmoid_d;

- define the memory manager:

      static MemoryManager mgr_d;

required public methods:

- static methods:

      static const String& name();

      static boolean diagnose(Integral::DEBUG debug_level);

- debug methods:

      boolean debug(const unichar* message) const;

  setDebug is inherited from base class

- destructor/constructor(s):

      ~SupportVectorModel();

      SupportVectorModel();

      SupportVectorModel(const SupportVectorModel& arg);

- assign methods:

      boolean assign(const SupportVectorModel& arg);

- operator= methods:

      SupportVectorModel& operator=(const SupportVectorModel& arg);

- i/o methods (many of them are required by the StatisticalModelBase interface contract):

      long sofSize() const;

      long sofAccumulatorSize() const;

      long sofOccupanciesSize() const;

      boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);

      boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;

      boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

      boolean readAccumulator(Sof& sof, long tag, const String& name = CLASS_NAME);

      boolean writeAccumulator(Sof& sof, long tag, const String& name = CLASS_NAME) const;

      boolean readAccumulatorData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeAccumulatorData(Sof& sof, const String& pname = DEF_PARAM) const;

      boolean readOccupancies(Sof& sof, long tag, const String& name = CLASS_NAME);

      boolean writeOccupancies(Sof& sof, long tag, const String& cname = CLASS_NAME) const;

      boolean readOccupanciesData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeOccupanciesData(Sof& sof, const String& pname = DEF_PARAM) const;

- equality methods:

      boolean eq(const SupportVectorModel& arg) const;

- memory management methods:

      static void* operator new(size_t size);

      static void* operator new[](size_t size);

      static void operator delete(void* ptr);

      static void operator delete[](void* ptr);

      static boolean setGrowSize(long grow_size);

      boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);

class-specific public methods:

- set methods:

      boolean setAlgorithm(ALGORITHM algo);

      ALGORITHM getAlgorithm();

      boolean setImplementation(IMPLEMENTATION impl);

      IMPLEMENTATION getImplementation();

      boolean setNumSupportVectors(long number, ALGORITHM algorithm = DEF_ALGORITHM);

      VectorFloat& getSupportVector(long index);

      Kernel& getKernel(long index);

      Double& getAlpha(long index);

      Sigmoid& getSigmoid();

      float getDistance();

- interface contract for the StatisticalModelBase:

      boolean assign(const StatisticalModelBase& arg);

      boolean eq(const StatisticalModelBase& arg);

      boolean setMode(MODE mode);

      const String& className() const;

      boolean init();

      float getLikelihood(const VectorFloat& input);

      float getLogLikelihood(const VectorFloat& input);

- accumulate and update methods needed for training models:

      boolean getMean(VectorFloat& mean);

      boolean getCovariance(VectorFloat& cov);

      boolean resetAccumulators();

      boolean getOccupancy(double arg);

      boolean setOccupancy(double arg);

      long getAccessCount();

      boolean setAccessCount(long arg);

      boolean initialize(VectorFloat& param);

      boolean accumulate(VectorFloat& param);

      boolean accumulate(VectorDouble& param, VectorFloat& data, boolean precomp);

      boolean update(VectorFloat& varfloor, long min_count);

private methods:

- none

examples:

- This example shows how to set the SupportVectorModel and get the likelihood for a vector:

      // declare a SupportVectorModel object
      //
      SupportVectorModel svm;

      // set the mean and covariance matrix
      //
      VectorFloat vector0(L"1.0, -1.3, 1.4");
      VectorFloat vector1(L"3.0, 1.2, -1.9");

      svm.setNumSupportVectors(2);
      svm.getSupportVector(0) = vector0;
      svm.getSupportVector(1) = vector1;

      svm.getKernel(0).setAlgorithm(Kernel::RBF);

      // declare the input vector
      //
      VectorFloat input;
      input.assign(L"-1.050, -7.709, -2.303");

      // get the log likelihood
      //
      Float likelihood = svm.getLogLikelihood(input);

notes:

- none