コード例 #1
0
ファイル: NeuronalNetwork.cs プロジェクト: pkupper/EvoNet
        private void DrawNeuron(SpriteBatch spriteBatch, Neuron n, float strongestConnection, Neuron mouseNeuron, Vector2?nameOffset = null, bool writeRight = false)
        {
            if (n is WorkingNeuron)
            {
                DrawConnections(spriteBatch, n, strongestConnection, mouseNeuron);
            }
            float x   = n.DrawPosition.X;
            float y   = n.DrawPosition.Y;
            Color c   = Color.Black;
            float val = n.GetValue();

            if (val < 0)
            {
                c = Color.Red;
            }
            else
            {
                c = Color.Green;
            }

            float valSize = val * NEURONSIZE;

            RenderHelper.DrawCircle(spriteBatch, x, y, NEURONSIZE / 2 + 1, Color.White);
            RenderHelper.DrawCircle(spriteBatch, x, y, valSize / 2, c);

            if (nameOffset != null)
            {
                Vector2 pos = new Vector2(x, y) + (Vector2)nameOffset;
                if (writeRight)
                {
                    pos.X -= Fonts.FontArial.MeasureString(n.GetName()).X;
                }
                spriteBatch.DrawString(Fonts.FontArial, n.GetName(), pos, Color.White);
            }
        }
コード例 #2
0
ファイル: NeuronalNetwork.cs プロジェクト: pkupper/EvoNet
        private void DrawConnections(SpriteBatch spriteBatch, Neuron n, float strongestConnection, Neuron mouseNeuron)
        {
            WorkingNeuron wn = (WorkingNeuron)n;

            foreach (Connection c in wn.GetConnections())
            {
                if (mouseNeuron != null && n != mouseNeuron && c.entryNeuron != mouseNeuron)
                {
                    continue;
                }
                Color color = Color.Black;
                float value = c.GetValue();
                float alpha = Mathf.Sqrt(Math.Abs(value) / strongestConnection);
                //TODO
                if (value > 0)
                {
                    color = new Color(0f, alpha, 0f, 1f);
                }
                else
                {
                    color = new Color(alpha, 0f, 0f, 1f);
                }
                RenderHelper.DrawLine(spriteBatch, n.DrawPosition.X, n.DrawPosition.Y, c.entryNeuron.DrawPosition.X, c.entryNeuron.DrawPosition.Y, color, 1);
            }
        }
コード例 #3
0
ファイル: NeuronalNetwork.cs プロジェクト: pkupper/EvoNet
 private void DrawLayer(SpriteBatch spriteBatch, List <Neuron> layer, float strongestConnection, Neuron mouseNeuron, Vector2?nameOffset = null, bool writeRight = false)
 {
     for (int i = 0; i < layer.Count; i++)
     {
         DrawNeuron(spriteBatch, layer[i], strongestConnection, mouseNeuron, nameOffset, writeRight);
     }
 }
コード例 #4
0
ファイル: Connection.cs プロジェクト: toffen/EvoNet
 public Connection(Neuron n, float weight)
 {
     this.weight      = weight;
     this.entryNeuron = n;
 }
コード例 #5
0
ファイル: WorkingNeuron.cs プロジェクト: pkupper/EvoNet
 public void AddNeuronConnection(Neuron n, float weight)
 {
     AddNeuronConnection(new Connection(n, weight));
 }
コード例 #6
0
        public NeuronalNetwork CloneFullMesh()
        {
            if (!fullMeshGenerated)
            {
                throw new NeuronalNetworkNotFullmeshedException();
            }
            NeuronalNetwork             copy        = new NeuronalNetwork();
            Dictionary <Neuron, Neuron> oldToNewMap = new Dictionary <Neuron, Neuron>();

            foreach (InputNeuron input in InputNeurons)
            {
                Neuron newNeuron = input.NameCopy();
                oldToNewMap.Add(input, newNeuron);

                copy.AddInputNeuron((InputNeuron)newNeuron);
            }
            for (int layerIndex = 0; layerIndex < HiddenLayerCount; layerIndex++)
            {
                List <Neuron> newLayer = new List <Neuron>();
                foreach (WorkingNeuron wn in neurons[layerIndex + 1])
                {
                    WorkingNeuron newNeuron = wn.NameCopy() as WorkingNeuron;
                    oldToNewMap.Add(wn, newNeuron);
                    newLayer.Add(newNeuron);
                    foreach (Connection con in wn.GetConnections())
                    {
                        newNeuron.AddNeuronConnection(oldToNewMap[con.entryNeuron], con.weight);
                    }
                }
                copy.AddHiddenLayer(newLayer);
            }
            foreach (Neuron output in OutputNeurons)
            {
                WorkingNeuron newNeuron = output.NameCopy() as WorkingNeuron;
                copy.AddOutputNeuron(newNeuron);
                foreach (Connection con in (output as WorkingNeuron).GetConnections())
                {
                    newNeuron.AddNeuronConnection(oldToNewMap[con.entryNeuron], con.weight);
                }
            }

            copy.fullMeshGenerated = true;

            //copy.GenerateFullMesh();

            //for (int layerIndex = 1; layerIndex < neurons.Count; layerIndex++)
            //{
            //    for (int neuronIndex = 0; neuronIndex < neurons[layerIndex].Count; neuronIndex++)
            //    {
            //        List<Connection> connectionsOriginal = ((WorkingNeuron)neurons[layerIndex][neuronIndex]).GetConnections();
            //        List<Connection> connectionsCopy = ((WorkingNeuron)copy.neurons[layerIndex][neuronIndex]).GetConnections();
            //        if (connectionsOriginal.Count != connectionsCopy.Count)
            //        {
            //            throw new NotSameAmountOfNeuronsException();
            //        }
            //        for (int k = 0; k < connectionsOriginal.Count; k++)
            //        {
            //            connectionsCopy[k].weight = connectionsOriginal[k].weight;
            //        }
            //    }
            //}

            return(copy);
        }
コード例 #7
0
 public void AddOutputNeuron(Neuron neuron)
 {
     OutputNeurons.Add(neuron);
 }