public static void SetNeuralNetwork(Organism organism) { organism.neuralNetwork = new NeuralNetwork(); List <Neuron> outputNeurons = new List <Neuron>(); List <Neuron> inputNeurons = new List <Neuron>(); organism.bias = new Neuron(Organism.GetInputOrganismNeuronsNumbers()[0]); organism.bias.Value = 1; organism.damageNeuron = new Neuron(Organism.GetInputOrganismNeuronsNumbers()[1]); organism.energyNeuron = new Neuron(Organism.GetInputOrganismNeuronsNumbers()[2]); organism.mitosisNeuron = new Neuron(Organism.GetOutputOrganismNeuronsNumbers()[0]); organism.sexualReproductionNeuron = new Neuron(Organism.GetOutputOrganismNeuronsNumbers()[1]); inputNeurons.Add(organism.bias); inputNeurons.Add(organism.damageNeuron); inputNeurons.Add(organism.energyNeuron); outputNeurons.Add(organism.mitosisNeuron); outputNeurons.Add(organism.sexualReproductionNeuron); foreach (var pair in organism.orderOfGrowth) { CellAttributes cell = pair.Value; cell.inputNeurons = Organism.CreateNeuronsFromNumbers(cell.type.GetComponent <Cell>().GetInputNeuronsNumbers(cell.number)); cell.outputNeurons = Organism.CreateNeuronsFromNumbers(cell.type.GetComponent <Cell>().GetOutputNeuronsNumbers(cell.number)); inputNeurons.AddRange(cell.inputNeurons); outputNeurons.AddRange(cell.outputNeurons); } organism.neuralNetwork.BuildFromChromosome(organism.chromosome.neuralChromosome, inputNeurons.ToArray(), outputNeurons.ToArray()); }
private static HashSet <int> OutputNeuronsNumbers(Chromosome chromosome) { HashSet <int> numbers = new HashSet <int>(); foreach (Gene gene in chromosome.Genes) { numbers.UnionWith(gene.Type.GetComponent <Cell>().GetOutputNeuronsNumbers(gene.Number)); } numbers.UnionWith(Organism.GetOutputOrganismNeuronsNumbers()); return(numbers); }