25#ifndef quantlib_general_statistics_hpp
26#define quantlib_general_statistics_hpp
56 const std::vector<std::pair<Real,Real> >&
data()
const;
115 template <
class Func,
class Predicate>
117 const Predicate& inRange)
const {
118 Real num = 0.0, den = 0.0;
120 std::vector<std::pair<Real,Real> >::const_iterator i;
122 Real x = i->first, w = i->second;
130 return std::make_pair<Real,Size>(
Null<Real>(),0);
132 return std::make_pair(num/den,N);
139 template <
class Func>
168 template <
class DataIterator>
170 for (;begin!=end;++begin)
174 template <
class DataIterator,
class WeightIterator>
176 WeightIterator wbegin) {
177 for (;begin!=end;++begin,++wbegin)
178 add(*begin, *wbegin);
191 mutable std::vector<std::pair<Real,Real> >
samples_;
206 inline const std::vector<std::pair<Real,Real> >&
221 return std::min_element(
samples_.begin(),
227 return std::max_element(
samples_.begin(),
233 QL_REQUIRE(weight>=0.0,
"negative weight not allowed");
234 samples_.emplace_back(value, weight);
239 samples_ = std::vector<std::pair<Real,Real> >();
Size samples() const
number of samples collected
void reserve(Size n) const
informs the internal storage of a planned increase in size
Real weightSum() const
sum of data weights
void add(Real value, Real weight=1.0)
adds a datum to the set, possibly with a weight
std::vector< std::pair< Real, Real > > samples_
Real percentile(Real y) const
void addSequence(DataIterator begin, DataIterator end)
adds a sequence of data to the set, with default weight
const std::vector< std::pair< Real, Real > > & data() const
collected data
std::pair< Real, Size > expectationValue(const Func &f, const Predicate &inRange) const
Real errorEstimate() const
Real standardDeviation() const
void sort() const
sort the data set in increasing order
Real topPercentile(Real y) const
std::pair< Real, Size > expectationValue(const Func &f) const
void addSequence(DataIterator begin, DataIterator end, WeightIterator wbegin)
adds a sequence of data to the set, each with its weight
void reset()
resets the data to a null set
template class providing a null value for a given type.
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container