36#ifndef STK_STAT_UNIVARIATEREAL_H
37#define STK_STAT_UNIVARIATEREAL_H
47template <
class TContainer1D,
typename Type =
typename TContainer1D::Type >
62template <
class TContainer1D>
73 : nbSamples_(V.size())
74 , nbAvailable_(V.size())
100 compOrderStatistics();
112 : nbSamples_(V.size())
113 , nbAvailable_(V.size())
139 if ((V_.range() != W_.range()))
141 initializeVariableAndWeights();
142 compOrderStatistics();
143 compWeightedStatistics();
149 : nbSamples_(
stat.nbSamples_)
150 , nbAvailable_(
stat.nbAvailable_)
151 , nbMiss_(
stat.nbMiss_)
154 , weighted_(
stat.weighted_)
155 , sorted_(
stat.sorted_)
156 , comporder_(
stat.comporder_)
157 , compstat_(
stat.compstat_)
158 , sumweights_(
stat.sumweights_)
159 , sum2weights_(
stat.sum2weights_)
164 , median_(
stat.median_)
170 , kurtosis_(
stat.kurtosis_)
171 , skewness_(
stat.skewness_)
172 , quartiles_(
stat.quartiles_)
173 , deciles_(
stat.deciles_)
174 , viceciles_(
stat.viceciles_)
175 , percentiles_(
stat.percentiles_)
184 nbSamples_ =
stat.nbSamples_;
185 nbAvailable_ =
stat.nbAvailable_;
186 nbMiss_ =
stat.nbMiss_;
189 weighted_ =
stat.weighted_;
190 sorted_ =
stat.sorted_;
191 comporder_ =
stat.comporder_;
192 compstat_ =
stat.compstat_;
193 sumweights_ =
stat.sumweights_;
194 sum2weights_ =
stat.sum2weights_;
199 median_ =
stat.median_;
205 kurtosis_ =
stat.kurtosis_;
206 skewness_ =
stat.skewness_;
207 quartiles_ =
stat.quartiles_;
208 deciles_ =
stat.deciles_;
209 viceciles_ =
stat.viceciles_;
210 percentiles_ =
stat.percentiles_;
219 template<
class Vector>
227 nbSamples_ = V_.size();
228 nbAvailable_ = V_.size();
251 initializeVariable();
252 compOrderStatistics();
260 template<
class Vector,
class Weights>
266 if ((V.range() !=
W.range()))
272 nbSamples_ = V_.size();
273 nbAvailable_ = V_.size();
296 initializeVariableAndWeights();
297 compOrderStatistics();
298 compWeightedStatistics();
329 inline const Real mad()
const {
return( mad_);}
351 template<
class OtherArray>
357 int nt = T.size(), shift = V_.begin()-1;
360 for (
int j=T.begin(), k=1;
j<T.end();
j++, k++)
365 int tind1 = std::min(nbAvailable_,
tind+1);
370 : T[
j] = V_[shift+
tind];
384 for (
int i=V_.lastIdx();
i>=V_.begin();
i--)
395 min_ = std::min((
Real)V_[
i], min_);
396 max_ = std::max((
Real)V_[
i], max_);
401 sum2weights_= 1./(
Real)nbAvailable_;
404 if (nbAvailable_ == 0)
411 amax_ = std::max(std::abs(min_), std::abs(max_));
424 for (
int i=V_.lastIdx();
i>=V_.begin();
i--)
435 min_ = std::min(V_[
i], min_);
436 max_ = std::max(V_[
i], max_);
437 sumweights_ += (W_[
i] = std::abs((
Real)W_[
i]));
438 sum2weights_ += W_[
i] * W_[
i];
442 if (nbAvailable_ == 0)
449 amax_ = std::max(std::abs(min_), std::abs(max_));
463 if (nbAvailable_ == 0)
477 if (nbAvailable_ == 1)
498 for (
int i=V_.begin();
i<=V_.lastIdx();
i++)
499 mean_ += V_[
i]/amax_;
513 for (
int i=V_.begin();
i<V_.end();
i++)
517 mad_ += std::abs(
dev1 );
521 mad_ *= sum2weights_;
522 uvar_ = (var_ -
sum*
sum/n)/(n - 1.);
523 var_ = (var_ -
sum*
sum/n)/n;
524 std_ = sqrt((
double)var_);
525 ustd_ = sqrt((
double)uvar_);
532 skewness_ /= (var_ * std_);
533 kurtosis_ /= (var_ * var_);
549 if (nbAvailable_ == 0)
563 if ((nbAvailable_ == 1)||(sumweights_*sumweights_ <= sum2weights_))
581 for (
int i=V_.begin();
i<V_.end();
i++)
582 mean_ += (W_[
i]*V_[
i])/amax_;
583 mean_ /= sumweights_;
593 for (
int i=V_.begin();
i<V_.end();
i++)
603 uvar_ = (var_ -
sum*
sum/sumweights_)/(sumweights_ - sum2weights_/sumweights_);
604 var_ = (var_ -
sum*
sum/sumweights_)/sumweights_;
605 std_ = sqrt((
double)var_);
606 ustd_ = sqrt((
double)uvar_);
610 skewness_ /= (sumweights_ * var_ * std_);
611 kurtosis_ /= (sumweights_ * var_ * var_);
627 if (nbAvailable_ == 0)
638 if (nbAvailable_ == 1)
654 TContainer1D
const&
Vconst = V_;
663 compQuantiles(quartiles_);
664 compQuantiles(deciles_);
665 compQuantiles(viceciles_);
666 compQuantiles(percentiles_);
668 median_ = quartiles_[2];
In this file we define an implementation of the heapsort algorithm for IVector containers.
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
#define _T(x)
Let x unmodified.
Implement the interface class IVariable as Variable.
void clear()
clear the object.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
bool weighted_
Samples are weighted ?
const Real skewness() const
get the skewness of the variable
const Real unbiasedStd() const
get the sample standard deviation of the variable
int nbMiss_
Number of missing samples.
void compOrderStatistics()
Compute the Order Statistics of the variable.
Variable< Real > const & quartiles() const
get the quartiles of the variable (25%)
bool sorted_
Samples are sorted ?
Real median_
median of the variable
const Real mean() const
get the mean of the variable
void initializeVariableAndWeights()
Initialize the containers in order to discard the missing elements in the weighted case.
Real var_
Variance of the variable (division by n)
const int nbAvailableSamples() const
get the number of available samples (not missing)
Real uvar_
Unbiased Variance of the variable (division by n-1)
Real skewness_
Skewness of the variable.
Real amax_
Absolute maximal value.
Real mad_
absolute deviation of the variable
Variable< Real > const & viceciles() const
get the viceciles of the variable (5%)
Real mean_
mean of the variable
Real kurtosis_
kurtosis of the variable
const Real unbiasedVariance() const
get the unbiased Variance of the variable (division by n-1)
void compStatistics()
Compute the usual statistics of the variable:
void setData(Vector const &V, Weights const &W, bool sorted=false)
Compute the statistics of a new weighted Variable.
Variable< Real > viceciles_
viceciles (5%)
const Real variance() const
get the variance of the variable (division by n)
Real std_
Standard deviation of the variable (n)
Variable< Real > deciles_
Deciles (10%)
Real ustd_
Sample standard deviation of the variable (n-1)
Univariate(TContainer1D const &V, bool sorted=false)
Default constructor Copy locally the variable V and set dimensions.
const Real aMax() const
get the absolute maximal value
const int nbMissingSamples() const
get the number of missing samples
const Real median() const
get the median of the variable
Variable< Real > const & deciles() const
get the deciles of the varibales (10%)
Real sumweights_
Sum of the weights.
const Real min() const
get the min of the variable
void compQuantiles(OtherArray &T)
Compute the quantiles of the sorted variable V_ and store the result in the array T.
TContainer1D W_
local copy of the weights
void setData(Vector const &V, bool sorted=false)
Compute the statistics of a new Variable.
Real max_
Max of the variable.
Variable< Real > const & percentiles() const
get the percentiles of the variable (1%)
bool comporder_
Orders Statistics are computed ?
const int nbSamples() const
get the number of samples
const Real mad() const
get the median absolute deviation of the variable
Univariate(const Univariate &stat)
Copy constructor.
const Real kurtosis() const
get the kurtosis of the variable
Real sum2weights_
Sum of the square of the weights.
int nbAvailable_
Number of Available samples.
Univariate & operator=(const Univariate &stat)
Operator = : overwrite the Univariate with stat.
Variable< Real > quartiles_
Quartiles (25%)
bool compstat_
Usuals Statistics are computed ?
const Real std() const
get the standard deviation of the variable
Variable< Real > percentiles_
percentiles (1%)
void initializeVariable()
Initialize the container in order to discard the missing elements in the non weighted case.
Univariate(TContainer1D const &V, TContainer1D const &W, bool sorted=false)
Default constructor for weighted variables.
void compWeightedStatistics()
Compute the usual weighted statistics of the variable.
int nbSamples_
Number of samples.
TContainer1D V_
local copy of the variable
Real min_
Min of the variable.
const Real max() const
get the max of the variable
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
void heapSort(Vector &T)
Sort the container T in ascending order.
void applySort1D(Vector &T, VectorInt const &I)
Apply a sorting index array to the 1D container T.
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
hidden::FunctorTraits< Derived, SumOp >::Row sum(Derived const &A)
Compute the sum of A.
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.
static Type NA()
Adding a Non Available (NA) special number.