3644 |
11 May 17 |
peter |
// $Id$ |
3644 |
11 May 17 |
peter |
2 |
|
3644 |
11 May 17 |
peter |
3 |
/* |
3644 |
11 May 17 |
peter |
Copyright (C) 2017 Peter Johansson |
3644 |
11 May 17 |
peter |
5 |
|
3644 |
11 May 17 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3644 |
11 May 17 |
peter |
7 |
|
3644 |
11 May 17 |
peter |
The yat library is free software; you can redistribute it and/or |
3644 |
11 May 17 |
peter |
modify it under the terms of the GNU General Public License as |
3644 |
11 May 17 |
peter |
published by the Free Software Foundation; either version 3 of the |
3644 |
11 May 17 |
peter |
License, or (at your option) any later version. |
3644 |
11 May 17 |
peter |
12 |
|
3644 |
11 May 17 |
peter |
The yat library is distributed in the hope that it will be useful, |
3644 |
11 May 17 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3644 |
11 May 17 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3644 |
11 May 17 |
peter |
General Public License for more details. |
3644 |
11 May 17 |
peter |
17 |
|
3644 |
11 May 17 |
peter |
You should have received a copy of the GNU General Public License |
3644 |
11 May 17 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3644 |
11 May 17 |
peter |
20 |
*/ |
3644 |
11 May 17 |
peter |
21 |
|
3644 |
11 May 17 |
peter |
22 |
#include <config.h> |
3644 |
11 May 17 |
peter |
23 |
|
3644 |
11 May 17 |
peter |
24 |
#include "Suite.h" |
3644 |
11 May 17 |
peter |
25 |
|
3644 |
11 May 17 |
peter |
26 |
#include "yat/statistics/GaussianMixture.h" |
3644 |
11 May 17 |
peter |
27 |
|
3644 |
11 May 17 |
peter |
28 |
#include <gsl/gsl_cdf.h> |
3644 |
11 May 17 |
peter |
29 |
#include <gsl/gsl_math.h> |
3644 |
11 May 17 |
peter |
30 |
|
3644 |
11 May 17 |
peter |
31 |
#include <iostream> |
3645 |
16 May 17 |
peter |
32 |
#include <cmath> |
3644 |
11 May 17 |
peter |
33 |
|
3644 |
11 May 17 |
peter |
34 |
using namespace theplu::yat; |
3644 |
11 May 17 |
peter |
35 |
int main(int argc, char* argv[]) |
3644 |
11 May 17 |
peter |
36 |
{ |
3644 |
11 May 17 |
peter |
37 |
test::Suite suite(argc, argv); |
3644 |
11 May 17 |
peter |
38 |
|
3644 |
11 May 17 |
peter |
39 |
statistics::GaussianMixture model; |
3644 |
11 May 17 |
peter |
40 |
|
3644 |
11 May 17 |
peter |
// parameters |
3644 |
11 May 17 |
peter |
42 |
double m1 = 0; |
3644 |
11 May 17 |
peter |
43 |
double m2 = 1.0; |
3644 |
11 May 17 |
peter |
44 |
double s1 = 0.1; |
3644 |
11 May 17 |
peter |
45 |
double s2 = 0.2; |
3644 |
11 May 17 |
peter |
46 |
|
3644 |
11 May 17 |
peter |
// add data |
3644 |
11 May 17 |
peter |
48 |
double delta = 1.0 / 1000; |
3644 |
11 May 17 |
peter |
49 |
for (double p=delta/2; p<1.0; p+=delta) |
3644 |
11 May 17 |
peter |
50 |
model.add(gsl_cdf_gaussian_Pinv(p, s1)+m1); |
3644 |
11 May 17 |
peter |
51 |
for (double p=delta/2; p<1.0; p+=delta) |
3644 |
11 May 17 |
peter |
52 |
model.add(gsl_cdf_gaussian_Pinv(p, s2)+m2, 4); |
3644 |
11 May 17 |
peter |
53 |
|
3644 |
11 May 17 |
peter |
54 |
model.fit(2); |
3644 |
11 May 17 |
peter |
55 |
suite.out() << "result:\n"; |
3644 |
11 May 17 |
peter |
56 |
suite.out() << "alpha: " << model.alpha(0) << " " << model.alpha(1) << "\n"; |
3644 |
11 May 17 |
peter |
57 |
suite.out() << "m: " << model.mean(0) << " " << model.mean(1) << "\n"; |
3644 |
11 May 17 |
peter |
58 |
suite.out() << "std: " << model.std(0) << " " << model.std(1) << "\n"; |
3644 |
11 May 17 |
peter |
59 |
|
3644 |
11 May 17 |
peter |
60 |
suite.add(suite.equal_fix(model.alpha(0), 0.2, 0.001)); |
3644 |
11 May 17 |
peter |
61 |
suite.add(suite.equal_fix(model.alpha(1), 0.8, 0.001)); |
3644 |
11 May 17 |
peter |
62 |
suite.add(suite.equal_fix(model.mean(0), m1, 0.001)); |
3644 |
11 May 17 |
peter |
63 |
suite.add(suite.equal_fix(model.mean(1), m2, 0.001)); |
3644 |
11 May 17 |
peter |
64 |
suite.add(suite.equal_fix(model.std(0), s1, 0.001)); |
3644 |
11 May 17 |
peter |
65 |
suite.add(suite.equal_fix(model.std(1), s2, 0.001)); |
3644 |
11 May 17 |
peter |
66 |
|
3644 |
11 May 17 |
peter |
67 |
|
3644 |
11 May 17 |
peter |
68 |
suite.out() << "pdf(-10): " << model.pdf(-10) << "\n"; |
3644 |
11 May 17 |
peter |
69 |
suite.out() << "pdf(0.0): " << model.pdf(0.0) << "\n"; |
3644 |
11 May 17 |
peter |
70 |
suite.out() << "pdf(1.0): " << model.pdf(1.0) << "\n"; |
3644 |
11 May 17 |
peter |
71 |
suite.out() << "pdf(10): " << model.pdf(10) << "\n"; |
3644 |
11 May 17 |
peter |
72 |
|
3644 |
11 May 17 |
peter |
73 |
suite.add(suite.equal_fix(model.pdf(-10), 0.0, 0.001)); |
3644 |
11 May 17 |
peter |
74 |
suite.add(suite.equal_fix(model.pdf(0), 0.2 / (std::sqrt(2*M_PI)*s1), 0.001)); |
3644 |
11 May 17 |
peter |
75 |
suite.add(suite.equal_fix(model.pdf(1), 0.8 / (std::sqrt(2*M_PI)*s2), 0.001)); |
3644 |
11 May 17 |
peter |
76 |
suite.add(suite.equal_fix(model.pdf(10), 0.0, 0.001)); |
3644 |
11 May 17 |
peter |
77 |
|
3644 |
11 May 17 |
peter |
78 |
suite.out() << "cdf(-10): " << model.cdf_P(-10) << "\n"; |
3644 |
11 May 17 |
peter |
79 |
suite.out() << "cdf(0.0): " << model.cdf_P(0.0) << "\n"; |
3644 |
11 May 17 |
peter |
80 |
suite.out() << "cdf(1.0): " << model.cdf_P(1.0) << "\n"; |
3644 |
11 May 17 |
peter |
81 |
suite.out() << "cdf(10): " << model.cdf_P(10) << "\n"; |
3644 |
11 May 17 |
peter |
82 |
|
3644 |
11 May 17 |
peter |
83 |
suite.add(suite.equal_fix(model.cdf_P(-10), 0.0, 0.001)); |
3644 |
11 May 17 |
peter |
84 |
suite.add(suite.equal_fix(model.cdf_P(0.0), 0.1+0.0, 0.001)); |
3644 |
11 May 17 |
peter |
85 |
suite.add(suite.equal_fix(model.cdf_P(1.0), 0.2+0.4, 0.001)); |
3644 |
11 May 17 |
peter |
86 |
suite.add(suite.equal_fix(model.cdf_P(10), 1.0, 0.001)); |
3644 |
11 May 17 |
peter |
87 |
|
4200 |
19 Aug 22 |
peter |
88 |
|
3644 |
11 May 17 |
peter |
89 |
return suite.return_value(); |
3644 |
11 May 17 |
peter |
90 |
} |