Changeset 3320


Ignore:
Timestamp:
Sep 19, 2014, 8:15:58 AM (7 years ago)
Author:
Peter
Message:

speedup. assume Distance is symmetric. closes #814

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/IGP.h

    r3319 r3320  
    2828#include "Target.h"
    2929#include "yat/utility/concept_check.h"
     30#include "yat/utility/Matrix.h"
    3031#include "yat/utility/Vector.h"
    3132#include "yat/utility/yat_assert.h"
     
    5354     http://biostatistics.oxfordjournals.org/cgi/content/abstract/kxj029v1">
    5455     Kapp and Tibshirani, Biostatistics (2006)</a>.
     56
     57     \note Distance must be symmetric, i.e., Distance(x,y) == Distance(y,x).
    5558  */
    5659  template <typename Distance>
     
    126129
    127130    // Calculate IGP for each class
    128     igp_ = utility::Vector(target_.nof_classes());
     131    igp_.resize(target_.nof_classes(), 0.0);
    129132
     133    // calculate distances
     134    utility::Matrix dist(matrix_.columns(), matrix_.columns());
     135    for (size_t i=0; i<dist.rows(); ++i)
     136      for (size_t j=i+1; j<dist.rows(); ++j) {
     137        dist(i,j) = dist(j,i) = distance_(matrix_.begin_column(i),
     138                                          matrix_.end_column(i),
     139                                          matrix_.begin_column(j));
     140      }
     141
     142    // find nearest neigbour for each sample
    130143    for(size_t i=0; i<target_.size(); i++) {
    131144      size_t neighbor=i;
     
    134147        if (i==j) // avoid self-self comparison
    135148          continue;
    136         double dist = distance_(matrix_.begin_column(i), matrix_.end_column(i),
    137                                 matrix_.begin_column(j));
    138         if(dist<mindist) {
    139           mindist=dist;
     149        if(dist(i,j)<mindist) {
     150          mindist=dist(i,j);
    140151          neighbor=j;
    141152        }
Note: See TracChangeset for help on using the changeset viewer.