Changeset 714
 Timestamp:
 Dec 22, 2006, 1:10:54 AM (15 years ago)
 Location:
 trunk/yat
 Files:

 6 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/SVindex.cc
r680 r714 51 51 for (size_t i=0; i<vec_.size(); i++) 52 52 vec_[i]=i; 53 } 54 55 size_t SVindex::index_first(void) const 56 { 57 assert(index_first_<size()); 58 return index_first_; 59 } 60 61 size_t SVindex::index_second(void) const 62 { 63 assert(index_second_<size()); 64 return index_second_; 53 65 } 54 66 … … 70 82 } 71 83 72 void SVindex::sv_first(void) 73 { 74 // if already sv, do nothing 75 if (index_first_<nof_sv()) 76 return; 77 78 // swap elements 79 if(index_second_==nof_sv_){ 80 index_second_=index_first_; 81 } 82 vec_[index_first_]=vec_[nof_sv_]; 83 vec_[nof_sv_]=value_first_; 84 index_first_ = nof_sv_; 85 86 nof_sv_++; 87 88 } 89 90 void SVindex::sv_second(void) 91 { 92 // if already sv, do nothing 93 if (index_second_<nof_sv()) 94 return; 95 96 // swap elements 97 if(index_first_==nof_sv_){ 98 index_first_=index_second_; 99 } 100 101 vec_[index_second_]=vec_[nof_sv_]; 102 vec_[nof_sv_]=value_second_; 103 index_second_=nof_sv_; 104 105 nof_sv_++; 84 size_t SVindex::nof_sv(void) const 85 { 86 return nof_sv_; 106 87 } 107 88 … … 143 124 } 144 125 126 size_t SVindex::size(void) const 127 { 128 return vec_.size(); 129 } 130 131 void SVindex::sv_first(void) 132 { 133 // if already sv, do nothing 134 if (index_first_<nof_sv()) 135 return; 136 137 // swap elements 138 if(index_second_==nof_sv_){ 139 index_second_=index_first_; 140 } 141 vec_[index_first_]=vec_[nof_sv_]; 142 vec_[nof_sv_]=value_first_; 143 index_first_ = nof_sv_; 144 145 nof_sv_++; 146 147 } 148 149 void SVindex::sv_second(void) 150 { 151 // if already sv, do nothing 152 if (index_second_<nof_sv()) 153 return; 154 155 // swap elements 156 if(index_first_==nof_sv_){ 157 index_first_=index_second_; 158 } 159 160 vec_[index_second_]=vec_[nof_sv_]; 161 vec_[nof_sv_]=value_second_; 162 index_second_=nof_sv_; 163 164 nof_sv_++; 165 } 166 145 167 void SVindex::update_first(const size_t i) 146 168 { … … 157 179 } 158 180 181 size_t SVindex::value_first(void) const 182 { 183 assert(value_first_<size()); 184 return value_first_; 185 } 186 187 size_t SVindex::value_second(void) const 188 { 189 assert(value_second_<size()); 190 return value_second_; 191 } 192 193 size_t SVindex::operator()(size_t i) const 194 { 195 assert(i<size()); 196 assert(vec_[i]<size()); 197 return vec_[i]; 198 } 199 159 200 }}} // of namespace classifier, yat, and theplu 
trunk/yat/classifier/SVindex.h
r706 r714 50 50 51 51 // @return index_first 52 inline size_t index_first(void) const { return index_first_; }52 size_t index_first(void) const; 53 53 54 54 // @return index_second 55 inline size_t index_second(void) const { return index_second_; }55 size_t index_second(void) const; 56 56 57 57 // synch the object against alpha 58 58 void init(const utility::vector& alpha, const double); 59 59 60 // @return nof samples61 inline size_t size(void) const { return vec_.size(); }62 63 60 // @return nof support vectors 64 inline size_t nof_sv(void) const { return nof_sv_; }61 size_t nof_sv(void) const; 65 62 66 63 // making first to an nsv. If already sv, nothing happens. … … 73 70 // nof_sv_ (the first nsv) 74 71 void shuffle(void); 72 73 // @return nof samples 74 size_t size(void) const; 75 75 76 76 // making first to a sv. If already sv, nothing happens. … … 87 87 88 88 // @return value_first 89 inline size_t value_first(void) const { return value_first_; }89 size_t value_first(void) const; 90 90 91 91 // @return const ref value_second 92 inline size_t value_second(void) const { return value_second_; }92 size_t value_second(void) const; 93 93 94 inline size_t operator()(size_t i) const { return vec_[i]; }94 size_t operator()(size_t i) const; 95 95 96 96 private: 
trunk/yat/classifier/Target.cc
r680 r714 88 88 } 89 89 90 bool Target::binary(size_t i) const 91 { 92 assert(i<size()); 93 return binary_[operator()(i)]; 94 } 95 96 const std::map<std::string,size_t>& Target::classes(void) const 97 { 98 return class_map_; 99 } 100 90 101 void Target::init(const std::vector<std::string>& label) 91 102 { … … 118 129 } 119 130 131 const std::vector<std::string>& Target::labels(void) 132 { 133 return labels_; 134 } 135 136 const size_t Target::nof_classes(void) const 137 { 138 return classes().size(); 139 } 140 120 141 void Target::random_shuffle(void) 121 142 { 122 143 random::DiscreteUniform d; 123 144 std::random_shuffle(classes_.begin(), classes_.end(),d); 145 } 146 147 void Target::set_binary(size_t i, bool b) 148 { 149 assert(i<nof_classes()); 150 binary_[i]=b; 124 151 } 125 152 … … 133 160 } 134 161 162 size_t Target::size(void) const 163 { 164 return classes_.size(); 165 } 166 135 167 const size_t Target::size(size_t cl) const 136 168 { … … 138 170 } 139 171 140 141 std::ostream& operator<<(std::ostream& s, const Target& a) 142 { 143 for (size_t j = 0; j < a.size(); ++j) { 144 s << a(j); 145 if ( (j+1)<a.size() ) 146 s << " "; 147 } 148 149 return s; 150 } 151 172 size_t Target::operator()(size_t sample) const 173 { 174 assert(sample<size()); 175 return classes_[sample]; 176 } 177 178 size_t Target::operator[](size_t sample) const 179 { 180 return this>operator()(sample); 181 } 152 182 153 183 const Target& Target::operator=(const Target& other) … … 161 191 162 192 193 std::ostream& operator<<(std::ostream& s, const Target& a) 194 { 195 for (size_t j = 0; j < a.size(); ++j) { 196 s << a(j); 197 if ( (j+1)<a.size() ) 198 s << " "; 199 } 200 201 return s; 202 } 203 204 163 205 }}} // of namespace classifier, yat, and theplu 
trunk/yat/classifier/Target.h
r706 r714 80 80 /// @return a map with label as key and class as value. 81 81 /// 82 inline const std::map<std::string,size_t>& classes(void) const 83 { return class_map_; } 82 const std::map<std::string,size_t>& classes(void) const; 84 83 85 84 /// … … 88 87 /// @return number of classes 89 88 /// 90 inline const size_t nof_classes(void) const { return classes().size(); }89 const size_t nof_classes(void) const; 91 90 92 91 /// … … 98 97 /// @see set_binary 99 98 /// 100 inline bool binary(const size_t i) const { return binary_[operator()(i)]; }99 bool binary(size_t i) const; 101 100 102 101 /// 103 102 /// @return vector of labels for classes 104 103 /// 105 inline const std::vector<std::string>& labels() { return labels_; }104 const std::vector<std::string>& labels(void); 106 105 107 106 /// … … 110 109 /// 0 which is set to true. 111 110 /// 112 inline void set_binary(const size_t i, const bool b) { binary_[i]=b; }111 void set_binary(size_t i, bool b); 113 112 114 113 /// … … 123 122 /// @return number of samples 124 123 /// 125 inline size_t size(void) const { return classes_.size(); }124 size_t size(void) const; 126 125 127 126 /// … … 139 138 /// @return the class of @a sample 140 139 /// 141 inline size_t operator()(const size_t sample) const 142 { return classes_[sample]; } 140 size_t operator()(size_t sample) const; 143 141 144 142 /// 145 143 /// @return the class of @a sample 146 144 /// 147 inline size_t operator[](const size_t sample) const 148 { return this>operator()(sample); } 145 size_t operator[](size_t sample) const; 149 146 150 147 /// 
trunk/yat/utility/vector.cc
r703 r714 189 189 190 190 191 int vector::add(const vector& other) 192 { 193 return gsl_vector_add(v_,other.v_); 194 } 195 196 197 int vector::add(double term) 198 { 199 return gsl_vector_add_constant(v_,term); 200 } 201 202 191 203 gsl_vector* vector::create_gsl_vector_copy(void) const 192 204 { … … 197 209 198 210 211 int vector::div(const vector& other) 212 { 213 return gsl_vector_div(v_,other.v_); 214 } 215 216 217 const gsl_vector* vector::gsl_vector_p(void) const 218 { 219 return proxy_v_; 220 } 221 222 223 gsl_vector* vector::gsl_vector_p(void) 224 { 225 return v_; 226 } 227 228 229 bool vector::isnull(void) const 230 { 231 return gsl_vector_isnull(proxy_v_); 232 } 233 234 235 bool vector::isview(void) const 236 { 237 return view_  view_const_; 238 } 239 240 241 double vector::max(void) const 242 { 243 return gsl_vector_max(proxy_v_); 244 } 245 246 247 size_t vector::max_index(void) const 248 { 249 return gsl_vector_max_index(proxy_v_); 250 } 251 252 253 double vector::min(void) const 254 { 255 return gsl_vector_min(proxy_v_); 256 } 257 258 259 size_t vector::min_index(void) const 260 { 261 return gsl_vector_min_index(proxy_v_); 262 } 263 264 199 265 std::pair<double,double> vector::minmax(void) const 200 266 { … … 210 276 gsl_vector_minmax_index(proxy_v_, &min_index, &max_index); 211 277 return std::pair<size_t,size_t>(min_index,max_index); 278 } 279 280 281 int vector::mul(const vector& other) 282 { 283 return gsl_vector_mul(v_,other.v_); 284 } 285 286 287 int vector::reverse(void) 288 { 289 return gsl_vector_reverse(v_); 290 } 291 292 293 int vector::scale(double factor) 294 { 295 return gsl_vector_scale(v_,factor); 296 } 297 298 299 int vector::set(const vector& vec) 300 { 301 return gsl_vector_memcpy(v_,vec.v_); 302 } 303 304 305 void vector::set_all(const double& value) 306 { 307 gsl_vector_set_all(v_,value); 308 } 309 310 311 void vector::set_basis(const size_t i) 312 { 313 gsl_vector_set_basis(v_,i); 314 } 315 316 317 void vector::set_zero(void) 318 { 319 gsl_vector_set_zero(v_); 320 } 321 322 323 size_t vector::size(void) const 324 { 325 return proxy_v_>size; 326 } 327 328 329 void vector::sort(void) 330 { 331 gsl_sort_vector(v_); 332 } 333 334 335 int vector::sub(const vector& other) 336 { 337 return gsl_vector_sub(v_,other.v_); 212 338 } 213 339 … … 219 345 sum += (*this)(i); 220 346 return( sum ); 347 } 348 349 350 int vector::swap(vector& other) 351 { 352 return gsl_vector_swap(v_,other.v_); 353 } 354 355 356 int vector::swap_elements(size_t i, size_t j) 357 { 358 return gsl_vector_swap_elements(v_,i,j); 359 } 360 361 362 double& vector::operator()(size_t i) 363 { 364 return *gsl_vector_ptr(v_,i); 365 } 366 367 368 const double& vector::operator()(size_t i) const 369 { 370 return *gsl_vector_const_ptr(proxy_v_,i); 371 } 372 373 374 double& vector::operator[](size_t i) 375 { 376 return *gsl_vector_ptr(v_,i); 377 } 378 379 380 const double& vector::operator[](size_t i) const 381 { 382 return *gsl_vector_const_ptr(proxy_v_,i); 221 383 } 222 384 
trunk/yat/utility/vector.h
r703 r714 209 209 /// 210 210 // Jari, group as vector_operators 211 in line int add(const vector& other) { return gsl_vector_add(v_,other.v_); }211 int add(const vector& other); 212 212 213 213 /// … … 218 218 /// 219 219 // Jari, group as vector_operators 220 in line int add(double term) { return gsl_vector_add_constant(v_,term); }220 int add(double term); 221 221 222 222 /// … … 227 227 /// 228 228 // Jari, doxygen group as Vector operators 229 in line int div(const vector& other) { return gsl_vector_div(v_,other.v_); }229 int div(const vector& other); 230 230 231 231 /// 232 232 /// @return A const pointer to the internal GSL vector, 233 233 /// 234 inline const gsl_vector* gsl_vector_p(void) const { return proxy_v_; } 234 const gsl_vector* gsl_vector_p(void) const; 235 235 236 236 /// 237 237 /// @return A pointer to the internal GSL vector, 238 238 /// 239 inline gsl_vector* gsl_vector_p(void) { return v_; } 239 gsl_vector* gsl_vector_p(void); 240 240 241 241 /// … … 243 243 /// othwerwise; 244 244 /// 245 inline bool isnull(void) const { return gsl_vector_isnull(proxy_v_); }245 bool isnull(void) const; 246 246 247 247 /// … … 251 251 /// @return True if the object is a view, false othwerwise. 252 252 /// 253 inline bool isview(void) const { return view_  view_const_; }253 bool isview(void) const; 254 254 255 255 /// … … 257 257 /// 258 258 // Jari, doxygen group as Finding maximum and minimum elements 259 inline double max(void) const { return gsl_vector_max(proxy_v_); }259 double max(void) const; 260 260 261 261 /// … … 264 264 /// 265 265 // Jari, doxygen group as Finding maximum and minimum elements 266 inline size_t 267 max_index(void) const { return gsl_vector_max_index(proxy_v_); } 266 size_t max_index(void) const; 268 267 269 268 /// … … 271 270 /// 272 271 // Jari, doxygen group as Finding maximum and minimum elements 273 inline double min(void) const { return gsl_vector_min(proxy_v_); }272 double min(void) const; 274 273 275 274 /// … … 278 277 /// 279 278 // Jari, doxygen group as Finding maximum and minimum elements 280 inline size_t 281 min_index(void) const { return gsl_vector_min_index(proxy_v_); } 279 size_t min_index(void) const; 282 280 283 281 /// … … 304 302 /// 305 303 // Jari, doxygen group as Vector operators 306 in line int mul(const vector& other) { return gsl_vector_mul(v_,other.v_); }304 int mul(const vector& other); 307 305 308 306 /// … … 312 310 /// 313 311 // Jari, doxygen group as Exchanging elements 314 in line int reverse(void) { return gsl_vector_reverse(v_);}312 int reverse(void); 315 313 316 314 /// … … 320 318 /// 321 319 // Jari, doxygen group as Vector operators 322 in line int scale(double factor) { return gsl_vector_scale(v_,factor); }320 int scale(double factor); 323 321 324 322 /// … … 332 330 /// @see const vector& operator=(const vector&) 333 331 /// 334 in line int set(const vector& vec) { return gsl_vector_memcpy(v_,vec.v_); }332 int set(const vector& vec); 335 333 336 334 /// … … 338 336 /// 339 337 // Jari, doxygen group as Initializing vector elements 340 inline void set_all(const double& value) { gsl_vector_set_all(v_,value); } 338 void set_all(const double& value); 341 339 342 340 /// … … 346 344 /// 347 345 // Jari, doxygen group as Initializing vector elements 348 inline void set_basis(const size_t i) { gsl_vector_set_basis(v_,i); }346 void set_basis(const size_t i); 349 347 350 348 /// … … 352 350 /// 353 351 // Jari, doxygen group as Initializing vector elements 354 inline void set_zero(void) { gsl_vector_set_zero(v_); } 352 void set_zero(void); 355 353 356 354 /// 357 355 /// @return the number of elements in the vector. 358 356 /// 359 inline size_t size(void) const { return proxy_v_>size; }357 size_t size(void) const; 360 358 361 359 /// … … 365 363 /// 366 364 // Markus to Jari, doxygen group as Exchanging elements ???? 367 inline void sort(void) { gsl_sort_vector(v_); }365 void sort(void); 368 366 369 367 /// … … 373 371 /// 374 372 // Jari, doxygen group as Vector operators 375 in line int sub(const vector& other) { return gsl_vector_sub(v_,other.v_); }373 int sub(const vector& other); 376 374 377 375 /// … … 388 386 /// @return GSL_SUCCESS on normal exit. 389 387 /// 390 in line int swap(vector& other) { return gsl_vector_swap(v_,other.v_); }388 int swap(vector& other); 391 389 392 390 /// … … 396 394 /// 397 395 // Jari, doxygen group as Exchanging elements 398 inline int 399 swap_elements(size_t i,size_t j) { return gsl_vector_swap_elements(v_,i,j);} 396 int swap_elements(size_t i,size_t j); 400 397 401 398 /// … … 405 402 /// 406 403 // Jari, doxygen group as Accessing vector elements 407 inline double& operator()(size_t i) { return *gsl_vector_ptr(v_,i); }404 double& operator()(size_t i); 408 405 409 406 /// … … 413 410 /// 414 411 // Jari, doxygen group as Accessing vector elements 415 inline const double& 416 operator()(size_t i) const { return *gsl_vector_const_ptr(proxy_v_,i); } 412 const double& operator()(size_t i) const; 417 413 418 414 /// … … 422 418 /// 423 419 // Jari, doxygen group as Accessing vector elements 424 inline double& operator[](size_t i) { return *gsl_vector_ptr(v_,i); }420 double& operator[](size_t i); 425 421 426 422 /// … … 430 426 /// 431 427 // Jari, doxygen group as Accessing vector elements 432 inline const double& 433 operator[](size_t i) const { return *gsl_vector_const_ptr(proxy_v_,i); } 434 435 /// 436 /// @return The dot product. 437 /// 438 double operator*(const vector&) const; 428 const double& operator[](size_t i) const; 439 429 440 430 /// … … 445 435 /// 446 436 bool operator==(const vector&) const; 437 438 /// 439 /// @return The dot product. 440 /// 441 double operator*(const vector&) const; 447 442 448 443 ///
Note: See TracChangeset
for help on using the changeset viewer.