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

Computation of the Factors of a 1D Container. More...

#include <STK_Stat_Factor.h>

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

Public Types

typedef IRunnerWithData< Array > Base
 
typedef hidden::Traits< Array >::Row RowVector
 
typedef hidden::Traits< Array >::Col ColVector
 
typedef Array::Type Type
 
typedef std::map< Type, int > EncodingMap
 
typedef std::map< int, Type > DecodingMap
 

Public Member Functions

 Factor ()
 Default Constructor.
 
 Factor (Array const &data)
 Constructor.
 
 Factor (Array const *p_data)
 Constructor.
 
 Factor (Factor const &f)
 copy constructor.
 
virtual ~Factor ()
 virtual destructor.
 
virtual Factor * clone () const
 clone pattern
 
CVectorXi const & asInteger () const
 
Array2DVector< Type > const & levels () const
 
VectorXi const & counts () const
 
int const & firstLevel () const
 
int const & nbLevels () const
 
EncodingMap const & encoder () const
 
DecodingMap const & decoder () const
 
void setFirstLevel (int firstLevel)
 set the value of the first level
 
virtual bool run ()
 run the estimation of the Factor statistics.
 
- Public Member Functions inherited from STK::IRunnerWithData< Array >
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.
 
- Public Member Functions inherited from STK::IRunnerBase
String const & error () const
 get the last error message.
 

Public Attributes

Array const * p_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

CVectorXi asInteger_
 vector with the levels in an integer format
 
int firstLevel_
 first level
 
int nbLevels_
 Number of levels of each variables.
 
Array2DVector< Type > levels_
 vector with the levels
 
VectorXi counts_
 Array with the counts of each factor.
 
EncodingMap encoder_
 encoder of the levels
 
DecodingMap decoder_
 decoder of the levels
 
- Protected Attributes inherited from STK::IRunnerWithData< Array >
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
 

Detailed Description

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

Computation of the Factors of a 1D Container.

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

Definition at line 54 of file STK_Stat_Factor.h.

Member Typedef Documentation

◆ Base

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

Definition at line 57 of file STK_Stat_Factor.h.

◆ ColVector

template<class Array >
typedef hidden::Traits<Array>::Col STK::Stat::Factor< Array >::ColVector

Definition at line 59 of file STK_Stat_Factor.h.

◆ DecodingMap

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

Definition at line 63 of file STK_Stat_Factor.h.

◆ EncodingMap

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

Definition at line 62 of file STK_Stat_Factor.h.

◆ RowVector

template<class Array >
typedef hidden::Traits<Array>::Row STK::Stat::Factor< Array >::RowVector

Definition at line 58 of file STK_Stat_Factor.h.

◆ Type

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

Definition at line 60 of file STK_Stat_Factor.h.

Constructor & Destructor Documentation

◆ Factor() [1/4]

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

Default Constructor.

Definition at line 129 of file STK_Stat_Factor.h.

130 , levels_(), counts_(), encoder_() {}
int nbLevels_
Number of levels of each variables.
CVectorXi asInteger_
vector with the levels in an integer format
VectorXi counts_
Array with the counts of each factor.
IRunnerWithData< Array > Base
EncodingMap encoder_
encoder of the levels
Array2DVector< Type > levels_
vector with the levels
int firstLevel_
first level
const int baseIdx
base index of the containers created in STK++.

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

◆ Factor() [2/4]

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

Constructor.

Parameters
dataa reference on the data set

Definition at line 133 of file STK_Stat_Factor.h.

133 : Base(data)
134 , asInteger_(p_data_->range())
136 , nbLevels_(0)
137 , levels_()
138 , counts_()
139 , encoder_()
140 , decoder_()
141{}
DecodingMap decoder_
decoder of the levels
Array const * p_data_
A pointer on the original data set.

◆ Factor() [3/4]

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

Constructor.

Parameters
p_dataa pointer on the data set

Definition at line 147 of file STK_Stat_Factor.h.

147 : Base(p_data)
148 , asInteger_()
150 , nbLevels_(0)
151 , levels_()
152 , counts_()
153 , encoder_()
154 , decoder_()
155{
156 if (p_data_)
157 {
158 asInteger_.resize(p_data_->range());
159 nbLevels_= 0;
160 }
161}
Derived & resize(Range const &I, Range const &J)
resize the Array.
Array const * p_data() const
get the data set

References STK::Stat::Factor< Array >::asInteger_, STK::Stat::Factor< Array >::nbLevels_, STK::Stat::Factor< Array >::p_data_, and STK::ICArray< Derived >::resize().

◆ Factor() [4/4]

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

copy constructor.

Parameters
fthe Factor to copy

Definition at line 164 of file STK_Stat_Factor.h.

164 : Base(f), asInteger_(f.asInteger_)
165 , firstLevel_(f.firstLevel_), nbLevels_(f.nbLevels_)
166 , levels_(f.levels_), counts_(f.counts_)
167 , encoder_(f.encoder_)
168 , decoder_(f.decoder_)
169{}

◆ ~Factor()

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

virtual destructor.

Definition at line 82 of file STK_Stat_Factor.h.

82{}

Member Function Documentation

◆ asInteger()

template<class Array >
CVectorXi const & STK::Stat::Factor< Array >::asInteger ( ) const
inline
Returns
vector with the factors encoded as integers

Definition at line 88 of file STK_Stat_Factor.h.

