36#ifndef STK_CATEGORICALBASE_H
37#define STK_CATEGORICALBASE_H
39#include "../STK_IMixtureDensity.h"
40#include "../CategoricalModels/STK_CategoricalParameters.h"
49template<
class Derived>
97#ifdef STK_MIXTURE_VERBOSE
98 stk_cout <<
_T(
"In CatagoricalBase::initializeModelImpl. modalities_ = ")
110 template<
class Weights>
115 inline int rand(
int i,
int j,
int k)
const
121 template<
class Array>
139template<
class Derived>
143 for (
int j=p_data()->beginCols();
j<p_data()->endCols(); ++
j)
146 Real prob= proba(k,
j, p_data()->elt(
i,
j));
147 if (prob) {
sum += std::log(prob);}
153template<
class Derived>
154template<
class Weights>
157 int lmax = modalities_.begin();
160 for (
int l=modalities_.begin();
l< modalities_.end(); ++
l)
163 for (
int k= tk.begin(); k < tk.end(); ++k)
164 {
p += tk[k] * proba(k,
j,
l);}
175template<
class Derived>
178 ArrayXX p(modalities(), p_data()->cols());
179 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
182 for (
int j=
p.beginCols();
j <
p.endCols(); ++
j)
184 for (
int l= modalities().begin();
l < modalities().end(); ++
l)
185 {
p(
l,
j) = proba(k,
j,
l);}
187 os <<
_T(
"---> Component ") << k <<
_T(
"\n");
188 os <<
_T(
"probabilities =\n") <<
p <<
_T(
"\n");
193template<
class Derived>
197 int nbCluster = this->nbCluster();
198 int nbModalities = modalities().size();
200 params.resize(nbModalities * nbCluster, p_data()->cols());
201 for (
int k = 0; k < nbCluster; ++k)
203 for (
int j = p_data()->beginCols();
j < p_data()->endCols(); ++
j)
205 for (
int l = 0;
l < nbModalities; ++
l)
A Array2DPoint is a one dimensional horizontal container.
#define _R(first, last)
Utility macro that can be used in a similar way that first:last.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Base class for the Categorical models.
~CategoricalBase()
destructor
CategoricalBase(CategoricalBase const &model)
copy constructor
CVectorX proba(int k, int j) const
Array const *const & p_data() const
Real proba(int k, int j, int l) const
int rand(int i, int j, int k) const
Parameters param_
parameters of the derived mixture model.
IMixtureDensity< Derived > Base
Range modalities_
range of the modalities
Range const & modalities() const
void initializeModelImpl()
Initialize the model.
CategoricalBase(int nbCluster)
default constructor
int impute(int i, int j, Weights const &tk) const
PointXi nbModalities_
Array with the number of modalities of each columns of the data set.
void writeParameters(CArrayXX const *p_tik, ostream &os) const
This function can be used to write summary of parameters to the output stream.
void getParameters(Array ¶ms) const
This function is used in order to get the current values of the parameters in an array.
Real lnComponentProbability(int i, int k) const
PointXi const & nbModalities() const
Derived & resize(Range const &I, Range const &J)
resize the array.
Base class for all Mixture densities.
Array const *const & p_data() const
Parameters param_
parameters of the derived mixture model.
hidden::MixtureTraits< Derived >::Array Array
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
const int baseIdx
base index of the containers created in STK++.
double Real
STK fundamental type of Real values.
hidden::SliceVisitorSelector< Derived, hidden::MinVisitor, Arrays::by_col_ >::type_result min(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual minimal value of the ...
hidden::SliceVisitorSelector< Derived, hidden::MaxVisitor, Arrays::by_col_ >::type_result max(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual maximal value of the ...
std::basic_ostream< Char > ostream
ostream for Char
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.