public List<bool> fire(List<double> network_input)
{
// test
// si la taille de network_input n'est pas coherente == erreur
if(network_input.Count != network[0].Count)
{
Debug.Log("You may have as many inputs as the number of neuron in the first layer.");
throw new System.Exception();
}
// tout les input -1<...<1
// fait le transfert layer par layer des inputs
double control;
double threashold = 0.5; // advice = 0
bool tmp_output;
output.Clear();
//List<bool> output = new List<bool>();
for (int i = 0; i < network.Count; i++) // boucle in network
{
for (int j = 0; j < network[i].Count; j++) // boucle in each layer to set the inputs
{
if (i == 0) // First layer have to be taken differently
{
network[i][j].setInput(network_input[j], 0);
control = network[i][j].fire();
}
else
{
network[i][j].setInput(1, 0);//bias
for (int k = 0; k < network[i - 1].Count; k++) // Parse the previous layer and take outputs of neurons
{
network[i][j].setInput(network[i - 1][k].fire_val,k+1); // get the output of Neurons in layer i-1
}
control = network[i][j].fire();
if (i == network.Count - 1 && control != -1) // At the last layer, build the output
{
//toString();
//Debug.Log("control : " + control);
if (control < threashold) tmp_output = false;
else tmp_output = true;
output.Add(tmp_output);
}
}
if(control == -1) // Gestion des Exception
{
Debug.Log("one Neuron returned -1 !!");
throw new System.Exception("stop in Neural_network.fire(). got bad value");
}
}
}
return output;
}