STK++ 0.9.13
STK_GammaParameters.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
37
38namespace STK
39{
40/* copy operator */
42{
43 mean_ = other.mean_;
44 meanLog_ = other.meanLog_;
45 variance_ = other.variance_;
46 return *this;
47}
48
49/* default constructor */
51 : mean_(nbCluster), meanLog_(nbCluster)
52 , variance_(nbCluster)
53{}
54/* copy constructor */
56 : mean_(model.mean_)
57 , meanLog_(model.meanLog_)
58 , variance_(model.variance_) {}
59/* destructor */
61/* @param range the range of the variables */
63{
64 for (int k=mean_.begin(); k < mean_.end(); ++k)
65 {
66 mean_[k].resize(range) = 1.;
67 meanLog_[k].resize(range) = 0.;
68 variance_[k].resize(range) = 1.;
69 }
70}
71
72/* default constructor
73 * @param nbCluster the number of class of the mixture
74 **/
76 : ParametersGammaBase(nbCluster)
77 , shape_(0.), scale_(nbCluster)
78 , stat_shape_(), stat_scale_(nbCluster)
79{}
80/* copy constructor.
81 * @param param the parameters to copy.
82 **/
84 : ParametersGammaBase(param)
85 , shape_(param.shape_), scale_(param.scale_)
86 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
87{}
88/* destructor */
90
91/* resize the set of parameter */
93{
95 shape_ = 1.;
96 stat_shape_.release();
97 for (int k = scale_.begin(); k< scale_.end(); ++k)
98 {
99 scale_[k].resize(range) = 1.;
100 stat_scale_[k].resize(range);
101 }
102}
103
104/* update statistics of the parameters. */
106{
107 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
108 { stat_scale_[k].update(scale_[k]);}
109 stat_shape_.update(shape_);
110}
111/* Set the computed statistics */
113{
114 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
115 {
116 scale_[k] = stat_scale_[k].mean();
117 stat_scale_[k].release();
118 }
119 shape_ = stat_shape_.mean();
120 stat_shape_.release();
121}
122/* Release the computed statistics */
124{
125 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
126 { stat_scale_[k].release();}
127 stat_shape_.release();
128}
129
130/* default constructor
131 * @param nbCluster the number of class of the mixture
132 **/
134 : ParametersGammaBase(nbCluster)
135 , shape_(0.), scale_(nbCluster)
136 , stat_shape_(), stat_scale_(nbCluster)
137{}
138/* copy constructor.
139 * @param param the parameters to copy.
140 **/
142 : ParametersGammaBase(param)
143 , shape_(param.shape_), scale_(param.scale_)
144 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
145{}
146/* destructor */
148/* resize the set of parameter */
150{
152 shape_ = 1.;
153 stat_shape_.release();
154 for (int k = scale_.begin(); k< scale_.end(); ++k)
155 { scale_[k] = 1.;}
156}
157
158/* update statistics of the parameters. */
160{
161 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
162 { stat_scale_[k].update(scale_[k]);}
163 stat_shape_.update(shape_);
164}
165/* Set the computed statistics */
167{
168 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
169 {
170 scale_[k] = stat_scale_[k].mean();
171 stat_scale_[k].release();
172 }
173 shape_ = stat_shape_.mean();
174 stat_shape_.release();
175}
176/* Release the computed statistics */
178{
179 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
180 { stat_scale_[k].release();}
181 stat_shape_.release();
182}
183
184/* default constructor
185 * @param nbCluster the number of class of the mixture
186 **/
188 : ParametersGammaBase(nbCluster)
189 , shape_(), scale_(nbCluster)
190 , stat_shape_(), stat_scale_(nbCluster)
191{}
192/* copy constructor.
193 * @param param the parameters to copy.
194 **/
196 : ParametersGammaBase(param)
197 , shape_(param.shape_), scale_(param.scale_)
198 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
199{}
200/* destructor */
202/* resize the set of parameter */
204{
206 shape_.resize(range) = 1.;
207 stat_shape_.resize(range);
208 for (int k = scale_.begin(); k< scale_.end(); ++k)
209 {
210 scale_[k].resize(range) = 1.;
211 stat_scale_[k].resize(range);
212 }
213}
214
215/* update statistics of the parameters. */
217{
218 stat_shape_.release();
219 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
220 { stat_scale_[k].update(scale_[k]);}
221}
222/* Set the computed statistics */
224{
225 shape_ = stat_shape_.mean();
226 stat_shape_.release();
227 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
228 {
229 scale_[k] = stat_scale_[k].mean();
230 stat_scale_[k].release();
231 }
232}
233/* Release the computed statistics */
235{
236 stat_shape_.release();
237 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
238 { stat_scale_[k].release();}
239}
240
241/* default constructor
242 * @param nbCluster the number of class of the mixture
243 **/
245 : ParametersGammaBase(nbCluster)
246 , shape_(), scale_(nbCluster)
247 , stat_shape_(nbCluster), stat_scale_(nbCluster)
248{}
249/* copy constructor.
250 * @param param the parameters to copy.
251 **/
253 : ParametersGammaBase(param)
254 , shape_(param.shape_), scale_(param.scale_)
255 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
256{}
257/* destructor */
259/* resize the set of parameter */
261{
263 shape_.resize(range) = 1.;
264 stat_shape_.resize(range);
265 for (int k = scale_.begin(); k< scale_.end(); ++k)
266 {
267 scale_[k] = 1.;
268 stat_scale_[k].release();
269 }
270}
271
272/* update statistics of the parameters. */
274{
275 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
276 { stat_scale_[k].update(scale_[k]);}
277 stat_shape_.update(shape_);
278}
279/* Set the computed statistics */
281{
282 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
283 {
284 scale_[k] = stat_scale_[k].mean();
285 stat_scale_[k].release();
286 }
287 shape_ = stat_shape_.mean();
288 stat_shape_.release();
289}
290/* Release the computed statistics */
292{
293 for(int k=stat_scale_.begin(); k<stat_scale_.end(); ++k)
294 { stat_scale_[k].release();}
295 stat_shape_.release();
296}
297
298/* default constructor
299 * @param nbCluster the number of class of the mixture
300 **/
302 : ParametersGammaBase(nbCluster)
303 , shape_(nbCluster), scale_()
304 , stat_shape_(nbCluster), stat_scale_()
305{}
306/* copy constructor.
307 * @param param the parameters to copy.
308 **/
310 : ParametersGammaBase(param)
311 , shape_(param.shape_), scale_(param.scale_)
312 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
313{}
314/* destructor */
316/* resize the set of parameter */
318{
320 for (int k = shape_.begin(); k< shape_.end(); ++k)
321 {
322 shape_[k].resize(range) = 1.;
323 stat_shape_[k].resize(range);
324 }
325 scale_ = 1.;
326 stat_scale_.release();
327}
328/* update statistics of the parameters. */
330{
331 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
332 { stat_shape_[k].update(shape_[k]);}
333 stat_scale_.update(scale_);
334}
335/* Set the computed statistics */
337{
338 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
339 {
340 shape_[k] = stat_shape_[k].mean();
341 stat_shape_[k].release();
342 }
343 scale_ = stat_scale_.mean();
344 stat_scale_.release();
345}
346/* Release the computed statistics */
348{
349 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
350 { stat_shape_[k].release();}
351 stat_scale_.release();
352}
353
354/* default constructor
355 * @param nbCluster the number of class of the mixture
356 **/
358 : ParametersGammaBase(nbCluster)
359 , shape_(nbCluster), scale_()
360 , stat_shape_(nbCluster), stat_scale_(nbCluster)
361{}
362/* copy constructor.
363 * @param param the parameters to copy.
364 **/
366 : ParametersGammaBase(param)
367 , shape_(param.shape_), scale_(param.scale_)
368 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
369{}
370/* destructor */
372/* resize the set of parameter */
374{
376 scale_.resize(range) = 1.;
377 stat_scale_.resize(range);
378 for (int k = shape_.begin(); k< shape_.end(); ++k)
379 {
380 shape_[k].resize(range) = 1.;
381 stat_shape_[k].resize(range);
382 }
383}
384/* update statistics of the parameters. */
386{
387 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
388 { stat_shape_[k].update(shape_[k]);}
389 stat_scale_.update(scale_);
390}
391/* Set the computed statistics */
393{
394 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
395 {
396 shape_[k] = stat_shape_[k].mean();
397 stat_shape_[k].release();
398 }
399 scale_ = stat_scale_.mean();
400 stat_scale_.release();
401}
402/* Release the computed statistics */
404{
405 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
406 { stat_shape_[k].release();}
407 stat_scale_.release();
408}
409
410
411/* default constructor
412 * @param nbCluster the number of class of the mixture
413 **/
415 : ParametersGammaBase(nbCluster)
416 , shape_(nbCluster), scale_(nbCluster)
417 , stat_shape_(nbCluster), stat_scale_(nbCluster)
418{}
419/* copy constructor.
420 * @param param the parameters to copy.
421 **/
423 : ParametersGammaBase(param)
424 , shape_(param.shape_), scale_(param.scale_)
425 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
426{}
427/* destructor */
429
430/* resize the set of parameter */
432{
434 for (int k = shape_.begin(); k< shape_.end(); ++k)
435 {
436 shape_[k].resize(range) = 1.;
437 stat_shape_[k].resize(range);
438 scale_[k].resize(range) = 1.;
439 stat_scale_[k].resize(range);
440 }
441}
442
443/* update statistics of the parameters. */
445{
446 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
447 { stat_shape_[k].update(shape_[k]);
448 stat_scale_[k].update(scale_[k]);
449 }
450}
451/* Set the computed statistics */
453{
454 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
455 {
456 shape_[k] = stat_shape_[k].mean();
457 stat_shape_[k].release();
458 scale_[k] = stat_scale_[k].mean();
459 stat_scale_[k].release();
460 }
461}
462/* Release the computed statistics */
464{
465 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
466 {
467 stat_shape_[k].release();
468 stat_scale_[k].release();
469 }
470}
471
472/* default constructor
473 * @param nbCluster the number of class of the mixture
474 **/
476 : ParametersGammaBase(nbCluster)
477 , shape_(nbCluster), scale_(nbCluster)
478 , stat_shape_(nbCluster), stat_scale_(nbCluster)
479{}
480/* copy constructor.
481 * @param param the parameters to copy.
482 **/
484 : ParametersGammaBase(param)
485 , shape_(param.shape_), scale_(param.scale_)
486 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
487{}
488/* destructor */
490/* resize the set of parameter */
492{
494 for (int k = shape_.begin(); k< shape_.end(); ++k)
495 {
496 shape_[k].resize(range) = 1.;
497 stat_shape_[k].resize(range);
498 scale_[k] = 1.;
499 stat_scale_[k].release();
500 }
501}
502
503/* update statistics of the parameters. */
505{
506 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
507 {
508 stat_shape_[k].update(shape_[k]);
509 stat_scale_[k].update(scale_[k]);
510 }
511}
512/* Set the computed statistics */
514{
515 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
516 {
517 shape_[k] = stat_shape_[k].mean();
518 stat_shape_[k].release();
519 scale_[k] = stat_scale_[k].mean();
520 stat_scale_[k].release();
521 }
522}
523/* Release the computed statistics */
525{
526 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
527 {
528 stat_shape_[k].release();
529 stat_scale_[k].release();
530 }
531}
532
533/* default constructor
534 * @param nbCluster the number of class of the mixture
535 **/
537 : ParametersGammaBase(nbCluster)
538 , shape_(nbCluster), scale_()
539 , stat_shape_(nbCluster), stat_scale_()
540{}
541/* copy constructor.
542 * @param param the parameters to copy.
543 **/
545 : ParametersGammaBase(param)
546 , shape_(param.shape_), scale_(param.scale_)
547 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
548{}
549/* destructor */
551/* resize the set of parameter */
553{
555 scale_ = 1.;
556 stat_scale_.release();
557 for (int k = shape_.begin(); k< shape_.end(); ++k)
558 {
559 shape_[k] = 1.;
560 stat_shape_[k].release();
561 }
562}
563
564/* update statistics of the parameters. */
566{
567 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
568 { stat_shape_[k].update(shape_[k]);}
569 stat_scale_.update(scale_);
570}
571/* Set the computed statistics */
573{
574 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
575 {
576 shape_[k] = stat_shape_[k].mean();
577 stat_shape_[k].release();
578 }
579 scale_ = stat_scale_.mean();
580 stat_scale_.release();
581}
582/* Release the computed statistics */
584{
585 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
586 { stat_shape_[k].release();}
587 stat_scale_.release();
588}
589
590/* default constructor
591 * @param nbCluster the number of class of the mixture
592 **/
594 : ParametersGammaBase(nbCluster)
595 , shape_(nbCluster), scale_()
596 , stat_shape_(nbCluster), stat_scale_(nbCluster)
597{}
598/* copy constructor.
599 * @param param the parameters to copy.
600 **/
602 : ParametersGammaBase(param)
603 , shape_(param.shape_), scale_(param.scale_)
604 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
605{}
606/* destructor */
608/* resize the set of parameter */
610{
612 for (int k = shape_.begin(); k< shape_.end(); ++k)
613 {
614 shape_[k] = 1.;
615 stat_shape_[k].release();
616 }
617 scale_.resize(range) = 1.;
618 stat_scale_.resize(range);
619}
620
621/* update statistics of the parameters. */
623{
624 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
625 { stat_shape_[k].update(shape_[k]);}
626 stat_scale_.update(scale_);
627}
628/* Set the computed statistics */
630{
631 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
632 {
633 shape_[k] = stat_shape_[k].mean();
634 stat_shape_[k].release();
635 }
636 scale_ = stat_scale_.mean();
637 stat_scale_.release();
638}
639/* Release the computed statistics */
641{
642 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
643 { stat_shape_[k].release();}
644 stat_scale_.release();
645}
646
647/* default constructor
648 * @param nbCluster the number of class of the mixture
649 **/
651 : ParametersGammaBase(nbCluster)
652 , shape_(nbCluster), scale_(nbCluster)
653 , stat_shape_(nbCluster), stat_scale_(nbCluster)
654{}
655/* copy constructor.
656 * @param param the parameters to copy.
657 **/
659 : ParametersGammaBase(param)
660 , shape_(param.shape_), scale_(param.scale_)
661 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
662{}
663/* destructor */
665/* resize the set of parameter */
667{
669 for (int k = shape_.begin(); k< shape_.end(); ++k)
670 {
671 shape_[k] = 1.;
672 stat_shape_[k].release();
673 scale_[k].resize(range) = 1.;
674 stat_scale_[k].resize(range);
675 }
676}
677/* update statistics of the parameters. */
679{
680 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
681 { stat_shape_[k].update(shape_[k]);
682 stat_scale_[k].update(scale_[k]);
683 }
684}
685/* Set the computed statistics */
687{
688 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
689 {
690 shape_[k] = stat_shape_[k].mean();
691 stat_shape_[k].release();
692 scale_[k] = stat_scale_[k].mean();
693 stat_scale_[k].release();
694 }
695}
696/* Release the computed statistics */
698{
699 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
700 {
701 stat_shape_[k].release();
702 stat_scale_[k].release();
703 }
704}
705
706
707/* default constructor
708 * @param nbCluster the number of class of the mixture
709 **/
711 : ParametersGammaBase(nbCluster)
712 , shape_(nbCluster), scale_(nbCluster)
713 , stat_shape_(nbCluster), stat_scale_(nbCluster)
714{}
715/* copy constructor.
716 * @param param the parameters to copy.
717 **/
719 : ParametersGammaBase(param)
720 , shape_(param.shape_), scale_(param.scale_)
721 , stat_shape_(param.stat_shape_), stat_scale_(param.stat_scale_)
722{}
723/* destructor */
725/* resize the set of parameter */
727{
729 for (int k = shape_.begin(); k< shape_.end(); ++k)
730 {
731 shape_[k] = 1.;
732 stat_shape_[k].release();
733 scale_[k] = 1.;
734 stat_scale_[k].release();
735 }
736}
737/* update statistics of the parameters. */
739{
740 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
741 { stat_shape_[k].update(shape_[k]);
742 stat_scale_[k].update(scale_[k]);
743 }
744}
745/* Set the computed statistics */
747{
748 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
749 {
750 shape_[k] = stat_shape_[k].mean();
751 stat_shape_[k].release();
752 scale_[k] = stat_scale_[k].mean();
753 stat_scale_[k].release();
754 }
755}
756/* Release the computed statistics */
758{
759 for(int k=stat_shape_.begin(); k<stat_shape_.end(); ++k)
760 {
761 stat_shape_[k].release();
762 stat_scale_[k].release();
763 }
764}
765
766} // namespace STK
767
In this file we define the Parameters classes for gamma mixture models.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
The namespace STK is the main domain space of the Statistical ToolKit project.
struct storing the parameters of the mixture.
base class of the Gamma models Parameter Handler
Array1D< CPointX > meanLog_
log-means for each class
ParametersGammaBase(int nbCluster)
default constructor
Array1D< CPointX > mean_
mean for each class
ParametersGammaBase & operator=(ParametersGammaBase const &other)
copy operator
Array1D< CPointX > variance_
variance for each class
void resize(Range const &range)