1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/* Copyright (C) 2009 Jens-Malte Gottfried <jmgottfried@web.de>
This file is part of Charon.
Charon is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Charon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Charon. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file fit2_CdFitter.cpp
* \author <a href="Jens-Malte.Gottfried@iwr.uni-heidelberg.de">
* Jens-Malte Gottfried </a>
* \date 19.11.2010
* \test
* Run Contrastive Divergence fitter on known distribution to recover
* its parameters.
*/
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <cassert>
// needed CPP definitions
#ifndef GLOBAL_PLUGIN_DIR
/// set this to the global plugin path
#define GLOBAL_PLUGIN_DIR ""
#error GLOBAL_PLUGIN_DIR not defined!
#endif
#ifndef LOCAL_PLUGIN_DIR
/// set this to the plugin build path (local plugin path)
#define LOCAL_PLUGIN_DIR ""
#error LOCAL_PLUGIN_DIR not defined!
#endif
#ifndef TESTDIR
/// local test source directory
#define TESTDIR ""
#error TESTDIR not defined!
#endif
#include <charon-core/PluginManager.h>
#include <charon-core/ExceptionHandler.h>
#include <charon/MixtureOfGaussians.h>
/// unit tests
int test() {
std::ofstream log("fit2_CdFitter.log", std::ios::trunc);
assert(log.good());
sout.assign(log);
// load plugin manager
PluginManager man(GLOBAL_PLUGIN_DIR, LOCAL_PLUGIN_DIR);
// start tests
std::string testfile(TESTDIR "/fit2.wrp");
std::cout << "Loading parameter file \"" << testfile;
std::cout << "\"" << std::endl;
man.loadParameterFile(testfile);
// get test instances
MixtureOfGaussians* gsm = dynamic_cast<MixtureOfGaussians*>(
man.getInstance("gsm"));
assert(gsm);
// print results to stdout
std::cout << "Parameters on start:" << std::endl;
gsm->run();
sout.assign(std::cout);
gsm->printParameters();
sout.assign(log);
man.runWorkflow();
std::cout << "Parameters after fitting:" << std::endl;
sout.assign(std::cout);
gsm->printParameters();
sout.assign(log);
// since sampling is a random process, this may fail
// but only in rare cases.
assert(gsm->fitParameters[0]>0.2);
assert(gsm->fitParameters[0]<0.3);
assert(gsm->fitParameters[1]>0.7);
assert(gsm->fitParameters[1]<0.8);
man.reset();
sout.assign();
log.close();
return EXIT_SUCCESS;
}
/// start tests with exception handling
int main() {
return ExceptionHandler::run(test);
}
|