STK++ 0.9.13
STK::Stat::Multivariate< Array, Real > Class Template Reference

Computation of the Multivariate Statistics of a 2D Container of Real. More...

#include <STK_Stat_MultivariateReal.h>

Inheritance diagram for STK::Stat::Multivariate< Array, Real >:
Inheritance graph

Public Member Functions

 Multivariate ()
 Default Constructor.
 
 Multivariate (Array const &data)
 Constructor.
 
 Multivariate (Array const *p_data)
 Constructor.
 
 Multivariate (Multivariate const &stat)
 copy constructor.
 
virtual ~Multivariate ()
 virtual destructor.
 
virtual Multivariate * clone () const
 clone pattern
 
int nbVariable () const
 
int nbSamples () const
 
PointX const & min () const
 
PointX const & max () const
 
PointX const & mean () const
 
PointX const & variance () const
 
ArraySquareX const & covariance () const
 
virtual bool run ()
 run the estimation of the Multivariate statistics.
 
virtual bool run (ColVector const &weights)
 run the estimation of the weighted multivariate statistics.
 
- Public Member Functions inherited from STK::IRunnerUnsupervised< Array, hidden::Traits< Array >::Col >
Array const * p_data () const
 get the data set
 
virtual void setData (Array const *p_data)
 Set the data set.
 
virtual void setData (Array const &data)
 Set the data set.
 
virtual bool run (hidden::Traits< Array >::Col const &weights)=0
 run the weighted computations.
 
- Public Member Functions inherited from STK::IRunnerBase
String const & error () const
 get the last error message.
 

Protected Member Functions

virtual void update ()
 udpating method in case we set a new data set
 
- Protected Member Functions inherited from STK::IRunnerUnsupervised< Array, hidden::Traits< Array >::Col >
 IRunnerUnsupervised ()
 default constructor.
 
 IRunnerUnsupervised (Array const *const p_data)
 constructor with a pointer on the constant data set
 
 IRunnerUnsupervised (Array const &data)
 constructor with a constant reference on the data set
 
 IRunnerUnsupervised (IRunnerUnsupervised const &runner)
 copy constructor
 
 ~IRunnerUnsupervised ()
 destructor
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 

Protected Attributes

int nbSamples_
 number of samples
 
int nbVar_
 Number of variables.
 
PointX min_
 Vector of the mean of the Variables.
 
PointX max_
 Vector of the mean of the Variables.
 
PointX mean_
 Vector of the mean of the Variables.
 
PointX var_
 Vector of the variance of the variables.
 
ArraySquareX cov_
 Array of the covariance of the variables.
 
- Protected Attributes inherited from STK::IRunnerUnsupervised< Array, hidden::Traits< Array >::Col >
Array const * p_data_
 A pointer on the original data set.
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Private Types

enum  { value_ = hidden::isSame<Type_, Real>::value_ }
 
typedef hidden::Traits< Array >::Row RowVector
 
typedef hidden::Traits< Array >::Col ColVector
 
typedef IRunnerUnsupervised< Array, ColVector > Runner
 type of runner
 
typedef Array::Type Type_
 

Detailed Description

template<class Array>
class STK::Stat::Multivariate< Array, Real >

Computation of the Multivariate Statistics of a 2D Container of Real.

The class Multivariate is just a factory class for computing the mean, the variance and the covariance square matrix of a p_data set stored in a Array with n rows (the samples) and p columns (the variables).

Definition at line 59 of file STK_Stat_MultivariateReal.h.

Member Typedef Documentation

◆ ColVector

template<class Array >
typedef hidden::Traits<Array>::Col STK::Stat::Multivariate< Array, Real >::ColVector
private

Definition at line 62 of file STK_Stat_MultivariateReal.h.

◆ RowVector

template<class Array >
typedef hidden::Traits<Array>::Row STK::Stat::Multivariate< Array, Real >::RowVector
private

Definition at line 61 of file STK_Stat_MultivariateReal.h.

◆ Runner

template<class Array >
typedef IRunnerUnsupervised< Array, ColVector> STK::Stat::Multivariate< Array, Real >::Runner
private

type of runner

Definition at line 64 of file STK_Stat_MultivariateReal.h.

◆ Type_

template<class Array >
typedef Array::Type STK::Stat::Multivariate< Array, Real >::Type_
private

Definition at line 65 of file STK_Stat_MultivariateReal.h.

