STK++ 0.9.13
STK::Stat::MultiFactor< Array > Class Template Reference

Computation of the MultiFactors of a 2D Container. More...

#include <STK_Stat_MultiFactor.h>

Inheritance diagram for STK::Stat::MultiFactor< Array >:
Inheritance graph

Public Types

typedef IRunnerWithData< Array > Base
 
typedef Array::Type Type
 
typedef std::map< Type, intEncodingMap
 
typedef std::map< int, TypeDecodingMap
 
typedef CArrayPoint< EncodingMapEncoder
 
typedef CArrayPoint< DecodingMapDecoder
 

Public Member Functions

 MultiFactor ()
 Default Constructor.
 
 MultiFactor (Array const &data)
 Constructor.
 
 MultiFactor (Array const *p_data)
 Constructor.
 
 MultiFactor (MultiFactor const &f)
 copy constructor.
 
virtual ~MultiFactor ()
 virtual destructor.
 
virtual MultiFactorclone () const
 clone pattern
 
CArrayXXi constasInteger () const
 
CArrayPoint< Array2DVector< Type > > constlevels () const
 
CArrayPoint< VectorXi > constcounts () const
 
int constfirstLevel () const
 
CPointXi constnbLevels () const
 
Encoder constencoder () const
 
Decoder constdecoder () const
 
void setFirstLevel (int firstLevel)
 set the value of the first level
 
virtual bool run ()
 run the estimation of the MultiFactor statistics.
 
- Public Member Functions inherited from STK::IRunnerWithData< Array >
Array constp_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.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Public Attributes

Array constp_data_
 A pointer on the original data set.
 

Protected Member Functions

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

Protected Attributes

CArrayXXi asInteger_
 Array of the data size with the levels of each variables in an integer format.
 
int firstLevel_
 first level number
 
CPointXi nbLevels_
 Number of levels of each variables.
 
CArrayPoint< Array2DVector< Type > > levels_
 Array with the levels of each variables.
 
CArrayPoint< VectorXicounts_
 Array with the counts of each factor.
 
Encoder encoder_
 encoder of the levels
 
Decoder decoder_
 decoder of the levels
 
- Protected Attributes inherited from STK::IRunnerWithData< Array >
Array constp_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
 

Detailed Description

template<class Array>
class STK::Stat::MultiFactor< Array >

Computation of the MultiFactors of a 2D Container.

The class MultiFactor is a factory class for computing the factors of an array. The values can be of any type. the Coding is performed from the previous type in integer. The mapping is stored and preserved in an array of map array.

Definition at line 57 of file STK_Stat_MultiFactor.h.

Member Typedef Documentation

◆ Base

template<class Array >
typedef IRunnerWithData<Array> STK::Stat::MultiFactor< Array >::Base

Definition at line 60 of file STK_Stat_MultiFactor.h.

◆ Decoder

template<class Array >
typedef CArrayPoint<DecodingMap> STK::Stat::MultiFactor< Array >::Decoder

Definition at line 67 of file STK_Stat_MultiFactor.h.

◆ DecodingMap

template<class Array >
typedef std::map<int, Type> STK::Stat::MultiFactor< Array >::DecodingMap

Definition at line 64 of file STK_Stat_MultiFactor.h.

◆ Encoder

template<class Array >
typedef CArrayPoint<EncodingMap> STK::Stat::MultiFactor< Array >::Encoder

Definition at line 66 of file STK_Stat_MultiFactor.h.

◆ EncodingMap

template<class Array >
typedef std::map<Type, int> STK::Stat::MultiFactor< Array >::EncodingMap

Definition at line 63 of file STK_Stat_MultiFactor.h.

◆ Type

template<class Array >
typedef Array::Type STK::Stat::MultiFactor< Array >::Type

Definition at line 61 of file STK_Stat_MultiFactor.h.

Constructor & Destructor Documentation

◆ MultiFactor() [1/4]

template<class Array >
STK::Stat::MultiFactor< Array >::MultiFactor ( )

