Example #1
0
        public Data Clone()
        {
            Data d = new Data(this.RealInput.Clone() as double[], this.RealOutput.Clone() as double[]);

            d.Input = this.Input.Clone() as double[];
            d.Output = this.Output.Clone() as double[];

            return d;
        }
 public RCRunnableConfiguration(double[][] w, double[][] B, double[][] I, double[] H0, Data[] dataSet,
     int hidenNodesNumber, ERCActivationFunctionType activationFunctionType)
     : base(hidenNodesNumber, activationFunctionType)
 {
     this.w = w;
     this.B = B;
     this.I = I;
     this.H0 = H0;
     DataSet = dataSet;
 }
Example #3
0
        public DataProvider(Data[] dataSet, EExecutionType executionType, int seed, double trainSize, double validationSize, double testSize)
        {
            _Random = new Random(seed);
            ExecutionType = executionType;
            DataSet = dataSet;
            DataSetLines = dataSet.Length;
            DataSetColumns = dataSet[0].Input.Length + dataSet[0].Output.Length;
            InputsN = dataSet[0].Input.Length;
            OutputsN = dataSet[0].Output.Length;

            MinValue = new double[DataSetColumns];
            MaxValue = new double[DataSetColumns];

            _TrainSize = trainSize;
            _ValidationSize = validationSize;
            _TestSize = testSize;

            if ((_TrainSize + _ValidationSize + _TestSize) != 1)
                throw new ArgumentException("A soma do percentual de particionamento dos dados deve ser 100%");
        }
Example #4
0
        private double[] _GenerateSR(int N, int m, Data[] dataSet, double[][] predictionOutput)
        {
            double[] successCount = new double[m];
            double[] sr = new double[m];

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (dataSet[i].RealOutput[j] == Math.Round(_Prov.DeNormalizeOutputData(predictionOutput[i][j],j)))
                        successCount[j]++;
                }
            }

            for (int i = 0; i < m; i++)
                sr[i] = successCount[i] * 100 / N;

            return sr;
        }
Example #5
0
        private double[] _GenerateEPMAForPowerPlant(int N, int m, Data[] dataSet, double[][] predicitionOutput, double powerPlantPotency)
        {
            double[] EPMA = new double[m];
            double Error = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Error =  _Prov.DeNormalizeOutputData(predicitionOutput[i][j], j) - dataSet[i].RealOutput[j];

                    EPMA[j] += Math.Abs(Error / powerPlantPotency);
                }
            }

            for(int i = 0 ; i < m; i++)
                EPMA[i] = EPMA[i] / N * 100;

            return EPMA;
        }
Example #6
0
        private double[] _GenerateEPMA(int N, int m, Data[] dataSet, double[][] predictionOutput, bool evaluateLikeONS)
        {
            int epmaLength = evaluateLikeONS ? 7 : m;
            double[] EPMA = new double[epmaLength];
            double error = 0;
            double divisor = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = evaluateLikeONS ? 3 : 0, k = 0; j < (evaluateLikeONS ? 10 : m); j++, k++)
                {
                    if(_KeepDataNormalized)
                        error = predictionOutput[i][j] - dataSet[i].Output[j];
                    else
                        error = _Prov.DeNormalizeOutputData(predictionOutput[i][j], j) - dataSet[i].RealOutput[j];

                    if(_KeepDataNormalized)
                        divisor = dataSet[i].Output[j] == 0 ? Double.Epsilon : dataSet[i].Output[j];
                    else
                        divisor = dataSet[i].RealOutput[j] == 0 ? Double.Epsilon : dataSet[i].RealOutput[j];

                    EPMA[k] += Math.Abs(error / divisor);
                }
            }

            for (int i = 0; i < epmaLength; i++)
                EPMA[i] = EPMA[i] / N * 100;

            return EPMA;
        }
