-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtestIvm.cpp
177 lines (154 loc) · 5.26 KB
/
testIvm.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "CKern.h"
#include "CMatrix.h"
#include "CIvm.h"
int testGaussian();
int testProbit();
int testNcnm();
int main()
{
int fail = 0;
fail += testGaussian();
//fail += testOrdered();
fail += testProbit();
fail += testNcnm();
cout << "Number of failures: " << fail << endl;
}
int testGaussian()
{
int fail = 0;
CMatrix X;
X.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmGaussian.mat", "X");
CMatrix y;
y.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmGaussian.mat", "y");
CCmpndKern kernInit(X);
kernInit.addKern(new CRbfKern(X));
kernInit.addKern(new CLinKern(X));
kernInit.addKern(new CBiasKern(X));
kernInit.addKern(new CWhiteKern(X));
CGaussianNoise noiseInit(&y);
CIvm modelInit(&X, &y, &kernInit, &noiseInit, CIvm::ENTROPY, 50);
modelInit.selectPoints();
CCmpndKern kern(X);
kern.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmGaussian.mat", "kernInit");
CGaussianNoise noise(&y);
noise.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmGaussian.mat", "noiseInit");
CIvm model(&X, &y, &kern, &noise, "matfiles" + ndlstrutil::dirSep() + "testIvmGaussian.mat", "ivmInfoInit", 0);
if(model.equals(modelInit))
cout << model.getNoiseName() << " Noise IVM passed." << endl;
else
{
cout << "FAILURE: " << model.getNoiseName() << " Noise IVM." << endl;
fail++;
}
return fail;
model.toFile("crap_ivm");
modelInit.fromFile("crap_ivm");
if(model.equals(modelInit))
cout << "Stream read and write " << model.getNoiseName() << " Noise IVM passed." << endl;
else
{
cout << "FAILURE: " << "Stream read and write " << model.getNoiseName() << " Noise IVM." << endl;
cout << "Written noise model: " << endl;
model.display(cout);
cout << "Read in noise model: " << endl;
modelInit.display(cout);
fail++;
}
}
int testProbit()
{
int fail = 0;
CMatrix X;
X.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmProbit.mat", "X");
CMatrix y;
y.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmProbit.mat", "y");
CCmpndKern kernInit(X);
kernInit.addKern(new CRbfKern(X));
kernInit.addKern(new CLinKern(X));
kernInit.addKern(new CBiasKern(X));
kernInit.addKern(new CWhiteKern(X));
CProbitNoise noiseInit(&y);
CIvm modelInit(&X, &y, &kernInit, &noiseInit, CIvm::ENTROPY, 50);
modelInit.selectPoints();
CCmpndKern kern(X);
kern.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmProbit.mat", "kernInit");
CProbitNoise noise(&y);
noise.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmProbit.mat", "noiseInit");
CIvm model(&X, &y, &kern, &noise, "matfiles" + ndlstrutil::dirSep() + "testIvmProbit.mat", "ivmInfoInit", 0);
if(model.equals(modelInit))
cout << model.getNoiseName() << " Noise IVM passed." << endl;
else
{
cout << "FAILURE: " << model.getNoiseName() << " Noise IVM." << endl;
fail++;
}
model.toFile("crap_ivm");
modelInit.fromFile("crap_ivm");
if(model.equals(modelInit))
cout << "Stream read and write " << model.getNoiseName() << " Noise IVM passed." << endl;
else
{
cout << "FAILURE: " << "Stream read and write " << model.getNoiseName() << " Noise IVM." << endl;
cout << "Written noise model: " << endl;
model.display(cout);
cout << "Read in noise model: " << endl;
modelInit.display(cout);
fail++;
}
return fail;
}
int testNcnm()
{
int fail = 0;
CMatrix X;
X.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmNcnm.mat", "X");
CMatrix y;
y.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmNcnm.mat", "y");
// Add L1 prior for the kernel.
CGammaDist* prior = new CGammaDist();
prior->setParam(1.0, 0);
prior->setParam(1.0, 1);
CRbfKern* rbfKern = new CRbfKern(X);
rbfKern->addPrior(prior, 1);
CLinKern* linKern = new CLinKern(X);
linKern->addPrior(prior, 0);
CBiasKern* biasKern = new CBiasKern(X);
biasKern->addPrior(prior, 0);
CWhiteKern* whiteKern = new CWhiteKern(X);
whiteKern->addPrior(prior, 0);
CCmpndKern kernInit(X);
kernInit.addKern(rbfKern);
kernInit.addKern(linKern);
kernInit.addKern(biasKern);
kernInit.addKern(whiteKern);
CNcnmNoise noiseInit(&y);
CIvm modelInit(&X, &y, &kernInit, &noiseInit, CIvm::ENTROPY, 50);
modelInit.selectPoints();
modelInit.checkGradients();
CCmpndKern kern(X);
kern.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmNcnm.mat", "kernInit");
CNcnmNoise noise(&y);
noise.readMatlabFile("matfiles" + ndlstrutil::dirSep() + "testIvmNcnm.mat", "noiseInit");
CIvm model(&X, &y, &kern, &noise, "matfiles" + ndlstrutil::dirSep() + "testIvmNcnm.mat", "ivmInfoInit", 0);
if(model.equals(modelInit))
cout << model.getNoiseName() << " Noise IVM passed." << endl;
else
{
cout << "FAILURE: " << model.getNoiseName() << " Noise IVM." << endl;
fail++;
}
model.toFile("crap_ivm");
modelInit.fromFile("crap_ivm");
if(model.equals(modelInit))
cout << "Stream read and write " << model.getNoiseName() << " Noise IVM passed." << endl;
else
{
cout << "FAILURE: " << "Stream read and write " << model.getNoiseName() << " Noise IVM." << endl;
cout << "Written noise model: " << endl;
model.display(cout);
cout << "Read in noise model: " << endl;
modelInit.display(cout);
fail++;
}
return fail;
}