示例#1
0
文件: SineWave.cs 项目: DoctorBoo/ML
        private void display()
        {
            double[] input = new double[SineWave.INPUT_SIZE];
            double[] output = new double[SineWave.OUTPUT_SIZE];

            for (int i = SineWave.INPUT_SIZE; i < SineWave.ACTUAL_SIZE; i++)
            {
                this.actual.getInputData(i - SineWave.INPUT_SIZE, input);
                this.actual.getOutputData(i - SineWave.INPUT_SIZE, output);

                StringBuilder str = new StringBuilder();
                str.Append(i);
                str.Append(":Actual=");
                for (int j = 0; j < output.Length; j++)
                {
                    if (j > 0)
                    {
                        str.Append(',');
                    }
                    str.Append(output[j]);
                }

                double[] predict = this.network.ComputeOutputs(input);

                str.Append(":Predicted=");
                for (int j = 0; j < output.Length; j++)
                {
                    if (j > 0)
                    {
                        str.Append(',');
                    }
                    str.Append(predict[j]);
                }

                str.Append(":Difference=");

                ErrorCalculation error = new ErrorCalculation();
                error.UpdateError(predict, output);
                str.Append(error.CalculateRMS().ToString("N2"));

                Console.WriteLine(str.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// Calculate the error for this neural network. The error is calculated
        /// using root-mean-square(RMS).
        /// </summary>
        /// <param name="input">Input patterns.</param>
        /// <param name="ideal">Ideal patterns.</param>
        /// <returns>The error percentage.</returns>
        public double CalculateError(double[][] input, double[][] ideal)
        {
            ErrorCalculation errorCalculation = new ErrorCalculation();

            for (int i = 0; i < ideal.Length; i++)
            {
                ComputeOutputs(input[i]);
                errorCalculation.UpdateError(this.outputLayer.Fire,
                        ideal[i]);
            }
            return (errorCalculation.CalculateRMS());
        }
        public void display()
        {


            double[] present = new double[INPUT_SIZE * 2];
            double[] predict = new double[OUTPUT_SIZE];
            double[] actualOutput = new double[OUTPUT_SIZE];

            int index = 0;
            foreach (FinancialSample sample in this.actual.getSamples())
            {
                if (sample.getDate().CompareTo(this.PREDICT_FROM) > 0)
                {
                    StringBuilder str = new StringBuilder();
                    str.Append(ReadCSV.DisplayDate(sample.getDate()));
                    str.Append(":Start=");
                    str.Append(sample.getAmount());

                    this.actual.getInputData(index - INPUT_SIZE, present);
                    this.actual.getOutputData(index - INPUT_SIZE, actualOutput);

                    predict = this.network.ComputeOutputs(present);
                    str.Append(",Actual % Change=");
                    str.Append(actualOutput[0].ToString("N2"));
                    str.Append(",Predicted % Change= ");
                    str.Append(predict[0].ToString("N2"));

                    str.Append(":Difference=");

                    ErrorCalculation error = new ErrorCalculation();
                    error.UpdateError(predict, actualOutput);
                    str.Append(error.CalculateRMS().ToString("N2"));

                    // 

                    Console.WriteLine(str.ToString());
                }

                index++;
            }
        }