コード例 #1
0
        /// <summary>
        /// Determine the winner for the specified input. This is the number of the
        /// winning neuron.
        /// </summary>
        /// <param name="input">The input pattern.</param>
        /// <returns>The winning neuron.</returns>
        public int Winner(NormalizeInput input)
        {
            int win = 0;

            double biggest = Double.MinValue;

            for (int i = 0; i < this.outputNeuronCount; i++)
            {
                Matrix.Matrix optr = this.outputWeights.GetRow(i);
                this.output[i] = MatrixMath
                                 .DotProduct(input.InputMatrix, optr)
                                 * input.Normfac;

                this.output[i] = (this.output[i] + 1.0) / 2.0;

                if (this.output[i] > biggest)
                {
                    biggest = this.output[i];
                    win     = i;
                }

                if (this.output[i] < 0)
                {
                    this.output[i] = 0;
                }

                if (this.output[i] > 1)
                {
                    this.output[i] = 1;
                }
            }

            return(win);
        }
コード例 #2
0
        /// <summary>
        /// Determine the winner for the specified input. This is the number of the
        /// winning neuron.
        /// </summary>
        /// <param name="input">The input patter to present to the neural network.</param>
        /// <returns>The winning neuron.</returns>
        public int Winner(double[] input)
        {
            NormalizeInput normalizedInput = new NormalizeInput(input,
                                                                this.normalizationType);

            return(Winner(normalizedInput));
        }
コード例 #3
0
        /// <summary>
        /// Force a win, if no neuron won.
        /// </summary>
        protected void ForceWin()
        {
            int best, which = 0;

            Matrix.Matrix outputWeights = this.som.OutputWeights;

            // Loop over all training sets.  Find the training set with
            // the least output.
            double dist = Double.MaxValue;

            for (int tset = 0; tset < this.train.Length; tset++)
            {
                best = this.som.Winner(this.train[tset]);
                double[] output = this.som.Output;

                if (output[best] < dist)
                {
                    dist  = output[best];
                    which = tset;
                }
            }

            NormalizeInput input = new NormalizeInput(this.train[which],
                                                      this.som.NormalizationType);

            best = this.som.Winner(input);
            double[] output2 = this.som.Output;

            dist = Double.MinValue;
            int i = this.outputNeuronCount;

            while ((i--) > 0)
            {
                if (this.won[i] != 0)
                {
                    continue;
                }
                if (output2[i] > dist)
                {
                    dist  = output2[i];
                    which = i;
                }
            }

            for (int j = 0; j < input.InputMatrix.Cols; j++)
            {
                outputWeights[which, j] = input.InputMatrix[0, j];
            }

            NormalizeWeight(outputWeights, which);
        }
コード例 #4
0
        /// <summary>
        /// Determine the winner for the specified input. This is the number of the
        /// winning neuron.
        /// </summary>
        /// <param name="input">The input pattern.</param>
        /// <returns>The winning neuron.</returns>
        public int Winner(NormalizeInput input)
        {
            int win = 0;

            double biggest = Double.MinValue;
            for (int i = 0; i < this.outputNeuronCount; i++)
            {
                Matrix.Matrix optr = this.outputWeights.GetRow(i);
                this.output[i] = MatrixMath
                        .DotProduct(input.InputMatrix, optr)
                        * input.Normfac;

                this.output[i] = (this.output[i] + 1.0) / 2.0;

                if (this.output[i] > biggest)
                {
                    biggest = this.output[i];
                    win = i;
                }

                if (this.output[i] < 0)
                {
                    this.output[i] = 0;
                }

                if (this.output[i] > 1)
                {
                    this.output[i] = 1;
                }
            }

            return win;
        }
コード例 #5
0
 /// <summary>
 /// Determine the winner for the specified input. This is the number of the
 /// winning neuron.
 /// </summary>
 /// <param name="input">The input patter to present to the neural network.</param>
 /// <returns>The winning neuron.</returns>
 public int Winner(double[] input)
 {
     NormalizeInput normalizedInput = new NormalizeInput(input,
            this.normalizationType);
     return Winner(normalizedInput);
 }
コード例 #6
0
        /// <summary>
        /// Force a win, if no neuron won.
        /// </summary>
        protected void ForceWin()
        {
            int best, which = 0;

            Matrix.Matrix outputWeights = this.som.OutputWeights;

            // Loop over all training sets.  Find the training set with
            // the least output.
            double dist = Double.MaxValue;
            for (int tset = 0; tset < this.train.Length; tset++)
            {
                best = this.som.Winner(this.train[tset]);
                double[] output = this.som.Output;

                if (output[best] < dist)
                {
                    dist = output[best];
                    which = tset;
                }
            }

            NormalizeInput input = new NormalizeInput(this.train[which],
                   this.som.NormalizationType);
            best = this.som.Winner(input);
            double[] output2 = this.som.Output;

            dist = Double.MinValue;
            int i = this.outputNeuronCount;
            while ((i--) > 0)
            {
                if (this.won[i] != 0)
                {
                    continue;
                }
                if (output2[i] > dist)
                {
                    dist = output2[i];
                    which = i;
                }
            }

            for (int j = 0; j < input.InputMatrix.Cols; j++)
            {
                outputWeights[which, j] =  input.InputMatrix[0, j];
            }

            NormalizeWeight(outputWeights, which);
        }