88{ return asInteger_;}

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

Referenced by main().

◆ clone()

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

clone pattern

Definition at line 85 of file STK_Stat_Factor.h.

85{ return new Factor(*this);}
Factor()
Default Constructor.

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

◆ counts()

template<class Array >
VectorXi const & STK::Stat::Factor< Array >::counts ( ) const
inline
Returns
vector with the counts of each level

Definition at line 92 of file STK_Stat_Factor.h.

92{return counts_;}

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

Referenced by main().

◆ decoder()

template<class Array >
DecodingMap const & STK::Stat::Factor< Array >::decoder ( ) const
inline
Returns
decoding maps factor from int -> Type

Definition at line 100 of file STK_Stat_Factor.h.

100{ return decoder_;}

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

◆ encoder()

template<class Array >
EncodingMap const & STK::Stat::Factor< Array >::encoder ( ) const
inline
Returns
encoding maps factor from Type -> int

Definition at line 98 of file STK_Stat_Factor.h.

98{ return encoder_;}

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

◆ firstLevel()

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

Definition at line 94 of file STK_Stat_Factor.h.

94{ return firstLevel_;}

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

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

◆ levels()

template<class Array >
Array2DVector< Type > const & STK::Stat::Factor< Array >::levels ( ) const
inline
Returns
vector with the levels

Definition at line 90 of file STK_Stat_Factor.h.

90{return levels_;}

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

Referenced by main().

◆ nbLevels()

template<class Array >
int const & STK::Stat::Factor< Array >::nbLevels ( ) const
inline
Returns
number of levels

Definition at line 96 of file STK_Stat_Factor.h.

96{ return nbLevels_;}

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

Referenced by main().

◆ run()

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

run the estimation of the Factor statistics.

Implements STK::IRunnerBase.

Definition at line 188 of file STK_Stat_Factor.h.

189{
190 if (!p_data_)
191 { this->msg_error_ = STKERROR_NO_ARG(FactorArray::run,data is not set);
192 return false;
193 }
194 try
195 {
196 for (int i=p_data_->begin(); i< p_data_->end(); ++i)
197 {
198 // find coding
199 Type idData = p_data_->elt(i);
200 typename EncodingMap::const_iterator it = encoder_.find(idData);
201 if (it != encoder_.end()) // levels already exist, just update the levels array
202 { asInteger_[i] = it->second;
203 counts_[it->second]++; // add one to this level
204 }
205 else // find a new level to add
206 {
207 // create a new level and set it
208 int lev = firstLevel_ + nbLevels_;
209 asInteger_[i] = lev;
210 encoder_.insert(std::pair<Type, int>(idData, lev));
211 decoder_.insert(std::pair<int, Type>(lev, idData));
212 levels_.push_back(idData);
213 counts_.push_back(1); // start counting for this new level
214 nbLevels_++;
215 }
216 }
217 }
218 catch (Exception const& error)
219 {
220 this->msg_error_ += _T("Error in Factor::run():\nWhat: ");
221 this->msg_error_ += error.error();
222 return false;
223 }
224 // no error
225 return true;
226}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define _T(x)
Let x unmodified.
void push_back(Type const &v)
STL compatibility: append an element v.
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::Factor< Array >::setFirstLevel ( int  firstLevel)
inline

set the value of the first level

Definition at line 103 of file STK_Stat_Factor.h.

int const & firstLevel() const

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

◆ update()

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

udpating method in case we set a new data set

Reimplemented from STK::IRunnerBase.

Definition at line 172 of file STK_Stat_Factor.h.

173{
174 // if there is no data there is nothing to update
175 if (p_data_)
176 {
177 asInteger_.resize(p_data_->rows());
179 nbLevels_=0;
180 levels_.clear();
181 counts_.clear();
182 encoder_.clear();
183 decoder_.clear();
184 }
185}
void clear()
clear the object.

References STK::baseIdx.

Member Data Documentation

◆ asInteger_

template<class Array >
CVectorXi STK::Stat::Factor< Array >::asInteger_
protected

vector with the levels in an integer format

Definition at line 110 of file STK_Stat_Factor.h.

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

◆ counts_

template<class Array >
VectorXi STK::Stat::Factor< Array >::counts_
protected

Array with the counts of each factor.

Definition at line 118 of file STK_Stat_Factor.h.

Referenced by STK::Stat::Factor< Array >::counts().

◆ decoder_

template<class Array >
DecodingMap STK::Stat::Factor< Array >::decoder_
protected

decoder of the levels

Definition at line 122 of file STK_Stat_Factor.h.

Referenced by STK::Stat::Factor< Array >::decoder().

◆ encoder_

template<class Array >
EncodingMap STK::Stat::Factor< Array >::encoder_
protected

encoder of the levels

Definition at line 120 of file STK_Stat_Factor.h.

Referenced by STK::Stat::Factor< Array >::encoder().

◆ firstLevel_

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

◆ levels_

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

vector with the levels

Definition at line 116 of file STK_Stat_Factor.h.

Referenced by STK::Stat::Factor< Array >::levels().

◆ nbLevels_

template<class Array >
int STK::Stat::Factor< Array >::nbLevels_
protected

Number of levels of each variables.

Definition at line 114 of file STK_Stat_Factor.h.

Referenced by STK::Stat::Factor< Array >::Factor(), and STK::Stat::Factor< 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::Factor< Array >::Factor().


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