35#ifndef STK_GAMMA_AK_BJ_H
36#define STK_GAMMA_AK_BJ_H
39#include "../GammaModels/STK_GammaBase.h"
46template<
class Array>
class Gamma_ak_bj;
112 this->moments(p_tik);
114 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
117 for (
int j=p_data()->beginCols();
j < p_data()->endCols(); ++
j)
119 Real mean = meanjk(
j,k), variance = variancejk(
j,k);
125 for (
int j=p_data()->beginCols();
j < p_data()->endCols(); ++
j)
128 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
130 Real mean = meanjk(
j,k), variance = variancejk(
j,k);
131 value += p_tk->elt(k) * variance/
mean;
135#ifdef STK_MIXTURE_VERY_VERBOSE
136 stk_cout <<
_T(
" Gamma_ak_bj<Array>::randomInit done\n");
144 if (!this->moments(p_tik)) {
return false;}
148 for(iter=0; iter<
MAXITER; ++iter)
151 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
154 Real x0 = (param_.mean_[k].square()/param_.variance_[k]).
mean();
155 Real x1 = param_.shape_[k];
164 param_.shape_[k]=
x0;
165#ifdef STK_MIXTURE_DEBUG
166 stk_cout <<
_T(
"ML estimation failed in Gamma_ak_bj::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) \n");
173 else { param_.shape_[k]= a;}
176 for (
int j=p_data()->beginCols();
j<p_data()->endCols(); ++
j)
179 for (
int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
181 num += param_.mean_[k][
j] * p_tk->elt(k);
182 den += param_.shape_[k] * p_tk->elt(k);
188 param_.scale_[
j] = b;
191 Real value = this->qValue(p_tik, p_tk);
192#ifdef STK_MIXTURE_DEBUG
195 stk_cout <<
_T(
"In Gamma_ak_bj::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) : run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) diverge\n");
202#ifdef STK_MIXTURE_DEBUG
205 stk_cout <<
_T(
"In Gamma_ak_bj::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_ak_bj is a mixture model of the following form.
Gamma_ak_bj(Gamma_ak_bj const &model)
copy constructor
void randomInit(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Initialize randomly the parameters of the Gaussian mixture.
Gamma_ak_bj(int nbCluster)
default constructor
GammaBase< Gamma_ak_bj< Array > > Base
int computeNbFreeParameters() const
bool run(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Compute the weighted mean and the common variance.
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.
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.
static bool isFinite(Type const &x)
ModelParameters< Clust::Gamma_ak_bj_ > Parameters
Type of the structure storing the parameters of a Gamma_ak_bj model.
Main class for the mixtures traits policy.