35#ifndef STK_GAMMABASE_H
36#define STK_GAMMABASE_H
38#include "../STK_IMixtureDensity.h"
46#include "../GammaModels/STK_GammaParameters.h"
94template<
class Derived>
131 template<
class Weights>
143 template<
class Array>
169template<
class Derived>
173 for (
int j=p_data()->beginCols();
j<p_data()->endCols(); ++
j)
175 if (param_.shape(k,
j) && param_.scale(k,
j))
184template<
class Derived>
185template<
class Weights>
189 for (
int k= pk.begin(); k < pk.end(); ++k)
190 {
sum += pk[k] * shape(k,
j) * scale(k,
j);}
195template<
class Derived>
198 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
201 for (
int j=p_data()->beginCols();
j<p_data()->endCols(); ++
j)
206 param_.mean_[k][
j] =
mean;
209 if (
isNA(meanLog)) {
return false;}
210 param_.meanLog_[k][
j] = meanLog;
213 if ((variance<=0)||
isNA(variance)){
return false;}
214 param_.variance_[k][
j] = variance;
221template<
class Derived>
225 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
228 for (
int j=p_data()->beginCols();
j<p_data()->endCols(); ++
j)
230 Real a = shape(k,
j), b = scale(k,
j);
231 sumjk += a * (param_.meanLog_[k][
j]-std::log(b))
234 value += p_tk->elt(k) *
sumjk;
239template<
class Derived>
242 CPointX a(p_data()->cols()), b(p_data()->cols());
243 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
246 for (
int j=p_data()->beginCols();
j < p_data()->endCols(); ++
j)
251 os <<
_T(
"---> Component ") << k <<
_T(
"\n");
252 os <<
_T(
"shape = ") << a;
253 os <<
_T(
"scale = ") << b;
257template<
class Derived>
261 int nbClust = this->nbCluster();
263 for (
int k= 0; k <
nbClust; ++k)
265 for (
int j= p_data()->beginCols();
j< p_data()->endCols(); ++
j)
In this file we declare functions around the gamma function.
In this file we declare raw the functions.
In this file we define the Gamma probability distribution.
This file contain the functors computings statistics.
#define _T(x)
Let x unmodified.
Base class for the gamma models.
Real meank(int k)
get the mean of the weighted means of the kth cluster.
Real lnComponentProbability(int i, int k) const
Array const *const & p_data() const
Real variancek(int k)
get the mean of the weighted variances of the kth cluster.
Parameters param_
parameters of the derived mixture model.
Real meanjk(int j, int k)
get the weighted mean of the jth variable of the kth cluster.
bool moments(CArrayXX const *p_tik)
compute the weighted moments of a gamma mixture.
Real rand(int i, int j, int k) const
void writeParameters(CArrayXX const *p_tik, ostream &os) const
This function can be used to write summary of parameters to the output stream.
Real impute(int i, int j, Weights const &pk) const
void initializeModelImpl()
Initialize the parameters of the model.
GammaBase(int nbCluster)
default constructor
Real shape(int k, int j) const
Real scale(int k, int j) const
IMixtureDensity< Derived > Base
Real variancejk(int j, int k)
get the weighted variance of the jth variable of the kth cluster.
Real qValue(CArrayXX const *p_tik, CPointX const *p_tk) const
compute the Q(theta) value.
void getParameters(Array ¶ms) const
This function is used in order to get the current values of the parameters in an array of size (2*nbC...
GammaBase(GammaBase const &model)
copy constructor
hidden::CSlice< Derived, sizeRows_, 1 >::Result col(int j) const
implement the col operator using a reference on the column of the allocator
Interface base class for functions.
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
virtual Real lpdf(Real const &x) const
Compute.
virtual Real rand() const
generate a gamma random variate using the G.S algorithm of Ahrens and Dieter (1974) for 0<a_<1 and Ma...
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Functor computing the derivative of the lnLikelihood of a gamma_ajk_bjk model.
invPsiMLog(Real const &y)
Real fImpl(Real const &a) const
Functor computing the difference between the psi function and a fixed value.
invPsi(Real const &y)
initialize y_
Real fImpl(Real const &x) const
Real psi_raw(Real x)
Compute the psi function.
Real lgamma(Real const &)
This function computes the function .
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
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::MeanVisitor, Arrays::by_col_ >::type_result mean(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual mean value of the vec...
std::basic_ostream< Char > ostream
ostream for Char
The namespace STK is the main domain space of the Statistical ToolKit project.