Member Enumeration Documentation

◆ anonymous enum

Constructor & Destructor Documentation

◆ Multivariate() [1/4]

template<class Array >
STK::Stat::Multivariate< Array, Real >::Multivariate ( )
inline

Default Constructor.

Definition at line 73 of file STK_Stat_MultivariateReal.h.

73 : Runner()
74 , nbSamples_(0), nbVar_(0)
75 , min_(), max_(), mean_(), var_(), cov_()
76 { STK_STATIC_ASSERT(value_, YOU_CANNOT_USED_THIS_TYPE_OF_DATA_WITH_THIS_OBJECT);}
#define STK_STATIC_ASSERT(COND, MSG)
IRunnerUnsupervised< Array, ColVector > Runner
type of runner
PointX mean_
Vector of the mean of the Variables.
ArraySquareX cov_
Array of the covariance of the variables.
PointX min_
Vector of the mean of the Variables.
PointX var_
Vector of the variance of the variables.
PointX max_
Vector of the mean of the Variables.

References STK_STATIC_ASSERT.

◆ Multivariate() [2/4]

template<class Array >
STK::Stat::Multivariate< Array, Real >::Multivariate ( Array const &  data)
inline

Constructor.

Parameters
dataa reference on the data set

Definition at line 80 of file STK_Stat_MultivariateReal.h.

81 : Runner(&data)
82 , nbSamples_(data.sizeRows()), nbVar_(data.sizeCols())
83 , min_(), max_(), mean_(), var_(), cov_()
84 { STK_STATIC_ASSERT(value_, YOU_CANNOT_USED_THIS_TYPE_OF_DATA_WITH_THIS_OBJECT);}

References STK_STATIC_ASSERT.

◆ Multivariate() [3/4]

template<class Array >
STK::Stat::Multivariate< Array, Real >::Multivariate ( Array const *  p_data)
inline

Constructor.

Parameters
p_dataa pointer on the data set

Definition at line 88 of file STK_Stat_MultivariateReal.h.

89 : Runner(p_data)
90 , nbSamples_((p_data) ? p_data->sizeRows() : 0)
91 , nbVar_((p_data) ? p_data->sizeCols() : 0)
92 , min_(), max_(), mean_(), var_(), cov_()
93 { STK_STATIC_ASSERT(value_, YOU_CANNOT_USED_THIS_TYPE_OF_DATA_WITH_THIS_OBJECT);}

References STK_STATIC_ASSERT.

◆ Multivariate() [4/4]

template<class Array >
STK::Stat::Multivariate< Array, Real >::Multivariate ( Multivariate< Array, Real > const &  stat)
inline

copy constructor.

Parameters
statthe statistics to copy

Definition at line 97 of file STK_Stat_MultivariateReal.h.

98 : Runner(stat)
99 , nbSamples_(stat.nbSamples_), nbVar_(stat.nbVar_)
100 , min_(stat.min_), max_(stat.max_), mean_(stat.mean_)
101 , var_(stat.var_), cov_(stat.cov_)
102 {}

◆ ~Multivariate()

template<class Array >
virtual STK::Stat::Multivariate< Array, Real >::~Multivariate ( )
inlinevirtual

virtual destructor.

Definition at line 104 of file STK_Stat_MultivariateReal.h.

104{ }

Member Function Documentation

◆ clone()

template<class Array >
virtual Multivariate * STK::Stat::Multivariate< Array, Real >::clone ( ) const
inlinevirtual

clone pattern

Definition at line 106 of file STK_Stat_MultivariateReal.h.

106{ return new Multivariate(*this);}

◆ covariance()

template<class Array >
ArraySquareX const & STK::Stat::Multivariate< Array, Real >::covariance ( ) const
inline
Returns
the covariance of the variables in a square matrix

Definition at line 120 of file STK_Stat_MultivariateReal.h.

120{ return cov_;}

◆ max()

template<class Array >
PointX const & STK::Stat::Multivariate< Array, Real >::max ( ) const
inline
Returns
the maximal values of the variables in a RowVector

Definition at line 114 of file STK_Stat_MultivariateReal.h.

114{ return max_;}

◆ mean()

template<class Array >
PointX const & STK::Stat::Multivariate< Array, Real >::mean ( ) const
inline
Returns
the mean of the variables in a RowVector

