Exemplo n.º 1
0
//std::vector<double>
double xortest(Genome& g, Substrate& subst, Parameters& params)
{

    NeuralNetwork net;
    //g.BuildHyperNEATPhenotype(net, subst);
    g.Build_ES_Phenotype(net, subst, params);

    int depth = 5;
    double error = 0;
    std::vector<double> inputs;
    inputs.resize(3);

    net.Flush();
    inputs[0] = 1;
    inputs[1] = 0;
    inputs[2] = 1;
    net.Input(inputs);
    for(int i=0; i<depth; i++) { net.Activate(); }
    error += abs(net.Output()[0] - 1.0);

    net.Flush();
    inputs[0] = 0;
    inputs[1] = 1;
    inputs[2] = 1;
    net.Input(inputs);
    for(int i=0; i<depth; i++) { net.Activate(); }
    error += abs(net.Output()[0] - 1.0);

    net.Flush();
    inputs[0] = 0;
    inputs[1] = 0;
    inputs[2] = 1;
    net.Input(inputs);
    for(int i=0; i<depth; i++) { net.Activate(); }
    error += abs(net.Output()[0] - 0.0);

    net.Flush();
    inputs[0] = 1;
    inputs[1] = 1;
    inputs[2] = 1;
    net.Input(inputs);
    for(int i=0; i<depth; i++) { net.Activate(); }
    error += abs(net.Output()[0] - 0.0);

    //std::vector<double> f;
    //f.push_back((4.0 - error)*(4.0 - error));
    //f.push_back(g.Length);

    return (4.0 - error)*(4.0 - error);

}
Exemplo n.º 2
0
double evaluate(Genome& genome) {
	NeuralNetwork net;
    genome.BuildPhenotype(net);

    double error = 0;

    for(int i=0; i<4; i++) {
    	std::vector<double> inputs;
    	inputs.push_back((i<2) ? 1 : 0);
    	inputs.push_back((i%2==0) ? 1 : 0);
    	inputs.push_back(1);
    	double output = ((i == 1) || (i == 2)) ? 1 : 0;
        net.Flush();
        net.Input(inputs);
        for(int t=0; t<3; t++) {
        	net.Activate();
        }
        double o = net.Output()[0];
        error += fabs(output - o);
    }
    return ((4 - error) * (4 - error));
}