STK++
0.9.13
STK_CategoricalParameters.cpp
Go to the documentation of this file.
1
/*--------------------------------------------------------------------*/
2
/* Copyright (C) 2004-2016 Serge Iovleff
3
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU Lesser General Public License as
6
published by the Free Software Foundation; either version 2 of the
7
License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
13
14
You should have received a copy of the GNU Lesser General Public
15
License along with this program; if not, write to the
16
Free Software Foundation, Inc.,
17
59 Temple Place,
18
Suite 330,
19
Boston, MA 02111-1307
20
USA
21
22
Contact : S..._DOT_I..._AT_stkpp.org (see copyright for ...)
23
*/
24
25
/*
26
* Project: stkpp::Clustering
27
* created on: Oct 24, 2013
28
* Author: Serge Iovleff
29
**/
30
36
#include <
Clustering/include/CategoricalModels/STK_CategoricalParameters.h
>
37
38
namespace
STK
39
{
40
41
/*------------------Categorical_pjk_--------------- */
42
/* default constructor
43
* @param nbCluster the number of class of the mixture
44
**/
45
ModelParameters<Clust::Categorical_pjk_>::ModelParameters
(
int
nbCluster)
46
: proba_(nbCluster), stat_proba_(nbCluster) {}
47
/* copy constructor.
48
* @param param the parameters to copy.
49
**/
50
ModelParameters<Clust::Categorical_pjk_>::ModelParameters
(
ModelParameters
const
& param)
51
: proba_(param.proba_), stat_proba_(param.stat_proba_)
52
{}
53
/* copy operator.
54
* @param param the parameters to copy.
55
**/
56
ModelParameters<Clust::Categorical_pjk_>
&
ModelParameters<Clust::Categorical_pjk_>::operator=
(
ModelParameters
const
& param)
57
{
58
proba_ = param.proba_;
59
stat_proba_ = param.stat_proba_;
60
return
*
this
;
61
}
62
/* destructor */
63
ModelParameters<Clust::Categorical_pjk_>::~ModelParameters
() {}
64
/* resize the set of parameter */
65
void
ModelParameters<Clust::Categorical_pjk_>::resize
(
Range
const
&
rangeModalities
,
Range
const
& rangeCols)
66
{
67
for
(
int
k = proba_.begin(); k< proba_.end(); ++k)
68
{
69
proba_[k].resize(
rangeModalities
, rangeCols) = 1./
rangeModalities
.size();
70
stat_proba_[k].resize(
rangeModalities
, rangeCols);
71
}
72
}
73
74
/* update statistics of the parameters. */
75
void
ModelParameters<Clust::Categorical_pjk_>::updateStatistics
()
76
{
77
for
(
int
k=stat_proba_.begin(); k<stat_proba_.end(); ++k)
78
{ stat_proba_[k].update(proba_[k]);}
79
}
80
/* set and release the computed statistics */
81
void
ModelParameters<Clust::Categorical_pjk_>::setStatistics
()
82
{
83
for
(
int
k=stat_proba_.begin(); k<stat_proba_.end(); ++k)
84
{
85
proba_[k] = stat_proba_[k].mean();
86
stat_proba_[k].release();
87
}
88
}
89
90
/* Set the computed statistics */
91
void
ModelParameters<Clust::Categorical_pjk_>::releaseStatistics
()
92
{
93
for
(
int
k=stat_proba_.begin(); k<stat_proba_.end(); ++k)
94
{ stat_proba_[k].release();}
95
}
96
97
/*------------------Categorical_pk_--------------- */
98
/* default constructor
99
* @param nbCluster the number of class of the mixture
100
**/
101
ModelParameters<Clust::Categorical_pk_>::ModelParameters
(
int
nbCluster)
102
: proba_(nbCluster), stat_proba_(nbCluster) {}
103
/* copy constructor.
104
* @param param the parameters to copy.
105
**/
106
ModelParameters<Clust::Categorical_pk_>::ModelParameters
(
ModelParameters
const
& param)
107
: proba_(param.proba_), stat_proba_(param.stat_proba_)
108
{}
109
/* destructor */
110
ModelParameters<Clust::Categorical_pk_>::~ModelParameters
() {}
111
/* copy operator.
112
* @param param the parameters to copy.
113
**/
114
ModelParameters<Clust::Categorical_pk_>
&
ModelParameters<Clust::Categorical_pk_>::operator=
(
ModelParameters
const
& param)
115
{
116
proba_ = param.proba_;
117
stat_proba_ = param.stat_proba_;
118
return
*
this
;
119
}
120
121
/* resize the set of parameter */
122
void
ModelParameters<Clust::Categorical_pk_>::resize
(
Range
const
&
rangeModalities
,
Range
const
& rangeCols)
123
{
124
for
(
int
k = proba_.begin(); k< proba_.end(); ++k)
125
{
126
proba_[k].resize(
rangeModalities
) = 1./
rangeModalities
.size();
127
stat_proba_[k].resize(
rangeModalities
);
128
}
129
}
130
/* update statistics of the parameters. */
131
void
ModelParameters<Clust::Categorical_pk_>::updateStatistics
()
132
{
133
for
(
int
k=stat_proba_.begin(); k<stat_proba_.end(); ++k)
134
{ stat_proba_[k].update(proba_[k]);}
135
}
136
/* set the computed statistics */
137
void
ModelParameters<Clust::Categorical_pk_>::setStatistics
()
138
{
139
for
(
int
k=stat_proba_.begin(); k<stat_proba_.end(); ++k)
140
{
141
proba_[k] = stat_proba_[k].mean();
142
stat_proba_[k].release();
143
}
144
}
145
/* release the computed statistics */
146
void
ModelParameters<Clust::Categorical_pk_>::releaseStatistics
()
147
{
148
for
(
int
k=stat_proba_.begin(); k<stat_proba_.end(); ++k)
149
{ stat_proba_[k].release();}
150
}
151
152
}
// namespace STK
153
STK_CategoricalParameters.h
In this file we define the Parameters classes for categorical mixture models.
STK::MultidimRegression
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Definition
STK_MultidimRegression.h:52
STK::TRange< UnknownSize >
Index sub-vector region: Specialization when the size is unknown.
Definition
STK_Range.h:265
STK
The namespace STK is the main domain space of the Statistical ToolKit project.
STK::ModelParameters
struct storing the parameters of the mixture.
Definition
STK_Clust_Util.h:60
projects
Clustering
src
STK_CategoricalParameters.cpp
Generated on Sat Feb 15 2025 12:07:15 for STK++ by
1.9.8