Esempio n. 1
0
        public static Connection Create(double weight, Node fromNode, Node toNode)
        {
            var con = new Connection(weight, fromNode, toNode);

            fromNode.AddOutgoingConnection(con);
            toNode.AddIncommingConnection(con);

            return con;
        }
Esempio n. 2
0
        public void FillNetwork(int nrInputs, int nrOutputs, params int[] hiddenLayerHeights)
        {
            //Creation of outputs is similar to creating hidden layers
            var nonInputLayers = hiddenLayerHeights.ToList();
            nonInputLayers.Add(nrOutputs);

            //Init array
            Nodes = new Node[nonInputLayers.Count + 1][];

            //Inputs
            Nodes[0] = CreateInputs(nrInputs).ToArray();

            //Hidden & out
            for(int layerIndex = 1; layerIndex <= nonInputLayers.Count; layerIndex++) {
                int height = nonInputLayers[layerIndex - 1];

                var curLayer = new List<Perceptron>(height);
                for(int percNr = 0; percNr < height; percNr++) {
                    //Create perceptron
                    string name = layerIndex == Nodes.Length - 1 ? $"Output {percNr}" : $"Hidden #{layerIndex - 1}.{percNr}";
                    var newPerceptron = new Perceptron(TransferFunction, name);

                    //Create input connections
                    foreach(var inp in Nodes[layerIndex - 1]) {
                        double weight = 0;
                        if(layerIndex - 1 == 0) { //Input --> 1st hidden
                            weight = MathHelper.GuassianRandom(Math.Sqrt(1.0 / 3.0), 0);
                        }
                        Connection.Create(weight, inp, newPerceptron);
                    }

                    if(Bias != null) {
                        Connection.Create(0.5, Bias, newPerceptron);
                    }

                    curLayer.Add(newPerceptron);
                }
                Nodes[layerIndex] = curLayer.ToArray();
            }
        }
Esempio n. 3
0
 private Connection(double weight, Node fromNode, Node toNode)
 {
     Weight = weight;
     FromNode = fromNode;
     ToNode = toNode;
 }