示例#1
0
        /// <summary>
        /// Initialises a new fully connected feedforward neural network with given topology.
        /// </summary>
        /// <param name="topology">An array of unsigned integers representing the node count of each layer from input to output layer.</param>
        public NeuralNetwork(params uint[] topology)
        {
            this.Topology = topology;

            //Calculate overall weight count
            WeightCount = 0;
            for (int i = 0; i < topology.Length - 1; i++)
            {
                WeightCount += (int)((topology[i] + 1) * topology[i + 1]); // + 1 for bias node
            }
            UnityEngine.Debug.Log("weight count = " + WeightCount);

            //Initialise layers
            Layers = new NeuralLayer[topology.Length - 1];
            for (int i = 0; i < Layers.Length; i++)
            {
                Layers[i] = new NeuralLayer(topology[i], topology[i + 1]);
            }
        }
示例#2
0
        /// <summary>
        /// Copies this NeuralLayer including its weights.
        /// </summary>
        /// <returns>A deep copy of this NeuralLayer</returns>
        public NeuralLayer DeepCopy()
        {
            //Copy weights
            double[,] copiedWeights = new double[this.Weights.GetLength(0), this.Weights.GetLength(1)];

            for (int x = 0; x < this.Weights.GetLength(0); x++)
            {
                for (int y = 0; y < this.Weights.GetLength(1); y++)
                {
                    copiedWeights[x, y] = this.Weights[x, y];
                }
            }

            //Create copy
            NeuralLayer newLayer = new NeuralLayer(this.NeuronCount, this.OutputCount);

            newLayer.Weights = copiedWeights;
            newLayer.NeuronActivationFunction = this.NeuronActivationFunction;

            return(newLayer);
        }