37 Real quantile(
const std::vector<Real>& samples,
Real prob) {
38 Size nsample = samples.size();
40 "Probability has to be in [0,1].");
41 QL_REQUIRE(nsample > 0,
"The sample size has to be positive." );
47 const Real a = 1. / 3,
b = 2*a / (nsample+a);
49 return *std::min_element(samples.begin(), samples.end());
51 return *std::max_element(samples.begin(), samples.end());
54 Size index =
static_cast<Size>(std::floor((nsample+a)*prob+a));
55 std::vector<Real> sorted(index+1);
56 std::partial_sort_copy(samples.begin(), samples.end(),
57 sorted.begin(), sorted.end());
60 Real weight = nsample*prob + a - index;
61 return (1-weight) * sorted[index-1] + weight * sorted[index];
84 #if defined(QL_EXTRA_SAFETY_CHECKS)
92 #if defined(QL_EXTRA_SAFETY_CHECKS)
110 std::ceil(std::log(
static_cast<Real>(
data_.size()))
111 /std::log(2.0) + 1));
117 Real h = 2.0 * (r2-r1) * std::pow(
static_cast<Real>(
data_.size()), -1.0/3.0);
118 bins_ =
static_cast<Size>(std::ceil((max-min)/h));
126 * std::pow(
static_cast<Real>(
data_.size()), -1.0/3.0);
127 bins_ =
static_cast<Size>(std::ceil((max-min)/h));
131 QL_FAIL(
"a bin-partition algorithm is required");
133 QL_FAIL(
"unknown bin-partition algorithm");
161 bool processed =
false;
std::vector< Real > breaks_
std::vector< Real > frequency_
std::vector< Size > counts_
Algorithm algorithm() const
Real frequency(Size i) const
Size counts(Size i) const
const std::vector< Real > & breaks() const
std::vector< Real > data_
Statistics tool based on incremental accumulation.
void addSequence(DataIterator begin, DataIterator end)
adds a sequence of data to the set, with default weight
template class providing a null value for a given type.
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
ext::function< Real(Real)> b
LinearInterpolation variance
std::size_t Size
size of a container
statistics tool for generating histogram of given data
statistics tool based on incremental accumulation in the meantime, this is just a wrapper to the boos...
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)