Changeset 808


Ignore:
Timestamp:
Mar 15, 2007, 9:07:01 PM (16 years ago)
Author:
Peter
Message:

previous argument was invalid, but here is an implementation. Fixes #205

Location:
trunk/yat
Files:
6 edited

Legend:

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

    r768 r808  
    106106    assert(data_.rows()==input.rows());
    107107
     108    //    utility
     109    //for (size_t i=0;
     110
     111
    108112    prediction = utility::matrix(centroids_.columns(),input.columns());
    109113    for (size_t c=0; c<centroids_.columns(); ++c) {
  • trunk/yat/classifier/NBC.h

    r768 r808  
    8282
    8383   
    84     ///
    85     /// For each sample, calculate the probabilies the sample belong
    86     /// to the corresponding class.
    87     ///
     84    /**
     85       For each sample, calculate the probabilities the sample belong
     86      to the corresponding class.
     87    */
    8888    void predict(const DataLookup2D& data, utility::matrix& res) const;
    8989
  • trunk/yat/utility/matrix.cc

    r796 r808  
    55  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
    66  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    7   Copyright (C) 2007 Jari Häkkinen
     7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    88
    99  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    269269
    270270
     271  void matrix::resize(size_t r, size_t c, double init_value)
     272  {
     273      if (view_)
     274        delete view_;
     275      else if (view_const_)
     276        delete view_const_;
     277      else if (m_)
     278        gsl_matrix_free(m_);
     279      proxy_m_ = m_ = gsl_matrix_alloc(r,c);
     280      if (!m_)
     281        throw utility::GSL_error("matrix::matrix failed to allocate memory");
     282      set_all(init_value);
     283
     284      // no need to delete blas_result_ if the number of rows fit, it
     285      // may be useful later.
     286      if (blas_result_ && (blas_result_->size1!=rows())) {
     287        gsl_matrix_free(blas_result_);
     288        blas_result_=NULL;
     289      }
     290  }
     291
     292
    271293  size_t matrix::rows(void) const
    272294  {
  • trunk/yat/utility/matrix.h

    r792 r808  
    99  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
    1010  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    11   Copyright (C) 2007 Jari Häkkinen
     11  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    1212
    1313  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    146146
    147147       This function will make a deep copy of \a other. Memory is
    148        resized and view state is changed if needed.
     148       resized and view state is changed to same as in other.
    149149    */
    150150    const matrix& clone(const matrix& other);
     
    201201    */
    202202    void mul(const matrix& b);
     203
     204    ///
     205    /// @breif resize matrix
     206    ///
     207    /// All elements are set to @a init_value.
     208    ///
     209    void resize(size_t, size_t, double init_value=0);
    203210
    204211    ///
  • trunk/yat/utility/vector.cc

    r791 r808  
    291291
    292292
     293  void vector::resize(size_t n, double init_value)
     294  {
     295    if (view_)
     296      delete view_;
     297    else if (view_const_)
     298      delete view_const_;
     299    else if (v_)
     300      gsl_vector_free(v_);
     301    proxy_v_ = v_ = gsl_vector_alloc(n);
     302
     303    if (!v_)
     304      throw utility::GSL_error("vector::vector failed to allocate memory");
     305    set_all(init_value);
     306  }
     307
     308
    293309  void vector::reverse(void)
    294310  {
  • trunk/yat/utility/vector.h

    r791 r808  
    267267    void mul(const vector& other);
    268268
     269    ///
     270    /// @breif resize vector
     271    ///
     272    /// All elements are set to @a init_value.
     273    ///
     274    void resize(size_t, double init_value=0);
     275
    269276    /**
    270277       \brief Reverse the order of elements in the vector.
Note: See TracChangeset for help on using the changeset viewer.