Default Constructor.

Definition at line 133 of file STK_Stat_MultiFactor.h.

134 , nbLevels_(), levels_(), counts_(), encoder_() {}
CArrayPoint< VectorXi > counts_
Array with the counts of each factor.
CArrayPoint< Array2DVector< Type > > levels_
Array with the levels of each variables.
IRunnerWithData< Array > Base
Encoder encoder_
encoder of the levels
int firstLevel_
first level number
CPointXi nbLevels_
Number of levels of each variables.
CArrayXXi asInteger_
Array of the data size with the levels of each variables in an integer format.
const int baseIdx
base index of the containers created in STK++.

Referenced by STK::Stat::MultiFactor< Array >::clone().

◆ MultiFactor() [2/4]

template<class Array >
STK::Stat::MultiFactor< Array >::MultiFactor ( Array const data)

Constructor.

Parameters
dataa reference on the data set

Definition at line 137 of file STK_Stat_MultiFactor.h.

137 : Base(data)
138 , asInteger_(p_data_->rows(),p_data_->cols())
140 , nbLevels_(p_data_->cols(), 0)
141 , levels_(p_data_->cols())
142 , counts_(p_data_->cols())
143 , encoder_(p_data_->cols())
144 , decoder_(p_data_->cols())
145{}
Decoder decoder_
decoder of the levels
Array const * p_data_
A pointer on the original data set.

◆ MultiFactor() [3/4]

template<class Array >
STK::Stat::MultiFactor< Array >::MultiFactor ( Array const p_data)

Constructor.

Parameters
p_dataa pointer on the data set

Definition at line 151 of file STK_Stat_MultiFactor.h.

151 : Base(p_data)
152 , asInteger_()
154 , nbLevels_()
155 , levels_()
156 , encoder_()
157 , decoder_()
158{
159 if (p_data_)
160 {
161 asInteger_.resize(p_data_->rows(),p_data_->cols());
162 nbLevels_.resize(p_data_->cols()).setValue(0);
163 levels_.resize(p_data_->cols());
164 counts_.resize(p_data_->cols());
165 encoder_.resize(p_data_->cols());
166 decoder_.resize(p_data_->cols());
167 }
168}
Derived & resize(Range const &I, Range const &J)
resize the Array.
Array const * p_data() const
get the data set

References STK::Stat::MultiFactor< Array >::asInteger_, STK::Stat::MultiFactor< Array >::counts_, STK::Stat::MultiFactor< Array >::decoder_, STK::Stat::MultiFactor< Array >::encoder_, STK::Stat::MultiFactor< Array >::levels_, STK::Stat::MultiFactor< Array >::nbLevels_, STK::Stat::MultiFactor< Array >::p_data_, and STK::ICArray< Derived >::resize().

◆ MultiFactor() [4/4]

template<class Array >
STK::Stat::MultiFactor< Array >::MultiFactor ( MultiFactor< Array > const f)

copy constructor.

Parameters
fthe MultiFactor to copy

Definition at line 171 of file STK_Stat_MultiFactor.h.

171 : Base(f), asInteger_(f.asInteger_)
172 , firstLevel_(baseIdx), nbLevels_(f.nbLevels_)
173 , levels_(f.levels_), counts_(f.counts_)
174 , encoder_(f.encoder_)
175 , decoder_(f.decoder_)
176{}

◆ ~MultiFactor()

template<class Array >
virtual STK::Stat::MultiFactor< Array >::~MultiFactor ( )
inlinevirtual

virtual destructor.

Definition at line 86 of file STK_Stat_MultiFactor.h.

86{}

Member Function Documentation

◆ asInteger()

template<class Array >
CArrayXXi const & STK::Stat::MultiFactor< Array >::asInteger ( ) const
inline
Returns
array with the factors encoded as integers

Definition at line 92 of file STK_Stat_MultiFactor.h.

92{ return asInteger_;}

References STK::Stat::MultiFactor< Array >::asInteger_.

