コード例 #1
0
ファイル: NeuralNetExe.cs プロジェクト: DrUzair/CompoNet
        private void populateNeuralNet(ArrayList Structure, float [] Weights, float [] Biases)
        {
            //short[] neurons = structure;

            net.initNeuralNet(Structure);
            float[] w = Weights;

            // create links
            int totalLinks = 0;

            // calculate total number of links
            for (int i = 0; i < Structure.Count - 1; i++)
            {
                totalLinks += ((short[, ])(Structure[i]))[0, 0] * ((short[, ])(Structure[i + 1]))[0, 0];
            }

            // initialize WeightsCollection
            WeightsMatrix weights = new WeightsMatrix(totalLinks);

            for (int i = 0; i < totalLinks; i++)
            {
                weights.addWeight(w[i], i);
            }

            // initialize Links
            int linkcount = 0;

            for (short layerCount = 0; layerCount + 1 < Structure.Count; layerCount++)
            {
                // get adjacent layers
                NeuralNet.Layer layerOne = net.getLayer(layerCount);
                NeuralNet.Layer layerTwo = net.getLayer(layerCount + 1);

                // traverse nerons of second layer
                for (int toNeuronCount = 0; toNeuronCount < layerTwo.getNeuronCount(); toNeuronCount++)
                {
                    // traverse all neurons of first layer
                    for (int fromNeuronCount = 0; fromNeuronCount < layerOne.getNeuronCount(); fromNeuronCount++)
                    {
                        // create a link
                        NeuralNet.Link link = new NeuralNet.Link(layerOne.getNeuron(fromNeuronCount), layerTwo.getNeuron(toNeuronCount));
                        link.setWeight(weights.getWeight(linkcount++));
                    }
                }
            }

            // biases
            float[] biases = Biases;
            // initialize neurons with biases
            int count = 0;

            for (short layerCount = 1; layerCount < net.layers.Count; layerCount++)
            {
                for (int neuronCount = 0; neuronCount < net.getLayer(layerCount).getNeuronCount(); neuronCount++)
                {
                    net.getLayer(layerCount).getNeuron(neuronCount).setBias(biases[count++]);
                }
            }
        }