35#ifndef STK_GAMMA_AJ_BK_H
36#define STK_GAMMA_AJ_BK_H
39#include "../GammaModels/STK_GammaBase.h"
46template<
class Array>
class Gamma_aj_bk;
114 this->moments(p_tik);
116 for (
int j=p_data()->beginCols();
j < p_data()->endCols(); ++
j)
119 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
121 Real mean = meanjk(
j,k), variance = variancejk(
j,k);
122 value += p_tk->elt(k) *
mean*
mean/variance;
127 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
129#ifdef STK_MIXTURE_VERY_VERBOSE
130 stk_cout <<
_T(
" Gamma_aj_bk<Array>::randomInit done\n");
139 if (!this->moments(p_tik)) {
flag =
false;}
144 for(iter = 0; iter<
MAXITER; ++iter)
147 for (
int j=p_data()->beginCols();
j<p_data()->endCols(); ++
j)
151 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
153 Real mean = meanjk(
j,k), variance = variancejk(
j,k);
154 y += p_tk->elt(k) * (param_.meanLog_[k][
j] - std::log(param_.scale_[k]));
157 y /= this->nbSample();
158 x0/= this->nbSample();
171 #ifdef STK_MIXTURE_DEBUG
172 stk_cout <<
"ML estimation failed in Gamma_aj_bk::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) \n";
183#ifdef STK_MIXTURE_DEBUG
184 stk_cout <<
_T(
"ML estimation failed in Gamma_aj_bk::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) \n");
193 param_.shape_[
j] = a;
195 Real sum = param_.shape_.sum();
196 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
198 param_.scale_[k] = param_.mean_[k].sum()/
sum;
202 Real value = this->qValue(p_tik, p_tk);
203#ifdef STK_MIXTURE_VERBOSE
206 stk_cout <<
_T(
"In Gamma_aj_bk::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) : run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) diverge\n");
213#ifdef STK_MIXTURE_VERBOSE
216 stk_cout <<
_T(
"In Gamma_aj_bk::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) : run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) did not converge\n");
In this file we implement the exponential law.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Base class for the gamma models.
Array const *const & p_data() const
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.
Real variancejk(int j, int k)
get the weighted variance of the jth variable of the kth cluster.
Gamma_aj_bk is a mixture model of the following form.
Gamma_aj_bk(Gamma_aj_bk const &model)
copy constructor
void randomInit(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Initialize randomly the parameters of the Gamma mixture.
Gamma_aj_bk(int nbCluster)
default constructor
bool run(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Compute the run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) .
int computeNbFreeParameters() const
GammaBase< Gamma_aj_bk< Array > > Base
virtual Real rand() const
Generate a pseudo Exponential random variate.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Functor computing the difference between the psi function and a fixed value.
Real findZero(IFunction< Function > const &f, Real const &x0, Real const &x1, Real tol)
find the zero of a function.
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
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...
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.
ModelParameters< Clust::Gamma_aj_bk_ > Parameters
Type of the structure storing the parameters of a Gamma_aj_bk model.
Main class for the mixtures traits policy.