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; }
static int WarmUpCicles = 25; //Aumenta de 2 em 2 => 50 #endregion Fields #region Methods static void Main(string[] args) { #region Paths DataSetPath = @"C:\Users\Edgar\Desktop\Dados\Furnas\lag2.csv"; SimulationResultPath = @"C:\Users\Edgar\Desktop\Dados\Furnas\Predicao\furnas_weight.csv"; #endregion #region Ajustando arquivo de resultados File = new System.IO.StreamWriter(SimulationResultPath, false); string info = "Seed; Hiden Nodes number; WarmUpCicles; InterConnectivity; RestricSpectralRadious; "; if (DataType == EExecutionType.Predction) info = string.Concat(info, (PerformanceInfo & EEvaluationInfo.EMQ) != EEvaluationInfo.None ? "EMQ-Train; EMQ-Val; " : string.Empty, (PerformanceInfo & EEvaluationInfo.DEV) != EEvaluationInfo.None ? "DEV-Train; DEV-Val; " : string.Empty, (PerformanceInfo & EEvaluationInfo.RMSE) != EEvaluationInfo.None ? "RMSE-Train; RMSE-Val; " : string.Empty, (PerformanceInfo & EEvaluationInfo.EPMA) != EEvaluationInfo.None ? "EPMA-Train; EPMA-Val; " : string.Empty); else if ((PerformanceInfo & EEvaluationInfo.SR) != EEvaluationInfo.None) info = string.Concat("SuccessRate-Train; SuccessRate-Val; "); info = string.Concat(info, "Time"); info = string.Concat(info, "; StopCount"); info = string.Concat(info, "; StopEvaluation"); File.WriteLine(info); File.Close(); #endregion Console.WriteLine("Processando arquivo: " + SimulationResultPath); for (int i = 1; i <= TestIterations; i++) { Console.WriteLine("Início iteração: " + i); int seed = Rand.Next(); Random _Random = new Random(seed); StartTime = DateTime.Now; DataProvider prov = new DataProvider(DataSetPath, DataType, seed, trainSize, validationSize, testSize); prov.ApplyLogToData(); prov.NormalizeData(inputA, inputB, outputA, outputB); prov.ShuffleDataSet(); prov.SplitData(); RCHS hs = new RCHS(InterConnectionsNumber, WarmUpCicles, SpectralRadious, prov, seed,MemorySize, MaxHiddenNodes, MaxEvaluations, ActivationFunction, EvaluationFunction, PerformanceInfo); HSResult<byte> returnVal = hs.Run(); int stopIteration = returnVal.StopIteration; int stopEvaluation = returnVal.StopEvaluations; RCHSParticle bestParticle = (RCHSParticle)returnVal.BestParticle; EndTime = DateTime.Now; string resultString = seed + "; " + bestParticle.Config.HidenNodesNumber + "; "+ bestParticle.Config.WarmUpCicles + "; " + bestParticle.Config.Interconnectivity.ToString("0.######") + "; " + bestParticle.Config.SpectralRadious.ToString() + "; "; if (DataType == EExecutionType.Predction) { if ((PerformanceInfo & EEvaluationInfo.EMQ) != EEvaluationInfo.None) { resultString += bestParticle.Evaluator.TrainEMQ[0].ToString("0.######") + "; "; resultString += bestParticle.Evaluator.ValidationEMQ[0].ToString("0.######") + "; "; } if ((PerformanceInfo & EEvaluationInfo.DEV) != EEvaluationInfo.None) { resultString += bestParticle.Evaluator.TrainDEV[0].ToString("0.######") + "; "; resultString += bestParticle.Evaluator.ValidationDEV[0].ToString("0.######") + "; "; } if ((PerformanceInfo & EEvaluationInfo.RMSE) != EEvaluationInfo.None) { resultString += bestParticle.Evaluator.TrainRMSE[0].ToString("0.######") + "; "; resultString += bestParticle.Evaluator.ValidationRMSE[0].ToString("0.######") + "; "; } if ((PerformanceInfo & EEvaluationInfo.EPMA) != EEvaluationInfo.None) { resultString += bestParticle.Evaluator.TrainEPMA[0].ToString("0.######") + "; "; resultString += bestParticle.Evaluator.ValidationEPMA[0].ToString("0.######") + "; "; } } else if ((PerformanceInfo & EEvaluationInfo.SR) != EEvaluationInfo.None) { resultString += bestParticle.Evaluator.TrainSR[0].ToString("0.######") + "; "; resultString += bestParticle.Evaluator.ValidationSR[0].ToString("0.######") + "; "; } resultString += EndTime.Subtract(StartTime).ToReadableString(); resultString += "; " + stopIteration; resultString += "; " + stopEvaluation; Console.WriteLine(info); Console.WriteLine(resultString); File = new System.IO.StreamWriter(SimulationResultPath, true); File.WriteLine(resultString); File.Close(); ////////////////// Salvando predição /////////////////////////////// if (SavePrediciton) { double real = 0; double prediction = 0; double Error = 0; File = new System.IO.StreamWriter(SimulationResultPath + "predicao" + i + ".csv", false); for (int m = 0; m < prov.TestSetlines; m++) { for (int j = 0; j < prov.OutputsN; j++) { real = prov.TestSet[m].RealOutput[j]; prediction = prov.DeNormalizeOutputData(bestParticle.Evaluator.RC.TestT[m][j], j); Error = real - prediction; File.WriteLine(real + ";" + prediction + ";" + Error); } } File.Close(); } ////////////////////////////////////// Console.WriteLine("Fim iteração: " + i); } Console.WriteLine("Fim simulação"); Console.ReadKey(); }
static void Main(string[] args) { string path = @"C:\Users\Edgar\Desktop\Dados\Itaipu\itaipu_serie.csv"; double alfa = 0.80; double beta = 0.20; int maxCicles = 5; int hiddenNeurons = 75; int inputLag = 48; int outputLag = 12; Console.WriteLine("Carregando dados da planilha..."); DataBuilder db = new DataBuilder(@path); db.LagData(inputLag, outputLag); Data[] set = db.BuildDataSet(); DataProvider prov = new DataProvider(set, EExecutionType.Predction, 1, trainSize, validationSize, testSize); Console.WriteLine("Aplicando tranformação logarítmica..."); prov.ApplyLogToData(); Console.WriteLine("Normalizando dados..."); prov.NormalizeData(inputA, inputB, outputA, outputB); Console.WriteLine("Embaralhando dados..."); prov.ShuffleDataSet(); Console.WriteLine("Dividindo conjuntos de dados..."); prov.SplitData(); double[][] entradasTreinamento = null; double[][] saidasTreinamento = null; double[][] entradasValidacao = null; double[][] saidasValidacao = null; double[][] entradasTeste = null; double[][] saidasTeste = null; entradasTreinamento = new double[prov.TrainSetLines][]; saidasTreinamento = new double[prov.TrainSetLines][]; for (int i = 0; i < prov.TrainSetLines; i++) { entradasTreinamento[i] = new double[prov.TrainSet[i].Input.Length]; saidasTreinamento[i] = new double[prov.TrainSet[i].Output.Length]; for (int j = 0; j < prov.TrainSet[i].Input.Length; j++) entradasTreinamento[i][j] = prov.TrainSet[i].Input[j]; for (int j = 0; j < prov.TrainSet[i].Output.Length; j++) saidasTreinamento[i][j] = prov.TrainSet[i].Output[j]; } entradasValidacao = new double[prov.ValidationSetLines][]; saidasValidacao = new double[prov.ValidationSetLines][]; for (int i = 0; i < prov.ValidationSetLines; i++) { entradasValidacao[i] = new double[prov.ValidationSet[i].Input.Length]; saidasValidacao[i] = new double[prov.ValidationSet[i].Output.Length]; for (int j = 0; j < prov.ValidationSet[i].Input.Length; j++) entradasValidacao[i][j] = prov.ValidationSet[i].Input[j]; for (int j = 0; j < prov.ValidationSet[i].Output.Length; j++) saidasValidacao[i][j] = prov.ValidationSet[i].Output[j]; } entradasTeste = new double[prov.TestSetlines][]; saidasTeste = new double[prov.TestSetlines][]; for (int i = 0; i < prov.TestSetlines; i++) { entradasTeste[i] = new double[prov.TestSet[i].Input.Length]; saidasTeste[i] = new double[prov.TestSet[i].Output.Length]; for (int j = 0; j < prov.TestSet[i].Input.Length; j++) entradasTeste[i][j] = prov.TestSet[i].Input[j]; for (int j = 0; j < prov.TestSet[i].Output.Length; j++) saidasTeste[i][j] = prov.TestSet[i].Output[j]; } Console.WriteLine("Treinando Rede neural..."); RedeMLP mlp; mlp = new RedeMLP(prov, entradasTreinamento,//array de entradas de treinamento saidasTreinamento,//array de saidas de treinamento entradasValidacao,//array de entradas de validacao saidasValidacao,//array de saidas de validacao alfa,//valor de alpha beta,//valor de beta maxCicles,//maximo de ciclos hiddenNeurons,//quatidade de neuronios escondida EnumTipoExecucao.Previsao,//booleano para definir se é previsao(true) ou classificacao(false) Algoritmos.BACKPROPAGATION,//constante q define o algoritmo a ser utilizado seed); Console.WriteLine("Testando Rede neural..."); mlp.testar(entradasTeste, saidasTeste); EMLPEvaluationInfo PerformanceInfo = EMLPEvaluationInfo.EPMA | EMLPEvaluationInfo.EMQ | EMLPEvaluationInfo.DEV | EMLPEvaluationInfo.EvaluateLikeONS; MLPEvaluator eval = new MLPEvaluator(mlp, prov, PerformanceInfo); eval.Evaluate(); Console.ReadLine(); // double[][] entradasTreinamento = null; // double[][] saidasTreinamento = null; // double[][] entradasValidacao = null; // double[][] saidasValidacao = null; // double[][] entradasTeste = null; // double[][] saidasTeste = null; // DataProvider prov = new DataProvider(@"C:\Users\Edgar\Desktop\Dados\Itaipu\lag.csv", EExecutionType.Predction, 1, 0.5, 0.25, 0.25); // prov.ApplyLogToData(); // prov.NormalizeData(inputA, inputB, outputA, outputB); // prov.ShuffleDataSet(); // prov.SplitData(); // entradasTreinamento = new double[prov.TrainSetLines][]; // saidasTreinamento = new double[prov.TrainSetLines][]; // for (int i = 0; i < prov.TrainSetLines; i++) // { // entradasTreinamento[i] = new double[prov.TrainSet[i].Input.Length]; // saidasTreinamento[i] = new double[prov.TrainSet[i].Output.Length]; // for (int j = 0; j < prov.TrainSet[i].Input.Length; j++) // entradasTreinamento[i][j] = prov.TrainSet[i].Input[j]; // for (int j = 0; j < prov.TrainSet[i].Output.Length; j++) // saidasTreinamento[i][j] = prov.TrainSet[i].Output[j]; // } // entradasValidacao = new double[prov.ValidationSetLines][]; // saidasValidacao = new double[prov.ValidationSetLines][]; // for (int i = 0; i < prov.ValidationSetLines; i++) // { // entradasValidacao[i] = new double[prov.ValidationSet[i].Input.Length]; // saidasValidacao[i] = new double[prov.ValidationSet[i].Output.Length]; // for (int j = 0; j < prov.ValidationSet[i].Input.Length; j++) // entradasValidacao[i][j] = prov.ValidationSet[i].Input[j]; // for (int j = 0; j < prov.ValidationSet[i].Output.Length; j++) // saidasValidacao[i][j] = prov.ValidationSet[i].Output[j]; // } // entradasTeste = new double[prov.TestSetlines][]; // saidasTeste = new double[prov.TestSetlines][]; // for (int i = 0; i < prov.TestSetlines; i++) // { // entradasTeste[i] = new double[prov.TestSet[i].Input.Length]; // saidasTeste[i] = new double[prov.TestSet[i].Output.Length]; // for (int j = 0; j < prov.TestSet[i].Input.Length; j++) // entradasTeste[i][j] = prov.TestSet[i].Input[j]; // for (int j = 0; j < prov.TestSet[i].Output.Length; j++) // saidasTeste[i][j] = prov.TestSet[i].Output[j]; // } // RedeMLP mlp; // mlp = new RedeMLP(entradasTreinamento,//array de entradas de treinamento // saidasTreinamento,//array de saidas de treinamento // entradasValidacao,//array de entradas de validacao // saidasValidacao,//array de saidas de validacao // 0.7,//valor de alpha // 0.4,//valor de beta // 600,//maximo de ciclos // 20,//quantidade de neuronios escondida // false,//booleano para definir se é previsao(true) ou classificacao(false) // Algoritmos.BACKPROPAGATION);//constante q define o algoritmo a ser utilizado // mlp.testar(entradasTeste, saidasTeste); // Console.WriteLine("erros: " + mlp.getErros()); // Console.ReadLine(); // //Grafico grafico = new Grafico(mlp.getErros()); // /*Teste Estatistico*/ //// int totalTestes = 30; //// for (int i = 0; i < totalTestes; i++) { //// mlp = new MLP(dados.getEntradasTreinamento().getArray(),//array de entradas de treinamento //// dados.getSaidasTreinamento().getArray(),//array de saidas de treinamento //// dados.getEntradasValidacao().getArray(),//array de entradas de validacao //// dados.getSaidasValidacao().getArray(),//array de saidas de validacao //// 0.7,//valor de alpha //// 0.4,//valor de beta //// 600,//maximo de ciclos //// 20,//quatidade de neuronios escondida //// true,//booleano para definir se é previsao(true) ou classificacao(false) //// Algoritmos.BACKPROPAGATION);//constante q define o algoritmo a ser utilizado //// mlp.testar(dados.getEntradasTeste().getArray(), dados.getSaidasTeste().getArray()); //// } // /*Fim Teste Estatistico*/ }