-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtoy.cpp
More file actions
66 lines (52 loc) · 1.29 KB
/
toy.cpp
File metadata and controls
66 lines (52 loc) · 1.29 KB
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
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <cassert>
#include <map>
#include "SoftTree.cpp"
double randnorm() {
double x=0;
for (uint i=0; i<12; i++)
x += (double)rand()/RAND_MAX;
return x-6;
}
// Regression toy dataset generator
void generateToy(vector< vector<double> > &X, vector<double> &Y) {
uint d=1; // dimension
uint n=300; // number of instances
uint i,j;
for (i=0; i<n; i++)
{
vector<double> x;
for (j=0; j<d; j++)
x.push_back(((double)rand()/RAND_MAX)*6-3);
X.push_back(x);
Y.push_back(sin(2*x[0]) + randnorm()*0.04);
}
}
int main(int argc, char *argv[])
{
vector< vector< double> > X, V, U;
vector<double> Y, R, T;
//srand(time(NULL)); // random seed
srand(123457);
cout.precision(5);
cout.setf(ios::fixed,ios::floatfield);
// Toy dataset regression
generateToy(X, Y); // training set
generateToy(V, R); // validation set (acts as prepruning set)
SoftTree st = SoftTree(X, Y, V, R);
double y;
ofstream outf("out");
for(uint i=0; i<V.size(); i++) {
y = st.evaluate(V[i]);
outf << V[i][0] << " " << R[i] << " " << y << endl;
}
cout << "Number of nodes: " << st.size() << endl;
st.print();
return 0;
}