Changeset 445


Ignore:
Timestamp:
Dec 15, 2005, 5:52:58 PM (17 years ago)
Author:
Peter
Message:

added reset function and copy constructor to SVM

Location:
trunk/lib/svm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/svm/SVM.cc

    r377 r445  
    138138
    139139  SVM::SVM(const Kernel& kernel, const gslapi::vector& target)
    140            
    141140  : alpha_(target.size(),0),
    142141    bias_(0),
     
    149148    trained_(false),
    150149    tolerance_(0.00000001)
    151        
    152150  {
    153151    if (max_epochs_>ULONG_MAX)
     
    155153  }
    156154
     155  SVM::SVM(const SVM& other)
     156  : alpha_(other.alpha_),
     157    bias_(other.bias_),
     158    C_inverse_(other.C_inverse_),
     159    kernel_(other.kernel_),
     160    max_epochs_(other.max_epochs_),
     161    output_(other.output_),
     162    sample_(other.sample_),
     163    target_(other.target_),
     164    trained_(other.trained_),
     165    tolerance_(other.tolerance_)
     166  {
     167  }
    157168
    158169  bool SVM::train(void)
  • trunk/lib/svm/SVM.h

    r441 r445  
    3131    Index(const size_t);
    3232
    33     //not implemented
    34     Index(const Index&);
    35 
    3633    // @return index_first
    3734    inline size_t index_first(void) const
     
    3936
    4037    // @return index_second
    41     inline size_t index_second(void) const { assert(index_second_<n());return index_second_; }
     38    inline size_t index_second(void) const
     39    { assert(index_second_<n()); return index_second_; }
    4240
    4341    // synch the object against alpha
     
    7371
    7472    // @return value_first
    75     inline size_t value_first(void) const { assert(value_first_<n()); return value_first_; }
     73    inline size_t value_first(void) const
     74    { assert(value_first_<n()); return value_first_; }
    7675
    7776    // @return const ref value_second
    78     inline size_t value_second(void) const {  assert(value_first_<n()); return value_second_; }
     77    inline size_t value_second(void) const
     78    { assert(value_first_<n()); return value_second_; }
    7979
    8080    inline size_t operator()(size_t i) const {
     
    101101 
    102102  public:
    103     ///
    104     /// Default constructor (not implemented)
    105     ///
    106     SVM();
    107 
    108103    ///
    109104    /// Constructor taking the kernel and the target vector as
    110     /// input. @note if the kernel or target is destroyed the SVM is
    111     /// no longer defined
     105    /// input.
     106    ///
     107    /// @note if the target, kernel (or data in kernel) is destroyed
     108    /// the SVM is no longer defined.
    112109    ///
    113110    SVM(const Kernel&, const gslapi::vector&);
    114111
    115112    ///
    116     /// @todo Copy constructor.
     113    /// Copy constructor.
     114    ///
     115    /// @note Copying of kernel (and the data contained in kernel) is
     116    /// copied shallow. Hence, modifying any of these objects in one
     117    /// SVM would modify it in the other SVM.
    117118    ///
    118119    SVM(const SVM&);
     
    155156
    156157    ///
    157     /// @todo Function sets \f$ \alpha=0 \f$ and makes SVM untrained.
    158     ///
    159     void reset(void);
     158    /// Function sets \f$ \alpha=0 \f$ and makes SVM untrained.
     159    ///
     160    inline void reset(void)
     161    { trained_=false; alpha_=gslapi::vector(target_.size(),0); }
    160162
    161163    ///
     
    171173     
    172174  private:
     175    ///
     176    /// Default constructor (not implemented)
     177    ///
     178    SVM(void);
     179
     180    ///
     181    /// Calculates bounds for alpha2
     182    ///
     183    void bounds(double&, double&) const;
     184
     185    ///
     186    /// @todo Function calculating bias
     187    ///
     188    /// @return true if successful
     189    ///
     190    bool calculate_bias(void);
     191
     192    ///
     193    ///   Private function choosing which two elements that should be
     194    ///   updated. First checking for the biggest violation (output - target =
     195    ///   0) among support vectors (alpha!=0). If no violation was found check
     196    ///   sequentially among the other samples. If no violation there as
     197    ///   well training is completed
     198    ///
     199    ///  @return true if a pair of samples that violate the conditions
     200    ///  can be found
     201    ///
     202    bool choose(const theplu::gslapi::vector&);
     203
     204    ///
     205    /// @return kernel modified with diagonal term (soft margin)
     206    ///
     207    inline double kernel_mod(const size_t i, const size_t j) const
     208    { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; }
     209   
    173210    gslapi::vector alpha_;
    174211    double bias_;
     
    183220   
    184221
    185     ///
    186     /// Calculates bounds for alpha2
    187     ///
    188     void bounds(double&, double&) const;
    189 
    190     ///
    191     /// @todo Function calculating bias
    192     ///
    193     /// @return true if successful
    194     ///
    195     bool calculate_bias(void);
    196 
    197     ///
    198     ///   Private function choosing which two elements that should be
    199     ///   updated. First checking for the biggest violation (output - target =
    200     ///   0) among support vectors (alpha!=0). If no violation was found check
    201     ///   sequentially among the other samples. If no violation there as
    202     ///   well training is completed
    203     ///
    204     ///  @return true if a pair of samples that violate the conditions
    205     ///  can be found
    206     ///
    207     bool choose(const theplu::gslapi::vector&);
    208 
    209     ///
    210     /// @return kernel modified with diagonal term (soft margin)
    211     ///
    212     inline double kernel_mod(const size_t i, const size_t j) const
    213     { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; }
    214    
    215222  };
    216223
Note: See TracChangeset for help on using the changeset viewer.