Changeset 638


Ignore:
Timestamp:
Sep 6, 2006, 12:11:35 PM (15 years ago)
Author:
Markus Ringnér
Message:

Fixes #131

Location:
trunk/c++_tools/classifier
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/classifier/MatrixLookupWeighted.cc

    r631 r638  
    1616  MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data,
    1717                                             const utility::matrix& weights)
    18     : DataLookup2D(), data_(&data), weights_(&weights)
     18    : DataLookup2D(), data_(&data), weights_(&weights),weights_owner_(false)
    1919  {
    2020    assert(data.rows()==weights.rows());
     
    2525      column_index_.push_back(i);
    2626  }
     27
     28  MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data)
     29    : DataLookup2D(), data_(&data), weights_owner_(true)
     30  {
     31    utility::matrix weights;
     32    data_->nan(weights);   
     33    weights_= new utility::matrix(weights);
     34    for(size_t i=0;i<(*data_).rows();i++)
     35      row_index_.push_back(i);
     36    for(size_t i=0;i<(*data_).columns();i++)
     37      column_index_.push_back(i);
     38  }
    2739 
    2840
     
    3244                                             const std::vector<size_t>& row,
    3345                                             const std::vector<size_t>& col)
    34     : DataLookup2D(row,col), data_(&data), weights_(&weights)
     46    : DataLookup2D(row,col), data_(&data), weights_(&weights),
     47      weights_owner_(false)
    3548  {
    3649    // Checking that each row index is less than data.rows()
     
    5467                                             const std::vector<size_t>& index,
    5568                                             const bool row)
    56     : DataLookup2D(), data_(&data), weights_(&weights)
     69    : DataLookup2D(), data_(&data), weights_(&weights),weights_owner_(false)
    5770  {
    5871    if (row){
     
    95108
    96109  MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookupWeighted& dv)
    97     : DataLookup2D(dv), data_(dv.data_), weights_(dv.weights_)
     110    : DataLookup2D(dv), data_(dv.data_), weights_(dv.weights_),
     111      weights_owner_(false)
    98112  {
    99113  }
     
    104118                                             const std::vector<size_t>& row,
    105119                                             const std::vector<size_t>& col)
    106     : DataLookup2D(ml,row,col), data_(ml.data_), weights_(ml.weights_)
     120    : DataLookup2D(ml,row,col), data_(ml.data_), weights_(ml.weights_),
     121      weights_owner_(false)
    107122  {
    108123  }
     
    113128                                             const std::vector<size_t>& index,
    114129                                             bool row)
    115     : DataLookup2D(ml,index,row), data_(ml.data_), weights_(ml.weights_)
     130    : DataLookup2D(ml,index,row), data_(ml.data_), weights_(ml.weights_),
     131      weights_owner_(false)
    116132  {
    117133    // Checking that no index is out of range
     
    136152                                             const double value,
    137153                                             const double weight)
    138     : DataLookup2D(rows,columns, true)
     154    : DataLookup2D(rows,columns, true),weights_owner_(true)
    139155  {
    140156    data_ = new utility::matrix(1,1,value);
     
    143159
    144160 
    145     MatrixLookupWeighted::MatrixLookupWeighted(std::istream& is, char sep)
    146     : DataLookup2D(true)
     161  MatrixLookupWeighted::MatrixLookupWeighted(std::istream& is, char sep)
     162    : DataLookup2D(true), weights_owner_(true)
    147163  {
    148164    data_ = new utility::matrix(is,sep);
     
    159175  MatrixLookupWeighted::~MatrixLookupWeighted(void)
    160176  {
    161     if (owner_){
     177    if (owner_)
    162178      delete data_;
     179    if (weights_owner_)
    163180      delete weights_;
    164     }
    165181  }
    166182
  • trunk/c++_tools/classifier/MatrixLookupWeighted.h

    r632 r638  
    3030  /// the matrices.
    3131  ///
    32   /// @todo add on weight part
    33   ///
    3432  class MatrixLookupWeighted : public DataLookup2D
    3533  {
     
    4745    MatrixLookupWeighted(const utility::matrix& matrix,
    4846                         const utility::matrix& weights);
     47
     48   
     49    ///
     50    /// Constructor creating a lookup into the entire @a matrix.  A
     51    /// weight matrix is constructed with weights 1 for values and 0
     52    /// for nan's in @a matrix. @note If @a matrix goes out of scope or
     53    /// is deleted, the MatrixLookupWeighted becomes invalid and the
     54    /// result of further use is undefined.
     55    ///
     56    MatrixLookupWeighted(const utility::matrix& matrix);
     57
    4958
    5059    ///
     
    285294    const utility::matrix* data_;
    286295    const utility::matrix* weights_;
     296    bool weights_owner_;
    287297  }; 
    288298 
  • trunk/c++_tools/classifier/NCC.cc

    r635 r638  
    126126        }
    127127      }
    128       catch (std::bad_cast) {
    129         std::cerr << "Error in NCC::predict: DataLookup2D of unexpected class"
    130                   << std::endl;
     128      catch (std::bad_cast e) {       
     129        std::cerr << "Error in NCC::predict: DataLookup2D of unexpected class. "
     130                  <<  "bad_cast: " << e.what() << std::endl;
    131131      }
    132132    }
Note: See TracChangeset for help on using the changeset viewer.