Referenced by main().

◆ clone()

template<class Array >
virtual MultiFactor * STK::Stat::MultiFactor< Array >::clone ( ) const
inlinevirtual

clone pattern

Definition at line 89 of file STK_Stat_MultiFactor.h.

89{ return new MultiFactor(*this);}
MultiFactor()
Default Constructor.

References STK::Stat::MultiFactor< Array >::MultiFactor().

◆ counts()

template<class Array >
CArrayPoint< VectorXi > const & STK::Stat::MultiFactor< Array >::counts ( ) const
inline
Returns
array with for each variables the counts of the levels

Definition at line 96 of file STK_Stat_MultiFactor.h.

96{return counts_;}

References STK::Stat::MultiFactor< Array >::counts_.

Referenced by main().

◆ decoder()

template<class Array >
Decoder const & STK::Stat::MultiFactor< Array >::decoder ( ) const
inline
Returns
array with the encoding maps factor to int

Definition at line 104 of file STK_Stat_MultiFactor.h.

104{ return decoder_;}

References STK::Stat::MultiFactor< Array >::decoder_.

◆ encoder()

template<class Array >
Encoder const & STK::Stat::MultiFactor< Array >::encoder ( ) const
inline
Returns
array with the encoding maps factor to int

Definition at line 102 of file STK_Stat_MultiFactor.h.

102{ return encoder_;}

References STK::Stat::MultiFactor< Array >::encoder_.

◆ firstLevel()

template<class Array >
int const & STK::Stat::MultiFactor< Array >::firstLevel ( ) const
inline
Returns
the value of the first level

Definition at line 98 of file STK_Stat_MultiFactor.h.

98{ return firstLevel_;}

References STK::Stat::MultiFactor< Array >::firstLevel_.

Referenced by STK::Stat::MultiFactor< Array >::setFirstLevel().

◆ levels()

template<class Array >
CArrayPoint< Array2DVector< Type > > const & STK::Stat::MultiFactor< Array >::levels ( ) const
inline
Returns
array with for each variables the levels

Definition at line 94 of file STK_Stat_MultiFactor.h.

94{return levels_;}

References STK::Stat::MultiFactor< Array >::levels_.

Referenced by main().

◆ nbLevels()

template<class Array >
CPointXi const & STK::Stat::MultiFactor< Array >::nbLevels ( ) const
inline
Returns
array with for each variables the number of levels

Definition at line 100 of file STK_Stat_MultiFactor.h.

100{ return nbLevels_;}

References STK::Stat::MultiFactor< Array >::nbLevels_.

Referenced by main().

◆ run()

template<class Array >
bool STK::Stat::MultiFactor< Array >::run ( )
virtual

run the estimation of the MultiFactor statistics.

Implements STK::IRunnerBase.

Definition at line 202 of file STK_Stat_MultiFactor.h.

203{
204 if (!p_data_)
205 { this->msg_error_ = STKERROR_NO_ARG(MultiFactorArray::run,data is not set);
206 return false;
207 }
208 try
209 {
210 for (int j=p_data_->beginCols(); j< p_data_->endCols(); ++j)
211 {
212 for (int i=p_data_->beginRows(); i< p_data_->endRows(); ++i)
213 {
214 // find coding
215 Type idData = p_data_->elt(i,j);
216 typename EncodingMap::const_iterator it = encoder_[j].find(idData);
217 if (it != encoder_[j].end())
218 { // levels already exist, just update the integer and counts array
219 asInteger_(i,j) = it->second;
220 counts_[j][it->second]++;
221 }
222 else
223 { // find a new level to add
224 // create a new level and set it
225 int lev = firstLevel_ + nbLevels_[j];
226 asInteger_(i,j) = lev;
227 encoder_[j].insert(std::pair<Type, int>(idData, lev));
228 decoder_[j].insert(std::pair<int, Type>(lev, idData));
229 levels_[j].push_back(idData);
230 counts_[j].push_back(1); // start counting for this new level
231 ++nbLevels_[j];
232 }
233 }
234 }
235 }
236 catch (Exception const& error)
237 {
238 this->msg_error_ += _T("Error in MultiFactor::run():\nWhat: ");
239 this->msg_error_ += error.error();
240 return false;
241 }
242 // no error
243 return true;
244}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define _T(x)
Let x unmodified.
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

