Changeset 1483


Ignore:
Timestamp:
Sep 9, 2008, 6:03:15 PM (13 years ago)
Author:
Peter
Message:

refs #396 - removing a constructor in MatrixLookupWeighted? - needed to re-organize tests in ncc_test to track down an error

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r1458 r1483  
    4040  iterator_test kernel_lookup_test kernel_test \
    4141  knn_test large_file_test matrix_lookup_test matrix_test \
    42   nbc_test \
     42  matrix_weighted_test nbc_test \
    4343  ncc_test nni_test normalization_test pca_test \
    4444  range_test regression_test rnd_test roc_test \
     
    8181large_file_test_SOURCES = large_file_test.cc
    8282matrix_test_SOURCES = matrix_test.cc
     83matrix_weighted_test_SOURCES = matrix_weighted_test.cc
    8384matrix_lookup_test_SOURCES = matrix_lookup_test.cc
    8485nbc_test_SOURCES = nbc_test.cc
  • trunk/test/distance_test.cc

    r1437 r1483  
    2929#include "yat/statistics/PearsonDistance.h"
    3030#include "yat/utility/Matrix.h"
     31#include "yat/utility/MatrixWeighted.h"
    3132#include "yat/utility/Vector.h"
    3233
     
    227228{
    228229  utility::Matrix x=data();
    229   classifier::MatrixLookupWeighted ml(x);
    230   double dist1 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1));
     230  utility::MatrixWeighted mw(x);
     231  double dist1 = dist(mw.begin_row(0), mw.end_row(0), mw.begin_row(1));
    231232  double dist2 = dist(x.begin_row(0), x.end_row(0), x.begin_row(1));
    232233  check_equality(dist1, dist2, suite, "unity weights", N);
  • trunk/test/ncc_test.cc

    r1437 r1483  
    4646using namespace theplu::yat;
    4747
     48void predict_nan_data_unweighted_data(test::Suite& suite);
     49
    4850int main(int argc,char* argv[])
    4951
    5052  test::Suite suite(argc, argv);
    5153  suite.err() << "testing ncc" << std::endl;
     54
     55  predict_nan_data_unweighted_data(suite);
    5256
    5357  /////////////////////////////////////////////
     
    253257  return suite.return_value();
    254258}
     259
     260void predict_nan_data_unweighted_data(test::Suite& suite)
     261{
     262  //////////////////////////////////////////////////////////////////////////
     263  // A test of predictions using weighted training resulting in NaN's
     264  // in centroids and unweighted test data
     265  //////////////////////////////////////////////////////////////////////////
     266  suite.err() << "test of predictions using nan centroids and unweighted test data\n";
     267  utility::Matrix data1(3,4);
     268  for(size_t i=0;i<3;i++) {
     269    data1(i,0)=3-i;
     270    data1(i,1)=5-i;
     271    data1(i,2)=i+1;
     272    data1(i,3)=i+3;
     273  }
     274  std::vector<std::string> vec1(4, "pos");
     275  vec1[0]="neg";
     276  vec1[1]="neg";
     277
     278  classifier::MatrixLookup ml1(data1);
     279  classifier::Target target1(vec1);
     280  utility::Matrix prediction1;
     281  utility::Matrix result1(2,4);
     282
     283  utility::Matrix weights2(3,4,1.0);
     284  weights2(1,0)=weights2(1,1)=0.0;
     285
     286  classifier::MatrixLookupWeighted mlw2(data1,weights2);
     287  classifier::NCC<statistics::EuclideanDistance> ncc2;
     288  ncc2.train(mlw2,target1);
     289  ncc2.predict(ml1,prediction1); 
     290  result1(0,0)=result1(0,1)=result1(1,2)=result1(1,3)=sqrt(3.0);
     291  result1(1,0)=result1(1,1)=sqrt(11.0);
     292  result1(0,2)=result1(0,3)=sqrt(15.0);
     293  if(!std::isnan(ncc2.centroids()(1,0)))
     294    suite.add(false);
     295  if (!suite.equal_range(prediction1.begin(), prediction1.end(),
     296                         result1.begin())) {
     297    suite.add(false);
     298    suite.err() << "Difference to expected prediction too large\n";
     299  }
     300}
  • trunk/yat/classifier/MatrixLookupWeighted.cc

    r1482 r1483  
    8888
    8989
     90  /*
    9091  MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data)
    9192    : data_(MatrixP(&data, false))
     
    9899    assert(validate());
    99100  }
     101  */
    100102
    101103
  • trunk/yat/classifier/MatrixLookupWeighted.h

    r1482 r1483  
    107107       \brief Create a lookup into entire \a matrix.
    108108     */
    109     MatrixLookupWeighted(const utility::MatrixWeighted& matrix);
     109    explicit MatrixLookupWeighted(const utility::MatrixWeighted& matrix);
    110110
    111111    ///
     
    133133    /// result of further use is undefined.
    134134    ///
    135     MatrixLookupWeighted(const utility::Matrix& matrix);
     135    //MatrixLookupWeighted(const utility::Matrix& matrix);
    136136
    137137
  • trunk/yat/classifier/NCC.h

    r1437 r1483  
    3434#include "yat/statistics/AveragerWeighted.h"
    3535#include "yat/utility/Matrix.h"
     36#include "yat/utility/MatrixWeighted.h"
    3637#include "yat/utility/Vector.h"
    3738#include "yat/utility/stl_utility.h"
     
    294295                                          utility::Matrix& prediction) const
    295296  {
    296     MatrixLookupWeighted weighted_centroids(centroids_);
     297    utility::MatrixWeighted weighted_centroids(centroids_);
    297298    for(size_t j=0; j<test.columns();j++)
    298299      for(size_t k=0; k<centroids_.columns();k++)
  • trunk/yat/utility/MatrixWeighted.cc

    r1469 r1483  
    123123    assert(data.columns()==weight.columns());
    124124    columns_ = data.columns();
    125     resize(data.columns(), data.rows());
     125    resize(data.rows(), data.columns());
     126    assert(rows()==data.rows());
     127    assert(columns()==data.columns());
    126128    std::copy(data.begin(), data.end(), data_iterator(vec_.begin()));
    127129    std::copy(weight.begin(), weight.end(), weight_iterator(vec_.begin()));
     
    169171    columns_ = columns;
    170172    vec_.resize(rows*columns);
     173    assert(this->rows()==rows);
     174    assert(this->columns()==columns);
    171175  }
    172176
Note: See TracChangeset for help on using the changeset viewer.