UpdateNeural(CNeuralNet neuralNet) { this.neuralNet = neuralNet; neurons.Clear(); AddLayers(); List <SNeuron> neuronsToAdd = new List <SNeuron>(); for (int i = 0; i < layers.Count; i++) { float splitY = layers.ElementAt(i).Key; Transform parentLayer = layers[splitY].transform; neuronsToAdd.Clear(); // select all neurons with the same splitY value for (int j = 0; j < neuralNet.Neurons().Count; j++) { SNeuron neuron = neuralNet.Neurons()[j]; if (neuron.splitY != splitY) { continue; } neuronsToAdd.Add(neuron); } // sort by splitX values neuronsToAdd.Sort(delegate(SNeuron a, SNeuron b) { return(a.splitX.CompareTo(b.splitX)); }); for (int j = 0; j < neuronsToAdd.Count; j++) { SNeuron neuron = neuronsToAdd[j]; if (neurons.ContainsKey(neuron.neuronID)) { Debug.LogWarning("a neuron with id " + neuron.neuronID + " already exists!"); continue; } NeuronRenderer neuronRenderer = Instantiate(neuronPrefab, parentLayer).GetComponent <NeuronRenderer>(); neuronRenderer.neuron = neuron; neurons.Add(neuron.neuronID, neuronRenderer); } } }
CreatePhenotype(int depth) { // Delete previous phenotype assigned to this genome. DeletePhenotype(); List <SNeuron> neurons = new List <SNeuron> (); // Add the neuron genes to the phenotype neurons. for (int i = 0; i < m_vecNeurons.Count; i++) { SNeuronGene neuron = m_vecNeurons[i]; neurons.Add(new SNeuron(neuron.Type, neuron.ID, neuron.SplitY, neuron.SplitX, neuron.ActivationResponse)); } // Create the links for the phenotype. for (int i = 0; i < m_vecLinks.Count; i++) { SLinkGene link = m_vecLinks[i]; // Ignore the disabled links if (link.Enabled) { SNeuron fromNeuron = neurons[GetNeuronIndexById(link.FromNeuron)]; SNeuron toNeuron = neurons[GetNeuronIndexById(link.ToNeuron)]; SLink newLink = new SLink(link.Weight, fromNeuron, toNeuron, link.IsRecurrent); fromNeuron.linksFrom.Add(newLink); toNeuron.linksTo.Add(newLink); } } m_Phenotype = new CNeuralNet(neurons, depth); return(m_Phenotype); }