References _T, STK::Exception::error(), and STKERROR_NO_ARG.

Referenced by main().

◆ setFirstLevel()

template<class Array >
void STK::Stat::MultiFactor< Array >::setFirstLevel ( int  firstLevel)
inline

set the value of the first level

Definition at line 107 of file STK_Stat_MultiFactor.h.

int const & firstLevel() const

References STK::Stat::MultiFactor< Array >::firstLevel(), and STK::Stat::MultiFactor< Array >::firstLevel_.

◆ update()

template<class Array >
void STK::Stat::MultiFactor< Array >::update ( )
protectedvirtual

udpating method in case we set a new data set

Reimplemented from STK::IRunnerBase.

Definition at line 179 of file STK_Stat_MultiFactor.h.

180{
181 // if there is no data there is nothing to update
182 if (p_data_)
183 {
184 asInteger_.resize(p_data_->rows(),p_data_->cols());
186 nbLevels_.resize(p_data_->cols()).setValue(0);
187 for(int j=encoder_.begin(); j<std::min(encoder_.end(), p_data_->cols().end()); ++j)
188 {
189 levels_[j].clear();
190 counts_[j].clear();
191 encoder_[j].clear();
192 decoder_[j].clear();
193 }
194 levels_.resize(p_data_->cols());
195 counts_.resize(p_data_->cols());
196 encoder_.resize(p_data_->cols());
197 decoder_.resize(p_data_->cols());
198 }
199}
void clear()
clear all allocated memory .

References STK::baseIdx.

Member Data Documentation

◆ asInteger_

template<class Array >
CArrayXXi STK::Stat::MultiFactor< Array >::asInteger_
protected

Array of the data size with the levels of each variables in an integer format.

Definition at line 114 of file STK_Stat_MultiFactor.h.

Referenced by STK::Stat::MultiFactor< Array >::asInteger(), and STK::Stat::MultiFactor< Array >::MultiFactor().

◆ counts_

template<class Array >
CArrayPoint< VectorXi > STK::Stat::MultiFactor< Array >::counts_
protected

Array with the counts of each factor.

Definition at line 122 of file STK_Stat_MultiFactor.h.

Referenced by STK::Stat::MultiFactor< Array >::counts(), and STK::Stat::MultiFactor< Array >::MultiFactor().

◆ decoder_

template<class Array >
Decoder STK::Stat::MultiFactor< Array >::decoder_
protected

◆ encoder_

template<class Array >
Encoder STK::Stat::MultiFactor< Array >::encoder_
protected

◆ firstLevel_

template<class Array >
int STK::Stat::MultiFactor< Array >::firstLevel_
protected

◆ levels_

template<class Array >
CArrayPoint< Array2DVector<Type> > STK::Stat::MultiFactor< Array >::levels_
protected

Array with the levels of each variables.

Definition at line 120 of file STK_Stat_MultiFactor.h.

Referenced by STK::Stat::MultiFactor< Array >::levels(), and STK::Stat::MultiFactor< Array >::MultiFactor().

◆ nbLevels_

template<class Array >
CPointXi STK::Stat::MultiFactor< Array >::nbLevels_
protected

Number of levels of each variables.

Definition at line 118 of file STK_Stat_MultiFactor.h.

Referenced by STK::Stat::MultiFactor< Array >::MultiFactor(), and STK::Stat::MultiFactor< Array >::nbLevels().

◆ p_data_

template<class Array >
Array const* STK::IRunnerWithData< Array >::p_data_

A pointer on the original data set.

Definition at line 172 of file STK_IRunner.h.

Referenced by STK::Stat::MultiFactor< Array >::MultiFactor().


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