Changeset 774 for trunk/yat


Ignore:
Timestamp:
Mar 1, 2007, 10:52:48 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Fixes #194.

Location:
trunk/yat
Files:
3 edited

Legend:

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

    r720 r774  
    5353  {
    5454    utility::matrix weights;
    55     data_->nan(weights);   
     55    utility::nan(*data_,weights);
    5656    weights_= new utility::matrix(weights);
    5757    ref_count_weights_=new u_int(1);
     
    214214      column_index_.push_back(i);
    215215    utility::matrix weights;
    216     data_->nan(weights);   
     216    utility::nan(*data_,weights);
    217217    weights_= new utility::matrix(weights);
    218218    ref_count_weights_=new u_int(1);
  • trunk/yat/utility/matrix.cc

    r773 r774  
    213213
    214214
    215   bool matrix::isnull(void) const
    216   {
    217     return gsl_matrix_isnull(m_);
    218   }
    219 
    220 
    221215  bool matrix::isview(void) const
    222216  {
    223217    return view_;
    224   }
    225 
    226 
    227   double matrix::max(void) const
    228   {
    229     return gsl_matrix_max(m_);
    230   }
    231 
    232 
    233   double matrix::min(void) const
    234   {
    235     return gsl_matrix_min(m_);
    236   }
    237 
    238 
    239   void matrix::minmax_index(std::pair<size_t,size_t>& min,
    240                             std::pair<size_t,size_t>& max) const
    241   {
    242     gsl_matrix_minmax_index(m_, &min.first, &min.second, &max.first,
    243                             &max.second);
    244   }
    245 
    246 
    247   bool matrix::nan(matrix &m) const
    248   {
    249     m=matrix(rows(),columns(),1.0);
    250     bool nan=false;
    251     for (size_t i=0; i<rows(); i++)
    252       for (size_t j=0; j<columns(); j++)
    253         if (std::isnan(operator()(i,j))) {
    254           m(i,j)=0;
    255           nan=true;
    256         }
    257     return nan;
    258218  }
    259219
     
    302262    if (status)
    303263      throw utility::GSL_error(std::string("matrix::set_row",status));
    304   }
    305 
    306 
    307   void matrix::swap(matrix& other)
    308   {
    309     int status=gsl_matrix_swap(m_, other.m_);
    310     if (status)
    311       throw utility::GSL_error(std::string("matrix::swap",status));
    312264  }
    313265
     
    455407
    456408
     409  bool isnull(const matrix& m)
     410  {
     411    return gsl_matrix_isnull(m.gsl_matrix_p());
     412  }
     413
     414
     415  double max(const matrix& m)
     416  {
     417    return gsl_matrix_max(m.gsl_matrix_p());
     418  }
     419
     420
     421  double min(const matrix& m)
     422  {
     423    return gsl_matrix_min(m.gsl_matrix_p());
     424  }
     425
     426
     427  void minmax_index(const matrix& m,
     428                    std::pair<size_t,size_t>& min, std::pair<size_t,size_t>& max)
     429  {
     430    gsl_matrix_minmax_index(m.gsl_matrix_p(), &min.first, &min.second,
     431                            &max.first, &max.second);
     432  }
     433
     434
     435  bool nan(const matrix& templat, matrix& flag)
     436  {
     437    size_t rows=templat.rows();
     438    size_t columns=templat.columns();
     439    if (rows!=flag.rows() && columns!=flag.columns())
     440      flag=matrix(rows,columns,1.0);
     441    else
     442      flag.set_all(1.0);
     443    bool nan=false;
     444    for (size_t i=0; i<rows; i++)
     445      for (size_t j=0; j<columns; j++)
     446        if (std::isnan(templat(i,j))) {
     447          flag(i,j)=0;
     448          nan=true;
     449        }
     450    return nan;
     451  }
     452
     453
     454  void swap(matrix& a, matrix& b)
     455  {
     456    int status=gsl_matrix_swap(a.gsl_matrix_p(), b.gsl_matrix_p());
     457    if (status)
     458      throw utility::GSL_error(std::string("matrix::swap",status));
     459  }
     460
     461
    457462  std::ostream& operator<<(std::ostream& s, const matrix& m)
    458463  {
  • trunk/yat/utility/matrix.h

    r773 r774  
    177177
    178178    ///
    179     /// @return True if all elements in the matrix is zero, false
    180     /// othwerwise;
    181     ///
    182     bool isnull(void) const;
    183 
    184     ///
    185179    /// @brief Check if the matrix object is a view (sub-matrix) to
    186180    /// another matrix.
     
    189183    ///
    190184    bool isview(void) const;
    191 
    192     ///
    193     /// @return The maximum value of the matrix.
    194     ///
    195     double max(void) const;
    196 
    197     ///
    198     /// @return The minimum value of the matrix.
    199     ///
    200     double min(void) const;
    201 
    202     ///
    203     /// @return The indecies to the element with the minimum and
    204     /// maximum values of the matrix, respectively. The lowest index
    205     /// has precedence (searching in row-major order).
    206     ///
    207     void minmax_index(std::pair<size_t,size_t>& min,
    208                       std::pair<size_t,size_t>& max) const;
    209 
    210     ///
    211     /// The argument is changed into a matrix containing 1's and 0's
    212     /// only. 1 means element in matrix is valid and a zero means
    213     /// element is a NaN.
    214     ///
    215     /// @return true if matrix contains at least one NaN.
    216     ///
    217     bool nan(matrix&) const;
    218185
    219186    /**
     
    266233    */
    267234    void set_row(const size_t row, const vector& vec);
    268 
    269     /**
    270        \brief Exchange the elements of the this and \a other by copying.
    271 
    272        The two matrices must have the same size.
    273 
    274        \throw GSL_error if either index is out of bounds.
    275     */
    276     void swap(matrix& other);
    277235
    278236    /**
     
    453411  };
    454412
    455   ///
    456   /// The output operator for the matrix class.
    457   ///
     413  /**
     414     \brief Check if all elements of the matrix are zero.
     415
     416     \return True if all elements in the matrix is zero, false othwerwise
     417  */
     418  bool isnull(const matrix&);
     419
     420  /**
     421     \brief Get the maximum value in the matrix.
     422
     423     \return The maximum value of the matrix.
     424  */
     425  double max(const matrix&);
     426
     427  /**
     428     \brief Get the minimum value in the matrix.
     429
     430     \return The minimum value of the matrix.
     431  */
     432  double min(const matrix&);
     433
     434  /**
     435     \brief Locate the maximum and minumum element in the matrix.
     436
     437     \return The indecies to the element with the minimum and maximum
     438     values of the matrix, respectively.
     439
     440     \note The lowest index has precedence (searching in row-major
     441     order).
     442  */
     443  void minmax_index(const matrix&,
     444                    std::pair<size_t,size_t>& min,
     445                    std::pair<size_t,size_t>& max);
     446
     447  /**
     448     \brief Create a matrix \a flag indicating NaN's in another matrix
     449     \a templat.
     450
     451     The \a flag matrix is changed to contain 1's and 0's only. A 1
     452     means that the corresponding element in the \a templat matrix is
     453     valid and a zero means that the corresponding element is a NaN.
     454
     455     \note Space for matrix \a flag is reallocated to fit the size of
     456     matrix \a templat if sizes mismatch.
     457
     458     \return True if the \a templat matrix contains at least one NaN.
     459  */
     460  bool nan(const matrix& templat, matrix& flag);
     461
     462  /**
     463     \brief Exchange all elements between the matrices by copying.
     464
     465     The two matrices must have the same size.
     466
     467     \throw GSL_error if either index is out of bounds.
     468  */
     469  void swap(matrix&, matrix&);
     470
     471  /**
     472     \brief The output operator for the matrix class.
     473  */
    458474  std::ostream& operator<< (std::ostream& s, const matrix&);
    459475
Note: See TracChangeset for help on using the changeset viewer.