16 using namespace shark;
20 std::vector<RealVector> data(320,RealVector(16));
21 std::vector<unsigned int> label(320);
23 for(std::size_t k = 0; k != 10; ++k){
24 for(
size_t x=0; x != 16; x++) {
25 for(
size_t j=0; j != 4; j++) {
26 bool val = (x & (1<<j)) > 0;
32 for(
int i=0; i != 4; i++) {
33 subrange(data[x+k*16],i*4 ,i*4 + 4) = line;
35 for(
int i=0; i != 4; i++) {
36 for(
int l=0; l<4; l++) {
37 data[x+k*16+160](l*4 + i) = line(l);
41 label[x+k*16+160] = 0;
50 std::size_t numHidden,
51 std::size_t iterations,
52 double regularisation,
75 unsigned int numIterations = iterations;
77 optimizer.
init(estimator);
78 for(
unsigned int iteration = 0; iteration != numIterations; ++iteration) {
79 optimizer.
step(estimator);
89 std::size_t numHidden1 = 8;
90 std::size_t numHidden2 = 8;
92 double unsupRegularisation = 0.001;
93 double unsupLearningRate = 0.1;
94 std::size_t unsupIterations = 10000;
96 double regularisation = 0.0001;
97 std::size_t iterations = 200;
105 std::cout<<
"pre-training first layer"<<std::endl;
108 unsupRegularisation,unsupIterations, unsupLearningRate
116 std::cout<<
"pre-training second layer"<<std::endl;
118 intermediateData,numHidden2,
119 unsupRegularisation,unsupIterations, unsupLearningRate
128 auto network = layer1 >> layer2 >> output;
137 std::cout<<
"training supervised model"<<std::endl;
140 optimizer.
init(error);
141 for(std::size_t i = 0; i != iterations; ++i){
142 optimizer.
step(error);
150 cout <<
"classification error,train: " << loss01.
eval(data.
labels(), predictionTrain) << endl;
153 cout <<
"classification error,test: " << loss01.
eval(test.
labels(), prediction) << endl;