Changeset 1043 for trunk/yat


Ignore:
Timestamp:
Feb 6, 2008, 8:30:03 PM (14 years ago)
Author:
Peter
Message:

fixing #128 - iterators in Averger classes

Location:
trunk/yat
Files:
9 edited

Legend:

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

    r1000 r1043  
    5555  assert(x.size()==y.size());
    5656  statistics::AveragerPairWeighted averager;
    57   averager.add(x,y);
     57  add(averager, x.begin(),x.end(), y.begin());
    5858  if(order_>1)
    5959    return pow(1+averager.sum_xy(),order_);
     
    6767  assert(x.size()==y.size());
    6868  statistics::AveragerPairWeighted averager;
    69   averager.add(x,y);
     69  add(averager, x.begin(), x.end(),y.begin());
    7070  if(order_>1)
    7171    return pow(1+averager.sum_xy(),order_);
  • trunk/yat/regression/LinearWeighted.cc

    r1020 r1043  
    7575    // want.
    7676    ap_.reset();
    77     ap_.add_values(x,y,utility::vector(x.size(),1),w);
     77    yat::utility::vector dummy(x.size(), 1.0);
     78    add(ap_, x.begin(), x.end(), y.begin(),dummy.begin(),w.begin());
    7879
    7980    alpha_ = m_y();
  • trunk/yat/regression/NaiveWeighted.cc

    r1020 r1043  
    5151    assert(y.size()==w.size());
    5252    ap_.reset();
    53     ap_.add_values(x,y,utility::vector(x.size(),1.0), w);
     53    utility::vector dummy(x.size(),1.0);
     54    add(ap_, x.begin(), x.end(), y.begin(),dummy.begin(), w.begin());
    5455    chisq_ = ap_.y_averager().sum_xx_centered();
    5556  }
  • trunk/yat/regression/Polynomial.cc

    r1019 r1043  
    5252                       const utility::VectorBase& y)
    5353  {
    54     ap_.add_values(x,y);
     54    add(ap_, x.begin(), x.end(), y.begin());
    5555    utility::matrix X=utility::matrix(x.size(),power_+1,1);
    5656    for (size_t i=0; i<X.rows(); ++i)
  • trunk/yat/regression/PolynomialWeighted.cc

    r1020 r1043  
    5252    // product wx*wy, so we can send in w and a dummie to get what we
    5353    // want.
    54     ap_.add_values(x,y,utility::vector(x.size(),1),w);
     54    utility::vector dummy(x.size(), 1.0);
     55    add(ap_,x.begin(), x.end(),y.begin(),dummy.begin(),w.begin());
    5556    utility::matrix X=utility::matrix(x.size(),power_+1,1);
    5657    for (size_t i=0; i<X.rows(); ++i)
  • trunk/yat/statistics/AveragerPair.h

    r1000 r1043  
    7070    void add(const double x, const double y, const unsigned long n=1);
    7171
    72     ///
    73     /// Adding pairs of arrays with data points \a x and \a y.
    74     ///
    75     /// The requirements for the types T1 and T2 of the arrays \a x
    76     /// and \a y are: operator[] returning an element and function
    77     /// size() returning the number of elements.
    78     ///   
    79     template <typename T1, typename T2>
    80     void add_values(const T1& x, const T2& y);
    81 
    82     ///
    83     /// \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sum_i
    84     /// (x_i-m_x)^2+\sum_i (y_i-m_y)^2 + n(m_x-m_y)^2} \f$
    85     ///
    86     /// In case of a zero denominator - zero is returned.
    87     ///
    88     /// @return Concordence correlation coefficient.
    89     ///
     72    /**
     73       \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sum_i
     74       (x_i-m_x)^2+\sum_i (y_i-m_y)^2 + n(m_x-m_y)^2} \f$
     75       
     76       In case of a zero denominator - zero is returned.
     77       
     78       @return Concordence correlation coefficient.
     79    */
    9080    double ccc(void) const;
    9181
     
    172162
    173163  /**
    174      \brief adding a ranges of values to AveragerPair \a ap
     164     \brief adding data from two ranges to AveragerPair \a ap
    175165   */
    176166  template <class Iter1, class Iter2>
     
    184174
    185175
    186   // Template implementations
    187   template <typename T1, typename T2>
    188   void AveragerPair::add_values(const T1& x, const T2& y)
    189   {
    190     for (size_t i=0; i<x.size(); i++)
    191       add(x[i],y[i]);
    192   }
    193 
    194 
    195176}}} // of namespace statistics, yat, and theplu
    196177
  • trunk/yat/statistics/AveragerPairWeighted.cc

    r1000 r1043  
    5858    wxy_ += w*x*y;   
    5959    w_ +=w;
    60   }
    61 
    62 
    63   void AveragerPairWeighted::add(const classifier::DataLookup1D& x,
    64                                  const classifier::DataLookupWeighted1D& y)
    65   {
    66     assert(x.size()==y.size());
    67     for (size_t i=0; i<x.size(); ++i)
    68       add(x(i), y.data(i), 1.0, y.weight(i));
    69   }
    70 
    71 
    72   void AveragerPairWeighted::add(const classifier::DataLookupWeighted1D& x,
    73                                  const classifier::DataLookup1D& y)
    74   {
    75     add(y,x);
    76   }
    77 
    78 
    79   void AveragerPairWeighted::add(const classifier::DataLookupWeighted1D& x,
    80                                  const classifier::DataLookupWeighted1D& y)
    81   {
    82     assert(x.size()==y.size());
    83     for (size_t i=0; i<x.size(); ++i)
    84       add(x.data(i), y.data(i), x.weight(i), y.weight(i));
    8560  }
    8661
  • trunk/yat/statistics/AveragerPairWeighted.h

    r1009 r1043  
    7373    void  add(const double x, const double y,
    7474              const double wx, const double wy);
    75 
    76     ///
    77     /// Adding two sequences of data @a x and @a y. The data
    78     /// should be paired so \f$ x(i) \f$ is associated to \f$ y(i) \f$
    79     /// @a x will be treated as having all weights equal to unity
    80     ///
    81     void add(const classifier::DataLookup1D& x,
    82              const classifier::DataLookupWeighted1D& y);
    83 
    84     ///
    85     /// Adding two sequences of data @a x and @a y. The data should be
    86     /// paired so \f$ x(i) \f$ is associated to \f$ y(i) \f$
    87     /// @a y will be treated as having all weights equal to unity
    88     ///
    89     void add(const classifier::DataLookupWeighted1D& x,
    90              const classifier::DataLookup1D& y);
    91 
    92     ///
    93     /// Adding two sequences of weighted data @a x and @a y. The data
    94     /// should be paired so \f$ x(i) \f$ is associated to \f$ y(i) \f$
    95     ///
    96     void add(const classifier::DataLookupWeighted1D& x,
    97              const classifier::DataLookupWeighted1D& y);
    98 
    99     ///
    100     /// Adding pair of data and corresponding pair of weights in arrays
    101     ///
    102     ///
    103     /// The requirements for the types T1, T2, T3 and T4 of the arrays
    104     /// are: operator[] returning an element and function /// size()
    105     /// returning the number of elements.
    106     ///
    107     template <typename T1,typename T2,typename T3,typename T4>
    108     void add_values(const T1& x,
    109                     const T2& y,
    110                     const T3& wx,
    111                     const T4& wy);
    11275
    11376    ///
     
    194157
    195158
    196   template <typename T1,typename T2,typename T3,typename T4>
    197   void  AveragerPairWeighted::add_values(const T1& x,
    198                                          const T2& y,
    199                                          const T3& wx,
    200                                          const T4& wy)
     159  /**
     160     \brief adding four ranges of values to AveragerPairWeighted \a ap
     161   */
     162  template <class Iter1, class Iter2, class Iter3, class Iter4>
     163  void add(AveragerPairWeighted& ap, Iter1 x, Iter1 xlast, Iter2 y, Iter3 wx,
     164           Iter4 wy)
    201165  {
    202     for (size_t i=0; i<x.size(); ++i){
    203       utility::yat_assert<std::runtime_error>(!std::isnan(x(i)));
    204       add(x[i],y[i],wx[i],wy[i]);
     166    utility::check_iterator_is_unweighted(x);
     167    utility::check_iterator_is_unweighted(y);
     168    utility::check_iterator_is_unweighted(wx);
     169    utility::check_iterator_is_unweighted(wy);
     170    while (x!=xlast) {
     171      ap.add(*x, *y, *wx, *wy);
     172      ++x;
     173      ++y;
     174      ++wx;
     175      ++wy;
    205176    }
    206177  }
     178
    207179
    208180}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/AveragerWeighted.h

    r1000 r1043  
    211211  /**
    212212     \brief adding a range of values to AveragerWeighted \a a
     213
     214     If iterator is non-weighted unitary weights are used.
    213215   */
    214216  template <typename Iter>
Note: See TracChangeset for help on using the changeset viewer.