#include <Eigen/Dense>
#include <fstream>
#include <iostream>
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> loadFromFile(string fileName){
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix;
ifstream input(fileName.c_str(), ios::binary);
if (input){
double r, c;
input.read( reinterpret_cast<char*>( &r), sizeof(r));
input.read( reinterpret_cast<char*>( &c), sizeof(c));
matrix.resize(r,c);
for (int i=0; i<c; i++)
for (int j=0; j<r; j++)
input.read( reinterpret_cast<char*>( &matrix(j,i)), sizeof(double));
if (matrix.rows()==1)
matrix.transposeInPlace();
}
return matrix;
}
int main(
int argc,
char *argv[]){
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> weights=loadFromFile(string("testVectors/inputWeights.dat"));
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> bias=loadFromFile(string("testVectors/inputBias.dat"));
vector<NeuralLayer<double> *> networkLayers;
weights=loadFromFile(string("testVectors/hiddenWeights.dat"));
bias=loadFromFile(string("testVectors/hiddenBias.dat"));
weights=loadFromFile(string("testVectors/outputWeights.dat"));
bias=loadFromFile(string("testVectors/outputBias.dat"));
Eigen::Matrix<double, Eigen::Dynamic, 1> input(10,1);
input<<0.8333,0.8333,0.8333,0.8333,0.8333,0.6871,0.5833,0.4371,0.3333,0.4000;
Eigen::Matrix<double, Eigen::Dynamic, 1> outputExpected(9,1);
outputExpected<<0.2039,0.5875,0.2798,0.6588,0.5064,0.5675,0.3414,0.6927,0.3164;
cout<<"difference = "<<networkLayers[2]->output-outputExpected<<endl;
for (vector<
NeuralLayer<double> *>::iterator nl=networkLayers.begin(); nl!=networkLayers.end(); ++nl)
delete (*nl);
return 0;
}