Exemple #1
0
 public void createNetwork()
 {
     ActivationFunction threshold = new ActivationTANH();
     this.network = new FeedforwardNetwork();
     this.network.AddLayer(new FeedforwardLayer(threshold, PredictWeather.INPUT_SIZE * 4));
     this.network.AddLayer(new FeedforwardLayer(threshold, PredictWeather.NEURONS_HIDDEN_1));
     if (PredictWeather.NEURONS_HIDDEN_2 > 0)
     {
         this.network.AddLayer(new FeedforwardLayer(threshold, PredictWeather.NEURONS_HIDDEN_2));
     }
     this.network.AddLayer(new FeedforwardLayer(threshold, PredictWeather.OUTPUT_SIZE*3));
     this.network.Reset();
 }
Exemple #2
0
        /// <summary>
        /// Convert from an array.  Use an array to populate the memory of the neural network.
        /// </summary>
        /// <param name="array">An array that will hold the memory of the neural network.</param>
        /// <param name="network">A neural network to convert to an array.</param>
        public static void ArrayToNetwork(Double[] array,
                FeedforwardNetwork network)
        {
            // copy data to array
            int index = 0;

            foreach (FeedforwardLayer layer in network.Layers)
            {

                // now the weight matrix(if it exists)
                if (layer.Next != null)
                {
                    index = layer.LayerMatrix.FromPackedArray(array, index);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Convert to an array. This is used with some training algorithms that
        /// require that the "memory" of the neuron(the weight and threshold values)
        /// be expressed as a linear array.
        /// </summary>
        /// <param name="network">A neural network.</param>
        /// <returns>The memory of the neural network as an array.</returns>
        public static double[] NetworkToArray(FeedforwardNetwork network)
        {
            int size = 0;

            // first determine size
            foreach (FeedforwardLayer layer in network.Layers)
            {
                // count the size of the weight matrix
                if (layer.HasMatrix())
                {
                    size += layer.MatrixSize;
                }
            }

            // allocate an array to hold
            Double[] result = new Double[size];

            // copy data to array
            int index = 0;

            foreach (FeedforwardLayer layer in network.Layers)
            {

                // now the weight matrix(if it exists)
                if (layer.Next != null)
                {

                    Double[] matrix = layer.LayerMatrix.ToPackedArray();
                    for (int i = 0; i < matrix.Length; i++)
                    {
                        result[index++] = matrix[i];
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Compare the two neural networks. For them to be equal they must be of the
        /// same structure, and have the same matrix values.
        /// </summary>
        /// <param name="other">The other neural network.</param>
        /// <returns>True if the two networks are equal.</returns>
        public bool Equals(FeedforwardNetwork other)
        {
            int i = 0;

            foreach (FeedforwardLayer layer in this.Layers)
            {
                FeedforwardLayer otherLayer = other.Layers[i++];

                if (layer.NeuronCount != otherLayer.NeuronCount)
                {
                    return false;
                }

                // make sure they either both have or do not have
                // a weight matrix.
                if ((layer.LayerMatrix == null) && (otherLayer.LayerMatrix != null))
                {
                    return false;
                }

                if ((layer.LayerMatrix != null) && (otherLayer.LayerMatrix == null))
                {
                    return false;
                }

                // if they both have a matrix, then compare the matrices
                if ((layer.LayerMatrix != null) && (otherLayer.LayerMatrix != null))
                {
                    if (!layer.LayerMatrix.Equals(otherLayer.LayerMatrix))
                    {
                        return false;
                    }
                }
            }

            return true;
        }
        /// <summary>
        /// Return a clone of the structure of this neural network. 
        /// </summary>
        /// <returns>A cloned copy of the structure of the neural network.</returns>
        public FeedforwardNetwork CloneStructure()
        {
            FeedforwardNetwork result = new FeedforwardNetwork();

            foreach (FeedforwardLayer layer in this.layers)
            {
                FeedforwardLayer clonedLayer = new FeedforwardLayer(layer.NeuronCount);
                result.AddLayer(clonedLayer);
            }

            return result;
        }
Exemple #6
0
 public void loadNeuralNetwork(string station)
 {
     this.network = (FeedforwardNetwork)SerializeObject.Load(station+"_weather.net");
 }