Ejemplo n.º 1
0
        void AddSynapse(Synapse template)
        {
            if (AllSynapses.ContainsKey(template.InnovationNo))
            {
                Debug.Log("wtf??");
                Debug.Break();
            }
            Neuron neuron1 = null, neuron2 = null;

            if (template.InputNeuron.InnovationNo <= InputLayer.Count)
            {
                neuron1 = InputLayer[template.InputNeuron.InnovationNo - 1];
            }
            else
            {
                if (HiddenLayers.ContainsKey(template.InputNeuron.InnovationNo))
                {
                    neuron1 = HiddenLayers[template.InputNeuron.InnovationNo];
                }
                else
                {
                    neuron1 = new Neuron(template.InputNeuron);
                    HiddenLayers.Add(neuron1.InnovationNo, neuron1);
                }
            }
            if (template.OutputNeuron.InnovationNo <= InputLayer.Count + OutputLayer.Count)
            {
                neuron2 = OutputLayer[template.OutputNeuron.InnovationNo - InputLayer.Count - 1];
            }
            else
            {
                if (HiddenLayers.ContainsKey(template.OutputNeuron.InnovationNo))
                {
                    neuron2 = HiddenLayers[template.OutputNeuron.InnovationNo];
                }
                else
                {
                    neuron2 = new Neuron(template.OutputNeuron);
                    HiddenLayers.Add(neuron2.InnovationNo, neuron2);
                }
            }

            Synapse newSyn = new Synapse(neuron1, neuron2, template.InnovationNo);

            newSyn.Weight = template.Weight;
            AllSynapses.Add(newSyn.InnovationNo, newSyn);
            //Debug.Log("Koniec add synapse template");
        }