Definition at line 116 of file STK_Stat_MultivariateReal.h.

116{ return mean_;}

◆ min()

template<class Array >
PointX const & STK::Stat::Multivariate< Array, Real >::min ( ) const
inline
Returns
the minimal values of the variables in a RowVector

Definition at line 112 of file STK_Stat_MultivariateReal.h.

112{ return min_;}

◆ nbSamples()

template<class Array >
int STK::Stat::Multivariate< Array, Real >::nbSamples ( ) const
inline
Returns
the number of samples in the p_data_ set (the number of rows)

Definition at line 110 of file STK_Stat_MultivariateReal.h.

110{return nbSamples_;}

References STK::Stat::Multivariate< Array, WColVector, Type >::nbSamples_.

◆ nbVariable()

template<class Array >
int STK::Stat::Multivariate< Array, Real >::nbVariable ( ) const
inline
Returns
the number of variables in the p_data_ set (the number of columns)

Definition at line 108 of file STK_Stat_MultivariateReal.h.

108{return nbVar_;}

References STK::Stat::Multivariate< Array, WColVector, Type >::nbVar_.

◆ run() [1/2]

template<class Array >
virtual bool STK::Stat::Multivariate< Array, Real >::run ( )
inlinevirtual

run the estimation of the Multivariate statistics.

Implements STK::IRunnerUnsupervised< Array, hidden::Traits< Array >::Col >.

Definition at line 123 of file STK_Stat_MultivariateReal.h.

124 {
125 if (!this->p_data_)
126 { this->msg_error_ = STKERROR_NO_ARG(MultivariateArray::run(),data is not set);
127 return false;
128 }
129 try
130 {
131 mean_.move(Stat::mean(*this->p_data_));
132 min_.move(Stat::min(*this->p_data_));
133 max_.move(Stat::max(*this->p_data_));
135
136 cov_.resize(this->p_data_->cols());
137 for (int j=this->p_data_->beginCols(); j<this->p_data_->endCols(); j++)
138 {
139 cov_(j, j) = var_[j];
140 for (int i=this->p_data_->beginCols(); i<j; i++)
141 {
142 cov_(i, j) = covarianceWithFixedMean(this->p_data_->col(i), this->p_data_->col(j), mean_[i], mean_[j], false);
143 cov_(j, i) = cov_(i, j);
144 }
145 }
146 }
147 catch (Exception const& error)
148 {
149 this->msg_error_ += _T("Error in Multivariate::run():\nWhat: ");
150 this->msg_error_ += error.error();
151 return false;
152 }
153 // no error
154 return true;
155 }
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define _T(x)
Let x unmodified.
Derived & resize(Range const &I, Range const &J)
resize the array.
Derived & move(Derived const &T)
move T to this.
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
Array const * p_data_
A pointer on the original data set.
hidden::FunctorTraits< Derived, VarianceWithFixedMeanOp >::Row varianceWithFixedMean(Derived const &A, MeanType const &mean, bool unbiased)
Compute the VarianceWithFixedMean(s) value(s) of A.
hidden::FunctorTraits< Derived, MaxOp >::Row max(Derived const &A)
Compute the maximal(s) value(s) of A.
hidden::FunctorTraits< Derived, MeanOp >::Row mean(Derived const &A)
Compute the mean(s) value(s) of A.
Real covarianceWithFixedMean(ExprBase< XArray > const &X, ExprBase< YArray > const &Y, typename hidden::Traits< XArray >::Type const &xMu, typename hidden::Traits< YArray >::Type const &yMu, bool unbiased=false)
Compute the covariance of the variables X and Y with fixed means.
hidden::FunctorTraits< Derived, MinOp >::Row min(Derived const &A)
Compute the minimal(s) value(s) of A.

References _T, STK::Stat::covarianceWithFixedMean(), STK::Exception::error(), STK::IRunnerBase::error(), STK::Stat::max(), STK::Stat::mean(), STK::Stat::min(), STK::IRunnerBase::msg_error_, STK::IRunnerUnsupervised< Array, WColVector >::p_data_, STKERROR_NO_ARG, and STK::Stat::varianceWithFixedMean().

◆ run() [2/2]

template<class Array >
virtual bool STK::Stat::Multivariate< Array, Real >::run ( ColVector const &  weights)
inlinevirtual

run the estimation of the weighted multivariate statistics.

Parameters
weightsthe weights of the samples

