Changeset 916 for trunk/yat/classifier


Ignore:
Timestamp:
Sep 30, 2007, 2:50:10 AM (14 years ago)
Author:
Peter
Message:

Sorry this commit is a bit to big.

Adding a yat_assert. The yat assert are turned on by providing a
'-DYAT_DEBUG' flag to preprocessor if normal cassert is turned
on. This flag is activated for developers running configure with
--enable-debug. The motivation is that we can use these yat_asserts in
header files and the yat_asserts will be invisible to the normal user
also if he uses C-asserts.

added output operator in DataLookup2D and removed output operator in
MatrixLookup?

Removed template function add_values in Averager and weighted version

Added function to AveragerWeighted? taking iterator to four ranges.

Location:
trunk/yat/classifier
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/DataLookup2D.cc

    r865 r916  
    139139  }
    140140
     141  std::ostream& operator<<(std::ostream& s, const DataLookup2D& m)
     142  {
     143    s.setf(std::ios::dec);
     144    s.precision(12);
     145    for(size_t i=0, j=0; i<m.rows(); i++)
     146      for (j=0; j<m.columns(); j++) {
     147        s << m(i,j);
     148        if (j<m.columns()-1)
     149          s << s.fill();
     150        else if (i<m.rows()-1)
     151          s << "\n";
     152      }
     153    return s;
     154  }
     155
    141156}}} // of namespace classifier, yat, and theplu
  • trunk/yat/classifier/DataLookup2D.h

    r865 r916  
    175175  }; 
    176176 
     177  ///
     178  /// The output operator DataLookup2D
     179  ///
     180  std::ostream& operator<< (std::ostream& s, const DataLookup2D&);
     181
    177182}}} // of namespace classifier, yat, and theplu
    178183
  • trunk/yat/classifier/KNN.h

    r904 r916  
    1010#include "yat/statistics/vector_distance.h"
    1111#include "yat/utility/matrix.h"
    12 
     12#include "yat/utility/yat_assert.h"
     13
     14#include <cmath>
    1315#include <map>
    1416
     
    119121
    120122    // matrix with training samples as rows and test samples as columns
    121     utility::matrix* distances = new utility::matrix(data_.columns(),input.columns());
     123    utility::matrix* distances =
     124      new utility::matrix(data_.columns(),input.columns());
    122125     
    123126    if(weighted_data && weighted_input) {
     
    126129        for(size_t j=0; j<input.columns(); j++) {
    127130          classifier::DataLookupWeighted1D test(*weighted_input,j,false);
     131          yat_assert(training.size()==test.size());
    128132          (*distances)(i,j)=statistics::vector_distance(training.begin(),training.end(),test.begin(),typename statistics::vector_distance_traits<Distance>::distance());
     133          yat_assert(!std::isnan((*distances)(i,j)));
    129134        }
    130135      }
     
    186191    utility::matrix* distances=calculate_distances(input);
    187192   
    188     // for each test sample (column in distances) find the closest training samples
    189     prediction.clone(utility::matrix(target_.nof_classes(), input.columns(),0.0));
     193    // for each test sample (column in distances) find the closest
     194    // training samples
     195    prediction.clone(utility::matrix(target_.nof_classes(),input.columns(),0.0));
    190196    for(size_t sample=0;sample<distances->columns();sample++) {
    191197      std::vector<size_t> k_index;
  • trunk/yat/classifier/MatrixLookup.cc

    r865 r916  
    217217
    218218
    219   std::ostream& operator<<(std::ostream& s, const MatrixLookup& m)
    220   {
    221     s.setf(std::ios::dec);
    222     s.precision(12);
    223     for(size_t i=0, j=0; i<m.rows(); i++)
    224       for (j=0; j<m.columns(); j++) {
    225         s << m(i,j);
    226         if (j<m.columns()-1)
    227           s << s.fill();
    228         else if (i<m.rows()-1)
    229           s << "\n";
    230       }
    231     return s;
    232   }
    233 
    234219
    235220
  • trunk/yat/classifier/MatrixLookup.h

    r865 r916  
    284284  }; 
    285285 
    286   ///
    287   /// The output operator MatrixLookup
    288   ///
    289   std::ostream& operator<< (std::ostream& s, const MatrixLookup&);
    290 
    291286}}} // of namespace classifier, yat, and theplu
    292287
  • trunk/yat/classifier/NCC.cc

    r898 r916  
    130130        for(size_t k=0; k<centroids_.columns();k++) {
    131131          DataLookupWeighted1D centroid(weighted_centroids,k,false);
     132
     133          assert(in.size()==centroid.size());
    132134          prediction(k,j)=(*distance_)(in.begin(),in.end(),centroid.begin());
    133135        }
Note: See TracChangeset for help on using the changeset viewer.