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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.