/// <inheritdoc />
        public override sealed void Iteration()
        {
            if (_mustInit)
            {
                InitWeight();
            }

            var error = new ErrorCalculation();


            foreach (IMLDataPair pair  in  _training)
            {
                IMLData xout = _network.ComputeInstar(pair.Input);

                int j = EngineArray.IndexOfLargest(xout);
                for (int i = 0; i < _network.OutstarCount; i++)
                {
                    double delta = _learningRate
                                   * (pair.Ideal[i] - _network.WeightsInstarToOutstar[j, i]);
                    _network.WeightsInstarToOutstar.Add(j, i, delta);
                }

                IMLData out2 = _network.ComputeOutstar(xout);
                error.UpdateError(out2, pair.Ideal, pair.Significance);
            }

            Error = error.Calculate();
        }
Esempio n. 2
0
        /// <summary>
        /// Determine the class using part of an array.
        /// </summary>
        ///
        /// <param name="pos">The position to begin.</param>
        /// <param name="data">The array to check.</param>
        /// <returns>The class item.</returns>
        public ClassItem DetermineClass(int pos, IMLData data)
        {
            int resultIndex = 0;
            var d           = new double[ColumnsNeeded];

            for (int i = 0; i < d.Length; i++)
            {
                d[i] = data[pos + i];
            }

            switch (_action)
            {
            case NormalizationAction.Equilateral:
                resultIndex = _eq.Decode(d);
                break;

            case NormalizationAction.OneOf:
                resultIndex = EngineArray.IndexOfLargest(d);
                break;

            case NormalizationAction.SingleField:
                resultIndex = (int)d[0];
                break;

            default:
                throw new AnalystError("Invalid action: " + _action);
            }

            if (resultIndex < 0)
            {
                return(null);
            }

            return(_classes[resultIndex]);
        }
Esempio n. 3
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(IMLData input)
        {
            IMLData output = Compute(input);
            int     win    = EngineArray.IndexOfLargest(output.Data);

            return(win);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override sealed void Iteration()
        {
            if (_mustInit)
            {
                InitWeights();
            }

            double worstDistance = Double.NegativeInfinity;


            foreach (IMLDataPair pair  in  _training)
            {
                IMLData xout = _network.ComputeInstar(pair.Input);

                // determine winner
                int winner = EngineArray.IndexOfLargest(xout);

                // calculate the distance
                double distance = 0;
                for (int i = 0; i < pair.Input.Count; i++)
                {
                    double diff = pair.Input[i]
                                  - _network.WeightsInputToInstar[i, winner];
                    distance += diff * diff;
                }
                distance = BoundMath.Sqrt(distance);

                if (distance > worstDistance)
                {
                    worstDistance = distance;
                }

                // train
                for (int j = 0; j < _network.InputCount; j++)
                {
                    double delta = _learningRate
                                   * (pair.Input[j] - _network.WeightsInputToInstar[j, winner]);

                    _network.WeightsInputToInstar.Add(j, winner, delta);
                }
            }

            Error = worstDistance;
        }
        /// <summary>
        /// Determine what class the specified data belongs to.
        /// </summary>
        ///
        /// <param name="data">The data to analyze.</param>
        /// <returns>The class the data belongs to.</returns>
        public ClassItem DetermineClass(double[] data)
        {
            int resultIndex;

            switch (_action)
            {
            case NormalizationAction.Equilateral:
                resultIndex = _eq.Decode(data);
                break;

            case NormalizationAction.OneOf:
                resultIndex = EngineArray.IndexOfLargest(data);
                break;

            case NormalizationAction.SingleField:
                resultIndex = (int)data[0];
                break;

            default:
                throw new QuantError("Unknown action: " + _action);
            }

            return(_classes[resultIndex]);
        }