# Changeset 3528

Ignore:
Timestamp:
Oct 11, 2016, 9:35:40 AM (7 years ago)
Message:

refs #803. use new iterator concept in AveragerWeighted?

File:
1 edited

### Legend:

Unmodified
 r2564 */ #include "yat/utility/concept_check.h" #include "yat/utility/iterator_traits.h" /// be more precise than others. The larger weight a measurement has /// the more precise is is assumed to be, or more formally the /// weight is proportional to the reciprocal variance /// weight is proportional to the reciprocal variance /// \f$\sigma_i^2 = \frac{\sigma^2}{w_i} \f$. 2) Probability weights /// are used for the situation when calculating averages over a /// are taken to be \f$\sum \frac{f}{f'}X \f$ For further discussion: /// see \ref weighted_statistics /// /// /// If nothing else stated, each function fulfills the /// following:
• Setting a weight to zero corresponds to /// /// @brief The default constructor /// /// AveragerWeighted(void); /// /// @brief Calculate the weighted mean /// /// @return \f$\frac{\sum w_ix_i}{\sum w_i} \f$ /// @brief Calculate the weighted mean /// /// @return \f$\frac{\sum w_ix_i}{\sum w_i} \f$ /// double mean(void) const; /// /// @brief Weighted version of number of data points. /// @brief Weighted version of number of data points. /// /// If all /// /// @return \f$\frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$ /// /// double n(void) const; /// approximation, use bootstrapping to estimate the error. /// /// @return \f$\frac{\sum w^2}{\left(\sum w\right)^3}\sum w(x-m)^2 \f$ /// where \f$m \f$ is the mean() /// @return \f$\frac{\sum w^2}{\left(\sum w\right)^3}\sum w(x-m)^2 \f$ /// where \f$m \f$ is the mean() /// double standard_error(void) const; /// /// Calculating the sum of weights /// Calculating the sum of weights /// /// @return \f$\sum w_i \f$ /// /// \f$\sum w_ix_i \f$ /// \f$\sum w_ix_i \f$ /// /// @return weighted sum of x /** The variance is calculated as \f$\frac{\sum w_i (x_i - m)^2 }{\sum w_i} \f$, where \a m is the known mean. }{\sum w_i} \f\$, where \a m is the known mean. @return Variance when the mean is known to be \a m. */ variance has no meaning as each data point has its own variance. @return The variance. */ */ const AveragerWeighted& operator+=(const AveragerWeighted&); private: /// /// double sum_wwxx(void) const; double mean_; // wx/w double m2_; // wxx - m*m*w If InputIterator is non-weighted unitary weights are used. Type Requirement: - \c InputIterator models \ref concept_data_iterator - \c InputIterator is \single_pass_iterator \relates AveragerWeighted */ void add(AveragerWeighted& a, InputIterator first, InputIterator last) { BOOST_CONCEPT_ASSERT((boost::InputIterator)); BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept)); BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator)); utility::iterator_traits traits; for ( ; first != last; ++first) /** \brief add values from two ranges to AveragerWeighted \a a \brief add values from two ranges to AveragerWeighted \a a Add data from range [first1, last1) with their corresponding weight in range [first2, first2 + distance(first, last) ). Requirement: InputIterator1 and InputIterator2 are unweighted input iterators. Type Requirement: - \c InputIterator1 models \single_pass_iterator - \c InputIterator1 models \readable_iterator - \c InputIterator1 is unweighted - \c InputIterator2 models \single_pass_iterator - \c InputIterator2 models \readable_iterator - \c InputIterator2 is unweighted \relates AveragerWeighted */ template void add(AveragerWeighted& a, InputIterator1 first1, InputIterator1 last1, void add(AveragerWeighted& a, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) { BOOST_CONCEPT_ASSERT((boost::InputIterator)); BOOST_CONCEPT_ASSERT((boost::InputIterator)); BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator)); BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator)); BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator)); BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator)); utility::check_iterator_is_unweighted(first1); utility::check_iterator_is_unweighted(first2);