コード例 #7
0
        /// <summary>
        /// Evaludate the current error level of the network.
        /// </summary>
        public void EvaluateErrors()
        {

            this.correc.Clear();

            for (int i = 0; i < this.won.Length; i++)
            {
                this.won[i] = 0;
            }

            this.globalError = 0.0;
            // loop through all training sets to determine correction
            for (int tset = 0; tset < this.train.Length; tset++)
            {
                NormalizeInput input = new NormalizeInput(this.train[tset],
                       this.som.NormalizationType);
                int best = this.som.Winner(input);

                this.won[best]++;
                Matrix.Matrix wptr = this.som.OutputWeights.GetRow(best);

                double length = 0.0;
                double diff;

                for (int i = 0; i < this.inputNeuronCount; i++)
                {
                    diff = this.train[tset][i] * input.Normfac
                            - wptr[0, i];
                    length += diff * diff;
                    if (this.learnMethod == LearningMethod.SUBTRACTIVE)
                    {
                        this.correc.Add(best, i, diff);
                    }
                    else
                    {
                        this.work[0, i] = this.learnRate * this.train[tset][i]
                                * input.Normfac + wptr[0, i];
                    }
                }
                diff = input.Synth - wptr[0, this.inputNeuronCount];
                length += diff * diff;
                if (this.learnMethod == LearningMethod.SUBTRACTIVE)
                {
                    this.correc.Add(best, this.inputNeuronCount, diff);
                }
                else
                {
                    this.work[0, this.inputNeuronCount] =  this.learnRate
                                    * input.Synth
                                    + wptr[0, this.inputNeuronCount];
                }

                if (length > this.globalError)
                {
                    this.globalError = length;
                }

                if (this.learnMethod == LearningMethod.ADDITIVE)
                {
                    NormalizeWeight(this.work, 0);
                    for (int i = 0; i <= this.inputNeuronCount; i++)
                    {
                        this.correc.Add(best, i, this.work[0, i]
                                - wptr[0, i]);
                    }
                }

            }

            this.globalError = Math.Sqrt(this.globalError);
        }
コード例 #8
0
        /// <summary>
        /// Evaludate the current error level of the network.
        /// </summary>
        public void EvaluateErrors()
        {
            this.correc.Clear();

            for (int i = 0; i < this.won.Length; i++)
            {
                this.won[i] = 0;
            }

            this.globalError = 0.0;
            // loop through all training sets to determine correction
            for (int tset = 0; tset < this.train.Length; tset++)
            {
                NormalizeInput input = new NormalizeInput(this.train[tset],
                                                          this.som.NormalizationType);
                int best = this.som.Winner(input);

                this.won[best]++;
                Matrix.Matrix wptr = this.som.OutputWeights.GetRow(best);

                double length = 0.0;
                double diff;

                for (int i = 0; i < this.inputNeuronCount; i++)
                {
                    diff = this.train[tset][i] * input.Normfac
                           - wptr[0, i];
                    length += diff * diff;
                    if (this.learnMethod == LearningMethod.SUBTRACTIVE)
                    {
                        this.correc.Add(best, i, diff);
                    }
                    else
                    {
                        this.work[0, i] = this.learnRate * this.train[tset][i]
                                          * input.Normfac + wptr[0, i];
                    }
                }
                diff    = input.Synth - wptr[0, this.inputNeuronCount];
                length += diff * diff;
                if (this.learnMethod == LearningMethod.SUBTRACTIVE)
                {
                    this.correc.Add(best, this.inputNeuronCount, diff);
                }
                else
                {
                    this.work[0, this.inputNeuronCount] = this.learnRate
                                                          * input.Synth
                                                          + wptr[0, this.inputNeuronCount];
                }

                if (length > this.globalError)
                {
                    this.globalError = length;
                }

                if (this.learnMethod == LearningMethod.ADDITIVE)
                {
                    NormalizeWeight(this.work, 0);
                    for (int i = 0; i <= this.inputNeuronCount; i++)
                    {
                        this.correc.Add(best, i, this.work[0, i]
                                        - wptr[0, i]);
                    }
                }
            }

            this.globalError = Math.Sqrt(this.globalError);
        }