Exemplo n.º 1
0
        public NeuralNetwork(int inputNum, int outputNum, int hiddenNum, int layerNum)
        {
            rand = new Random();

            connections = new List<Connection>();
            hiddenLayers = new Node[layerNum][];
            outputNodes = new Node[outputNum];
            inputNodes = new Node[inputNum];

            for (int i = 0; i < inputNum; i++)
            {
                inputNodes[i] = new Node(RandStart());
            }

            for (int i = 0; i < outputNum; i++)
            {
                outputNodes[i] = new Node(RandStart());
            }
            for (int i = 0; i < layerNum; i++)
            {
                hiddenLayers[i] = new Node[hiddenNum];
                for (int j = 0; j < hiddenNum; j++)
                {
                    Node curNode = new Node(RandStart());
                    hiddenLayers[i][j] = curNode;

                    //hook up connection
                    if (i == 0) //input layer to first hiddden layer
                    {
                        for (int k = 0; k < inputNum; k++)
                        {
                            connections.Add(new Connection(RandStart(), inputNodes[k], curNode));

                        }
                    }
                    else //hidden layer to hidden layer
                    {
                        for (int k = 0; k < hiddenNum; k++)
                        {
                            connections.Add(new Connection(RandStart(), hiddenLayers[i - 1][k], curNode));

                        }
                    }

                    //last hidden layer to output layer
                    if (i == layerNum - 1)
                    {
                        for (int k = 0; k < outputNum; k++)
                        {
                            connections.Add(new Connection(RandStart(), curNode, outputNodes[k]));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void NodeToBuilder(Node node, StringBuilder strB)
 {
     strB.AppendFormat("{0}: bias={1}\n",node.GetHashCode(), node.Bias);
     foreach (Connection conn in node.OutCon)
     {
         strB.AppendFormat("\t-> {0} = {1}\n", conn.To.GetHashCode(), conn.Weight);
     }
 }