17 using namespace shark;
21 std::vector<RealVector> data(320,RealVector(16));
22 std::vector<unsigned int> label(320);
24 for(std::size_t k = 0; k != 10; ++k){
25 for(
size_t x=0; x != 16; x++) {
26 for(
size_t j=0; j != 4; j++) {
27 bool val = (x & (1<<j)) > 0;
33 for(
int i=0; i != 4; i++) {
34 subrange(data[x+k*16],i*4 ,i*4 + 4) = line;
36 for(
int i=0; i != 4; i++) {
37 for(
int l=0; l<4; l++) {
38 data[x+k*16+160](l*4 + i) = line(l);
42 label[x+k*16+160] = 0;
49 template<
class AutoencoderModel>
52 std::size_t numHidden,
53 double regularisation,
55 std::size_t iterations
61 initRandomUniform(baseModel,-0.1*std::sqrt(1.0/inputs),0.1*std::sqrt(1.0/inputs));
72 optimizer.
init(error);
73 std::cout<<
"Optimizing model: "+model.
name()<<std::endl;
74 for(std::size_t i = 0; i != iterations; ++i){
75 optimizer.
step(error);
88 std::size_t numHidden1,std::size_t numHidden2, std::size_t numOutputs,
89 double regularisation,
double noiseStrength, std::size_t iterations
92 std::cout<<
"training first layer"<<std::endl;
95 regularisation, noiseStrength,
102 std::cout<<
"training second layer"<<std::endl;
104 intermediateData,numHidden2,
105 regularisation, noiseStrength,
121 std::size_t numHidden1 = 8;
122 std::size_t numHidden2 = 8;
124 double unsupRegularisation = 0.001;
125 double noiseStrength = 0.3;
126 std::size_t unsupIterations = 100;
128 double regularisation = 0.0001;
129 std::size_t iterations = 200;
139 unsupRegularisation, noiseStrength, unsupIterations
149 std::cout<<
"training supervised model"<<std::endl;
151 optimizer.
init(error);
152 for(std::size_t i = 0; i != iterations; ++i){
153 optimizer.
step(error);
161 cout <<
"classification error,train: " << loss01.
eval(data.
labels(), predictionTrain) << endl;
164 cout <<
"classification error,test: " << loss01.
eval(test.
labels(), prediction) << endl;