Definition at line 159 of file STK_Stat_MultivariateReal.h.

160 {
161 if (!this->p_data_)
162 { this->msg_error_ = STKERROR_NO_ARG(MultivariateArray::run(weights),data is not set);
163 return false;
164 }
165 if (this->p_data_->rows() != weights.range())
166 { this->msg_error_ = STKERROR_NO_ARG(MultivariateArray::run(weights),p_data_->rows() != weights.range());
167 return false;
168 }
169 try
170 {
171 mean_.move(Stat::mean(*this->p_data_, weights));
172 min_.move(Stat::min(*this->p_data_,weights));
173 max_.move(Stat::max(*this->p_data_, weights));
174 var_.move(varianceWithFixedMean(*this->p_data_, weights, mean_, false));
175
176 cov_.resize(this->p_data_->cols());
177 // for each variables
178 for (int j= this->p_data_->beginCols(); j< this->p_data_->endCols(); j++)
179 {
180 cov_(j, j) = var_[j];
181 // compute the covariances
182 for (int i= this->p_data_->beginCols(); i<j; i++)
183 {
184 cov_(i, j) = covarianceWithFixedMean(this->p_data_->col(i), this->p_data_->col(j), weights, mean_[i], mean_[j]);
185 cov_(j, i) = cov_(i, j);
186 }
187 }
188 }
189 catch (Exception const& error)
190 {
191 this->msg_error_ = _T("Error in Multivariate::run(weights): ");
192 this->msg_error_ += error.error();
193 return false;
194 }
195 // no error
196 return true;
197 }

References _T, STK::Stat::covarianceWithFixedMean(), STK::Exception::error(), STK::IRunnerBase::error(), STK::Stat::max(), STK::Stat::mean(), STK::Stat::min(), STK::IRunnerBase::msg_error_, STK::IRunnerUnsupervised< Array, WColVector >::p_data_, STKERROR_NO_ARG, and STK::Stat::varianceWithFixedMean().

◆ update()

template<class Array >
virtual void STK::Stat::Multivariate< Array, Real >::update ( )
inlineprotectedvirtual

udpating method in case we set a new data set

Reimplemented from STK::IRunnerBase.

Definition at line 217 of file STK_Stat_MultivariateReal.h.

218 {
219 // if there is no data there is nothing to update
220 if (this->p_data_)
221 {
222 nbSamples_ = this->p_data_->sizeRows();
223 nbVar_ = this->p_data_->sizeCols();
224 }
225 }

References STK::IRunnerUnsupervised< Array, WColVector >::p_data_.

◆ variance()

template<class Array >
PointX const & STK::Stat::Multivariate< Array, Real >::variance ( ) const
inline
Returns
the variance of the variables in a RowVector

Definition at line 118 of file STK_Stat_MultivariateReal.h.

118{ return var_;}

Member Data Documentation

◆ cov_

template<class Array >
ArraySquareX STK::Stat::Multivariate< Array, Real >::cov_
protected

Array of the covariance of the variables.

Definition at line 214 of file STK_Stat_MultivariateReal.h.

◆ max_

template<class Array >
PointX STK::Stat::Multivariate< Array, Real >::max_
protected

Vector of the mean of the Variables.

Definition at line 208 of file STK_Stat_MultivariateReal.h.

◆ mean_

template<class Array >
PointX STK::Stat::Multivariate< Array, Real >::mean_
protected

Vector of the mean of the Variables.

Definition at line 210 of file STK_Stat_MultivariateReal.h.

◆ min_

template<class Array >
PointX STK::Stat::Multivariate< Array, Real >::min_
protected

Vector of the mean of the Variables.

Definition at line 206 of file STK_Stat_MultivariateReal.h.

◆ nbSamples_

template<class Array >
int STK::Stat::Multivariate< Array, Real >::nbSamples_
protected

number of samples

Definition at line 201 of file STK_Stat_MultivariateReal.h.

◆ nbVar_

template<class Array >
int STK::Stat::Multivariate< Array, Real >::nbVar_
protected

Number of variables.

Definition at line 203 of file STK_Stat_MultivariateReal.h.

◆ var_

template<class Array >
PointX STK::Stat::Multivariate< Array, Real >::var_
protected

Vector of the variance of the variables.

Definition at line 212 of file STK_Stat_MultivariateReal.h.


The documentation for this class was generated from the following file: