#include "neurone.h"
#include "couche.h"
#include "inputCouche.h"
#include "synapse.h"
#include "synapseMatrix.h"
#include "reseau.h"
#include <iostream>
#include "inputtest.h"
//using namespace std;


void testafroche()
	{
	try {
	Neurone NewNeu();
    	Couche Output(4);
    Couche Input(3,&Output);
    Synapse s(2.324232);
    SynapseMatrix m(3,2);
    InputCouche InputC(3);
    cout << InputC ;
    cout << "get syn:" << Input.getSynapse(2,2).getWeight() << endl;
    m(1,1) = 2.5;
    cout<< "Test: " << m(1,1).getWeight() << endl;
    m.randomize();
    cout<< m ;
    //Input[4];
    Input[2]=2.132;
    Input.getSynapse(1,2).getWeight();
    cout << "Synapse weight: " << s << endl;
    }
    catch(std::string str){
        cout << "Exception: " <<endl;
        cout << "  "<< str << endl;
    }
    catch(const unsigned int index){
        cout << "Exception: " <<endl;
        cout << "  Index " << index << " is out of range" << endl;
    }
	}

void testlau()
	{
	Utils u;
	int inputsize         =                   /*16; */ 64; /* */	// nombre de neurones d'input
	int outputsize        =                   /*3; */ 3; /* */	// nombre de neurones d'output
	int nbtests           =                   /*9; */ 32; /* */	// nombre de tests (xor = 4)
	int intermid          =                   /*8; */ 8; /* */    // nombre de neurones intermediaires
	int nbtests2          =                   /*8; */ 8; /* */		// nombre de tests différents du learn
	bool Input[nbtests][inputsize];
	bool Output[nbtests][outputsize];
	bool InputTest[nbtests2][inputsize];
	
	for(int i=0;i<nbtests;i++)
		for(int j=0;j<inputsize;j++)
			Input[i][j] =             /*Inp[i][j]; /**/ VoitureI[i][j];
	for(int i=0;i<nbtests2;i++)
		for(int j=0;j<inputsize;j++)
			InputTest[i][j] =         /*Inp_[i][j]; /**/ VoitureI_[i][j];
	for(int i=0;i<nbtests;i++)
		for(int j=0;j<outputsize;j++)
			Output[i][j] =            /*Rep[i][j];/**/ VoitureR[i][j];
	
	cout << "Init Network ...." << endl;
	Reseau R(inputsize,intermid,outputsize);
	cout << "Done ...." << endl;
	
	std::vector<bool *> in;
	std::vector<bool *> r;
	
	for(int i=0;i<nbtests;i++)
		{
		in.push_back(Input[i]);
		r.push_back(Output[i]);
		}
		
	double erreur ;
	int cpt=0;
	while(1)
		{
		++cpt;
		erreur = R.learnAll(in,r);
		if(erreur < LEARNACCEPT)
			break;
		if(cpt%100 == 0)
			cout << " : step " << cpt << " error:" << erreur << endl;
		}
	cout << "final error: " << erreur << endl;
	
	
	/* et on teste */
	cout << "tests sur les jeux de données : \n";
	std::vector<double> V;
	for(int i=0;i<nbtests;i++)
		{
		V=R.forward(Input[i]);
		cout << "pour : ";
		for(int j=0;j<inputsize;j++) cout << Input[i][j] ;
		for(unsigned i=0;i<V.size();i++)
			cout << " [" << u.accept(V[i]) << "]";
		cout << " bool " ;
		for(unsigned i=0;i<V.size();i++)
			cout << " [" << V[i] << "] " ;
		cout <<  "\n";
		}
	cout << "tests différents : \n"; 
	V.clear();
	for(int i=0;i<nbtests2;i++)
		{
		V=R.forward(InputTest[i]);
		cout << "pour : ";
		for(int j=0;j<inputsize;j++) cout << InputTest[i][j];
		for(unsigned i=0;i<V.size();i++)
			cout << " [" << u.accept(V[i]) << "]";
		cout << " bool " ;
		for(unsigned i=0;i<V.size();i++)
			cout << " [" << V[i] << "] " ;
		cout <<  "\n";
		}
	
	}
	

int main(void){
  	testlau();
    return 0;
}
