Changeset 916 for trunk/yat/statistics


Ignore:
Timestamp:
Sep 30, 2007, 2:50:10 AM (14 years ago)
Author:
Peter
Message:

Sorry this commit is a bit to big.

Adding a yat_assert. The yat assert are turned on by providing a
'-DYAT_DEBUG' flag to preprocessor if normal cassert is turned
on. This flag is activated for developers running configure with
--enable-debug. The motivation is that we can use these yat_asserts in
header files and the yat_asserts will be invisible to the normal user
also if he uses C-asserts.

added output operator in DataLookup2D and removed output operator in
MatrixLookup?

Removed template function add_values in Averager and weighted version

Added function to AveragerWeighted? taking iterator to four ranges.

Location:
trunk/yat/statistics
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/statistics/Averager.cc

    r865 r916  
    2525#include "Averager.h"
    2626
     27#include <cassert>
     28
    2729namespace theplu {
    2830namespace yat {
     
    4648  void Averager::add(double d, u_long n)
    4749  {
     50    assert(!std::isnan(d));
    4851    n_  += n;
    4952    x_  += n*d;
  • trunk/yat/statistics/Averager.h

    r914 r916  
    6767    ///
    6868    void add(double d, u_long n=1);
    69 
    70     ///
    71     /// Adding each value in an array \a v \a n (default=1)
    72     /// number of times. The requirements for the type T of the
    73     /// array \a v are: operator[] returning an element and function
    74     /// size() returning the number of elements.
    75     ///   
    76     ///
    77     template <typename T>
    78     void add_values(const T& v, u_long n=1);
    7969
    8070    /**
     
    205195  }
    206196
    207   // Template implementations
    208   template <typename T>
    209   void  Averager::add_values(const T& v, u_long n)
    210   {
    211     for (size_t i=0; i<v.size(); i++)
    212       add(v[i],n);
    213   }
    214 
    215197}}} // of namespace statistics, yat, and theplu
    216198
  • trunk/yat/statistics/AveragerPairWeighted.cc

    r899 r916  
    4949      return;
    5050    }
     51    assert(!std::isnan(x) && "x is nan");
     52    assert(!std::isnan(y) && "y is nan");
     53    assert(!std::isnan(wx) && "wx is nan");
     54    assert(!std::isnan(wy) && "wy is nan");
    5155    double w=wx*wy;
    5256    x_.add(x,w);
     
    8488  double AveragerPairWeighted::correlation(void) const
    8589  {
    86     return covariance() / ( x_.std()*y_.std() );
     90    return ( x_.variance()>0 && y_.variance()>0 ?
     91             covariance() / sqrt(x_.variance()*y_.variance()) : 0 );
    8792  }
    8893
  • trunk/yat/statistics/AveragerPairWeighted.h

    r915 r916  
    3030
    3131#include "yat/utility/IteratorTraits.h"
     32#include "yat/utility/yat_assert.h"
    3233
    3334#include <cmath>
     
    183184  void add(AveragerPairWeighted& ap, Iter1 first1, Iter1 last1, Iter2 first2)
    184185  {
    185     for ( ; first1 != last1; ++first1, ++first2)
     186    for ( ; first1 != last1; ++first1, ++first2) {
    186187      ap.add(utility::iterator_traits_data(first1),
    187188             utility::iterator_traits_data(first2),
    188189             utility::iterator_traits_weight(first1),
    189190             utility::iterator_traits_weight(first2));
     191    }
    190192  }
    191193
     
    197199                                         const T4& wy)
    198200  {
    199     for (size_t i=0; i<x.size(); i++)
     201    for (size_t i=0; i<x.size(); ++i){
     202      yat_assert(!std::isnan(x[i]));
    200203      add(x[i],y[i],wx[i],wy[i]);
     204    }
    201205  }
    202206
  • trunk/yat/statistics/AveragerWeighted.h

    r915 r916  
    8383
    8484    ///
    85     /// Adding each value in an array \a x and corresponding value in
    86     /// weight array \a w.
    87     ///
    88     /// The requirements for the types T1 and T2 of the arrays \a x
    89     /// and \a w are: operator[] returning an element and function
    90     /// size() returning the number of elements.
    91     ///
    92     template <typename T1, typename T2>
    93     void add_values(const T1& x, const T2& w);
    94 
    95     ///
    9685    /// @brief Calculate the weighted mean
    9786    ///
     
    221210
    222211  /**
    223      \brief adding a ranges of values to AveragerWeighted \a a
     212     \brief adding a range of values to AveragerWeighted \a a
    224213   */
    225214  template <typename Iter>
     
    230219  }
    231220
    232   // Template implementations
    233   template <typename T1, typename T2>
    234   void AveragerWeighted::add_values(const T1& x, const T2& w)
     221  /**
     222     \brief add values from two ranges to AveragerWeighted \a a
     223
     224     Add data from range [first1, last1) with their corresponding
     225     weight in range [first2, first2 + distance(first, last) ).
     226
     227     Requirement: Iter1 and Iter2 are unweighted iterators.
     228   */
     229  template <typename Iter1, typename Iter2>
     230  void add(AveragerWeighted& a, Iter1 first1, Iter1 last1, Iter2 first2)
    235231  {
    236     for (size_t i=0; i<x.size(); i++)
    237       add(x[i],w[i]);
     232    utility::check_iterator_is_unweighted(first1);
     233    utility::check_iterator_is_unweighted(first2);
     234    for ( ; first1 != last1; ++first1, ++first2)
     235      a.add(*first1, *first2);
    238236  }
    239237
    240 ///
    241 /// The AveragerWeighted output operator
    242 ///
    243 ///std::ostream& operator<<(std::ostream& s,const AveragerWeighted&);
    244 
    245238}}} // of namespace statistics, yat, and theplu
    246239
  • trunk/yat/statistics/vector_distance.h

    r909 r916  
    7171    return vector_distance(beg1,end1,beg2, typename statistics::vector_distance_traits<Dist>::distance());
    7272  }
    73 
    7473 
    7574}}} // of namespace statistics, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.