Changeset 445
- Timestamp:
- Dec 15, 2005, 5:52:58 PM (17 years ago)
- Location:
- trunk/lib/svm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/svm/SVM.cc
r377 r445 138 138 139 139 SVM::SVM(const Kernel& kernel, const gslapi::vector& target) 140 141 140 : alpha_(target.size(),0), 142 141 bias_(0), … … 149 148 trained_(false), 150 149 tolerance_(0.00000001) 151 152 150 { 153 151 if (max_epochs_>ULONG_MAX) … … 155 153 } 156 154 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 } 157 168 158 169 bool SVM::train(void) -
trunk/lib/svm/SVM.h
r441 r445 31 31 Index(const size_t); 32 32 33 //not implemented34 Index(const Index&);35 36 33 // @return index_first 37 34 inline size_t index_first(void) const … … 39 36 40 37 // @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_; } 42 40 43 41 // synch the object against alpha … … 73 71 74 72 // @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_; } 76 75 77 76 // @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_; } 79 79 80 80 inline size_t operator()(size_t i) const { … … 101 101 102 102 public: 103 ///104 /// Default constructor (not implemented)105 ///106 SVM();107 108 103 /// 109 104 /// 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. 112 109 /// 113 110 SVM(const Kernel&, const gslapi::vector&); 114 111 115 112 /// 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. 117 118 /// 118 119 SVM(const SVM&); … … 155 156 156 157 /// 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); } 160 162 161 163 /// … … 171 173 172 174 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 173 210 gslapi::vector alpha_; 174 211 double bias_; … … 183 220 184 221 185 ///186 /// Calculates bounds for alpha2187 ///188 void bounds(double&, double&) const;189 190 ///191 /// @todo Function calculating bias192 ///193 /// @return true if successful194 ///195 bool calculate_bias(void);196 197 ///198 /// Private function choosing which two elements that should be199 /// updated. First checking for the biggest violation (output - target =200 /// 0) among support vectors (alpha!=0). If no violation was found check201 /// sequentially among the other samples. If no violation there as202 /// well training is completed203 ///204 /// @return true if a pair of samples that violate the conditions205 /// can be found206 ///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) const213 { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; }214 215 222 }; 216 223
Note: See TracChangeset
for help on using the changeset viewer.