- Timestamp:
- Mar 10, 2007, 9:07:13 PM (16 years ago)
- Location:
- trunk/yat
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/IGP.cc
r680 r789 45 45 46 46 // Calculate IGP for each class 47 igp_ =utility::vector(target_.nof_classes());47 igp_.clone(utility::vector(target_.nof_classes())); 48 48 for(u_int i=0; i<target_.size(); i++) { 49 49 u_int neighbor=i; -
trunk/yat/classifier/NCC.cc
r722 r789 110 110 utility::vector& prediction) const 111 111 { 112 prediction =utility::vector(centroids_.columns());112 prediction.clone(utility::vector(centroids_.columns())); 113 113 114 114 utility::vector value(input.size(),0); -
trunk/yat/classifier/utility.cc
r779 r789 34 34 void convert(const DataLookup1D& lookup, utility::vector& vector) 35 35 { 36 vector =utility::vector(lookup.size());36 vector.clone(utility::vector(lookup.size())); 37 37 for(u_int i=0; i<lookup.size(); i++) 38 38 vector(i)=lookup(i); … … 43 43 { 44 44 45 value =utility::vector(lookup.size());46 weight =utility::vector(lookup.size());45 value.clone(utility::vector(lookup.size())); 46 weight.clone(utility::vector(lookup.size())); 47 47 for(u_int i=0; i<lookup.size(); i++){ 48 48 value(i)=lookup.data(i); -
trunk/yat/regression/Local.cc
r767 r789 58 58 59 59 size_t nof_fits=data_.size()/step_size; 60 x_ = utility::vector(nof_fits);61 y_predicted_ = utility::vector(x_.size());62 y_err_ = utility::vector(x_.size());60 x_.clone(utility::vector(nof_fits)); 61 y_predicted_.clone(utility::vector(x_.size())); 62 y_err_.clone(utility::vector(x_.size())); 63 63 sort(data_.begin(), data_.end()); 64 64 -
trunk/yat/regression/MultiDimensional.cc
r750 r789 57 57 assert(x.rows()==y.size()); 58 58 covariance_=utility::matrix(x.columns(),x.columns()); 59 fit_parameters_ =utility::vector(x.columns());59 fit_parameters_.clone(utility::vector(x.columns())); 60 60 if (work_) 61 61 gsl_multifit_linear_free(work_); -
trunk/yat/regression/MultiDimensionalWeighted.cc
r750 r789 59 59 60 60 covariance_=utility::matrix(x.columns(),x.columns()); 61 fit_parameters_ =utility::vector(x.columns());61 fit_parameters_.clone(utility::vector(x.columns())); 62 62 if (work_) 63 63 gsl_multifit_linear_free(work_); … … 85 85 } 86 86 87 87 88 double MultiDimensionalWeighted::predict(const utility::vector& x) const 88 89 { … … 90 91 return fit_parameters_ * x; 91 92 } 93 92 94 93 95 double MultiDimensionalWeighted::prediction_error2(const utility::vector& x, -
trunk/yat/statistics/Score.cc
r779 r789 54 54 { 55 55 assert(target.size()==value.size()); 56 utility::vector a ;56 utility::vector a(value.size()); 57 57 classifier::convert(value,a); 58 58 return score(target,a); … … 64 64 { 65 65 assert(target.size()==value.size()); 66 utility::vector a ;67 utility::vector b ;66 utility::vector a(value.size()); 67 utility::vector b(value.size()); 68 68 classifier::convert(value,a,b); 69 69 return score(target,a,b); … … 75 75 const classifier::DataLookup1D& weight) const 76 76 { 77 utility::vector a ;77 utility::vector a(value.size()); 78 78 classifier::convert(value,a); 79 utility::vector b ;79 utility::vector b(value.size()); 80 80 classifier::convert(weight,a); 81 81 return score(target,a,b); -
trunk/yat/utility/PCA.cc
r782 r789 69 69 eigenvectors_ = U; 70 70 eigenvectors_ .transpose(); 71 eigenvalues_ = pSVD->s();71 eigenvalues_.clone(pSVD->s()); 72 72 73 73 // T … … 109 109 eigenvectors_=V; 110 110 eigenvectors_.transpose(); 111 eigenvalues_ = pSVD->s();111 eigenvalues_.clone(pSVD->s()); 112 112 113 113 // Transform back when done with SVD! … … 139 139 void PCA::row_center(utility::matrix& A_center) 140 140 { 141 meanvalues_ = utility::vector( A_.rows());141 meanvalues_.clone(utility::vector(A_.rows())); 142 142 utility::vector A_row_sum(A_.rows()); 143 143 for (size_t i=0; i<A_row_sum.size(); ++i) -
trunk/yat/utility/vector.cc
r787 r789 30 30 31 31 #include <cassert> 32 #include <cmath> 32 33 #include <iostream> 33 34 #include <sstream> … … 83 84 throw utility::GSL_error("vector::vector failed to setup view"); 84 85 proxy_v_ = &(view_const_->vector); 85 const_cast<const gsl_vector*>(proxy_v_);86 86 } 87 87 … … 210 210 211 211 212 const vector& vector::clone(const vector& other) 213 { 214 if (this!=&other) { 215 216 if (view_) 217 delete view_; 218 else if (view_const_) 219 delete view_const_; 220 else if (v_) 221 gsl_vector_free(v_); 222 223 if (other.view_) { 224 view_ = new gsl_vector_view(*other.view_); 225 proxy_v_ = v_ = &(view_->vector); 226 } 227 else if (other.view_const_) { 228 view_const_ = new gsl_vector_const_view(*other.view_const_); 229 proxy_v_ = &(view_const_->vector); 230 v_=NULL; 231 } 232 else if (other.v_) 233 proxy_v_ = v_ = other.create_gsl_vector_copy(); 234 235 } 236 return *this; 237 } 238 239 212 240 void vector::div(const vector& other) 213 241 { … … 216 244 if (status) 217 245 throw utility::GSL_error(std::string("vector::div",status)); 246 } 247 248 249 bool vector::equal(const vector& other, const double d) const 250 { 251 if (this==&other) 252 return true; 253 if (size()!=other.size()) 254 return false; 255 // if gsl error handler disabled, out of bounds index will not 256 // abort the program. 257 for (size_t i=0; i<size(); ++i) 258 // The two last condition checks are needed for NaN detection 259 if (fabs( (*this)(i)-other(i) ) > d || 260 (*this)(i)!=(*this)(i) || other(i)!=other(i)) 261 return false; 262 return true; 218 263 } 219 264 … … 316 361 317 362 318 bool vector::operator==(const vector& a) const 319 { 320 if (size()!=a.size()) 321 return false; 322 // if gsl error handler disabled, out of bounds index will not 323 // abort the program. 324 for (size_t i=0; i<size(); ++i) 325 if (gsl_vector_get(proxy_v_,i)!=a(i)) 326 return false; 327 return true; 363 bool vector::operator==(const vector& other) const 364 { 365 return equal(other); 366 } 367 368 369 bool vector::operator!=(const vector& other) const 370 { 371 return !equal(other); 328 372 } 329 373 … … 341 385 { 342 386 if( this != &other ) { 343 if (view_) 344 delete view_; 345 else if (view_const_) 346 delete view_const_; 347 else if ( v_ ) 348 gsl_vector_free( v_ ); 349 proxy_v_ = v_ = other.create_gsl_vector_copy(); 387 if (size()!=other.size()) 388 throw utility::GSL_error("vector::operator= vector sizes differ"); 389 for (size_t i=0; i<size(); ++i) 390 gsl_vector_set(v_, i, other(i)); 350 391 } 351 392 return *this; -
trunk/yat/utility/vector.h
r787 r789 219 219 220 220 /** 221 \brief Make a copy of \a other. 222 223 This function will make a deep copy of \a other. Memory is 224 resized and view state is changed if needed. 225 */ 226 const vector& clone(const vector& other); 227 228 /** 221 229 \brief This function performs element-wise division, \f$ this_i = 222 230 this_i/other_i \; \forall i \f$. … … 225 233 */ 226 234 void div(const vector& other); 235 236 /** 237 \brief Check whether vectors are equal within a user defined 238 precision, set by \a precision. 239 240 \return True if each element deviates less or equal than \a 241 d. If any vector contain a NaN, false is always returned. 242 243 \see operator== and operator!= 244 */ 245 bool equal(const vector&, const double precision=0) const; 227 246 228 247 /// … … 321 340 const double& operator[](size_t i) const; 322 341 323 /// 324 /// Comparison operator. Takes linear time. 325 /// 326 /// @return True if the sequence of the elements in the vectors 327 /// are element/wise equal. 328 /// 342 /** 343 \brief Comparison operator. Takes linear time. 344 345 Checks are performed with exact matching, i.e., rounding off 346 effects may destroy comparison. Use the equal function for 347 comparing elements within a user defined precision. 348 349 \return True if all elements are equal otherwise false. 350 351 \see equal 352 */ 329 353 bool operator==(const vector&) const; 354 355 /** 356 \brief Comparison operator. Takes linear time. 357 358 Checks are performed with exact matching, i.e., rounding off 359 effects may destroy comparison. Use the equal function for 360 comparing elements within a user defined precision. 361 362 \return False if all elements are equal otherwise true. 363 364 \see equal 365 */ 366 bool operator!=(const vector&) const; 330 367 331 368 ///
Note: See TracChangeset
for help on using the changeset viewer.