Example #7
0
        private double[] _GenerateEMQ(int N, int m, Data[] dataSet, double[][] predictionOutput)
        {
            double[] EMQ = new double[m];
            double error = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if(_KeepDataNormalized)
                        error = dataSet[i].Output[j] - predictionOutput[i][j];
                    else
                        error = dataSet[i].RealOutput[j] - _Prov.DeNormalizeOutputData(predictionOutput[i][j], j);

                    EMQ[j] += Math.Pow(error, 2);
                    error = 0;
                }
            }

            for (int i = 0; i < m; i++)
                EMQ[i] = EMQ[i] / N;

            return EMQ;
        }
Example #8
0
        private double[] _GenerateDEV(int N, int m, Data[] dataSet, double[][] predictionOutput)
        {
            double[] Mean = new double[m];
            double[] DEV = new double[m];
            double error = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if(_KeepDataNormalized)
                        error = dataSet[i].Output[j] - predictionOutput[i][j];
                    else
                        error = dataSet[i].RealOutput[j] - _Prov.DeNormalizeOutputData(predictionOutput[i][j], j);

                    Mean[j] += error;

                    error = 0;
                }
            }

            for (int i = 0; i < m; i++)
                Mean[i] = Mean[i] / N;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (_KeepDataNormalized)
                        error = dataSet[i].Output[j] - predictionOutput[i][j];
                    else
                        error = dataSet[i].RealOutput[j] - _Prov.DeNormalizeOutputData(predictionOutput[i][j], j);

                    DEV[j] += Math.Pow(error - Mean[j], 2);

                    error = 0;
                }
            }

            for (int i = 0; i < m; i++)
                DEV[i] = DEV[i] / (N - 1);

            return DEV;
        }
Example #9
0
        private void _ReadDataSetFromFile(String filePath)
        {
            String line = null;
            using (StreamReader reader = new StreamReader(filePath))
            {
                line = reader.ReadLine();
                DataSetLines = int.Parse(line); // número de exemplos

                line = reader.ReadLine();
                DataSetColumns = int.Parse(line); // representa o número de entradas + número de saidas

                line = reader.ReadLine();
                InputsN = int.Parse(line);; // número de entradas da rede

                line = reader.ReadLine();
                OutputsN = int.Parse(line);; // número de saídas da rede

                DataSet = new Data[DataSetLines];

                for(int i = 0; i < DataSetLines; i++)
                {
                    line = reader.ReadLine();

                    String[] values = line.Split(';');

                    DataSet[i] = new Data(new double[InputsN], new double[OutputsN]);

                    for (int j = 0; j < values.Length; j++)
                    {
                        double val = double.Parse(values[j]);

                        if (double.IsNaN(val))
                            throw new Exception();

                        if (j >= InputsN)
                        {
                            DataSet[i].RealOutput[j - InputsN] = val;
                            DataSet[i].Output[j - InputsN] = val;
                        }
                        else
                        {
                            DataSet[i].RealInput[j] = val;
                            DataSet[i].Input[j] = val;
                        }
                    }
                }
            }
        }
Example #10
0
        public DataProvider ShrinkProvider(int inputs)
        {
            DataProvider shrinkProv = null;

            if (inputs < InputsN)
            {
                Data[] set = new Data[DataSetLines];

                for (int i = 0; i < DataSetLines; i++)
                {
                    set[i] = new Data(new double[inputs], DataSet[i].RealOutput.Clone() as double[]);

                    for (int j = inputs - 1, k = InputsN - 1; j >= 0; j--, k--)
                    {
                        set[i].RealInput[j] = DataSet[i].RealInput[k];
                    }
                }

                shrinkProv = new DataProvider(set, ExecutionType, _Random.Next(), _TrainSize, _ValidationSize, _TestSize);

                if (_LogAppliedToData)
                    shrinkProv.ApplyLogToData();

                if (_DataNormalized)
                    shrinkProv.NormalizeData(_InputBoundA, _InputBoundB, _OutputBoundA, _OutputBoundB);

                shrinkProv.ShuffleDataSet();
                shrinkProv.SplitData();
            }
            else if (inputs == InputsN)
                shrinkProv = this;
            else
                throw new ArgumentOutOfRangeException();

            return shrinkProv;
        }