public void Evaluate(FileInfo networkFile, FileInfo analystFile, FileInfo EvaluationFile, FileInfo validationResultsFile)
        {
            var network = EncogDirectoryPersistence.LoadObject(networkFile) as BasicNetwork;
            var analyst = new EncogAnalyst();

            analyst.Load(analystFile);

            var evaluationSet = EncogUtility.LoadCSV2Memory(EvaluationFile.ToString(), network.InputCount,
                                                            network.OutputCount, true, CSVFormat.English, false);

            using (var file = new StreamWriter(validationResultsFile.ToString()))
            {
                foreach (var item in evaluationSet)
                {
                    var normalizedActualOutput = (BasicMLData)network.Compute(item.Input);
                    var actualOutput           = analyst.Script.Normalize.NormalizedFields[8]
                                                 .DeNormalize(normalizedActualOutput.Data[0]);
                    var idealOutput = analyst.Script.Normalize.NormalizedFields[8]
                                      .DeNormalize(item.Ideal[0]);

                    file.WriteLine($"{idealOutput}, {actualOutput}");
                    Console.WriteLine($"Ideal: {idealOutput} | Actual: {actualOutput}");
                }
            }
        }
Esempio n. 2
0
        private void AnalystCommand()
        {
            String egaFile;
            String task;

            if (_cmd.Args.Count == 0)
            {
                Console.WriteLine(@"Must specify the EGA file to run");
                return;
            }

            if (_cmd.Args.Count == 1)
            {
                egaFile = _cmd.Args[0];
                task    = "task-full";
            }
            else
            {
                egaFile = _cmd.Args[0];
                task    = _cmd.Args[1];
            }

            _sw.Start();
            var analyst = new EncogAnalyst();

            analyst.AddAnalystListener(new ConsoleAnalystListener());
            analyst.Load(new FileInfo(egaFile));
            analyst.ExecuteTask(task);
        }
Esempio n. 3
0
        static void Evaluate()
        {
            var network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(Config.TrainedNetworkFile);
            var analyst = new EncogAnalyst();

            analyst.Load(Config.AnalystFile.ToString());
            var evaluationSet = EncogUtility.LoadCSV2Memory(Config.NormalizedEvaluateFile.ToString(),
                                                            network.InputCount, network.OutputCount, true, CSVFormat.English, false);

            using (var file = new System.IO.StreamWriter(Config.ValidationResult.ToString()))
            {
                file.WriteLine("Ideal,Actual");
                foreach (var item in evaluationSet)
                {
                    // WAS 8
                    var NormalizedActualoutput = (BasicMLData)network.Compute(item.Input);
                    var Actualoutput           = analyst.Script.Normalize.NormalizedFields[8].DeNormalize(NormalizedActualoutput.Data[0]);
                    var IdealOutput            = analyst.Script.Normalize.NormalizedFields[8].DeNormalize(item.Ideal[0]);

                    //Write to File
                    var resultLine = IdealOutput.ToString() + "," + Actualoutput.ToString();
                    file.WriteLine(resultLine);
                    Console.WriteLine("Ideal : {0}, Actual : {1}", IdealOutput, Actualoutput);
                }
            }
        }
Esempio n. 4
0
        public void TestRegression()
        {
            FileInfo rawFile    = TEMP_DIR.CreateFile("EncogCSharp/Resources/simple.csv");
            FileInfo egaFile    = TEMP_DIR.CreateFile("EncogCSharp/Resources/simple.ega");
            FileInfo outputFile = TEMP_DIR.CreateFile("EncogCSharp/Resources/simple_output.csv");

            FileUtil.CopyResource("EncogCSharp/Resources/simple.csv", rawFile);
            FileUtil.CopyResource("EncogCSharp/Resources/simple-r.ega", egaFile);

            EncogAnalyst analyst = new EncogAnalyst();

            analyst.Load(egaFile);

            analyst.ExecuteTask("task-full");

            ReadCSV csv = new ReadCSV(outputFile.ToString(), true, CSVFormat.English);

            while (csv.Next())
            {
                double diff = Math.Abs(csv.GetDouble(2) - csv.GetDouble(4));
                Assert.IsTrue(diff < 1.5);
            }

            Assert.AreEqual(4, analyst.Script.Fields.Length);
            Assert.AreEqual(3, analyst.Script.Fields[3].ClassMembers.Count);

            csv.Close();
        }
Esempio n. 5
0
        public void TestClassification()
        {
            FileInfo rawFile    = TEMP_DIR.CreateFile("simple.csv");
            FileInfo egaFile    = TEMP_DIR.CreateFile("simple.ega");
            FileInfo outputFile = TEMP_DIR.CreateFile("simple_output.csv");

            FileUtil.CopyResource("simple.csv", rawFile);
            FileUtil.CopyResource("simple.ega", egaFile);

            EncogAnalyst analyst = new EncogAnalyst();

            analyst.AddAnalystListener(new ConsoleAnalystListener());
            analyst.Load(egaFile);

            analyst.ExecuteTask("task-full");

            ReadCSV csv = new ReadCSV(outputFile.ToString(), true, CSVFormat.English);

            while (csv.Next())
            {
                Assert.AreEqual(csv.Get(3), csv.Get(4));
            }

            Assert.AreEqual(4, analyst.Script.Fields.Length);
            Assert.AreEqual(3, analyst.Script.Fields[3].ClassMembers.Count);

            csv.Close();
        }
Esempio n. 6
0
        /// <see cref="INetwork.Evaluate"/>
        public INetwork Evaluate()
        {
            var network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(TrainedNetworkFile);
            var analyst = new EncogAnalyst();

            analyst.Load(AnalystFile.ToString());

            var evaluationSet = EncogUtility.LoadCSV2Memory(NormalizedEvaluateFile.ToString(),
                                                            network.InputCount, network.OutputCount, true, CSVFormat.English, false);

            int count = 0;

            using (var file = new StreamWriter(EvaluateFileOutput.ToString())) {
                file.WriteLine("Target, Predict");

                foreach (var item in evaluationSet)
                {
                    count++;

                    var output  = network.Compute(item.Input);
                    var predict = analyst.Script.Normalize.NormalizedFields[43].DeNormalize(output[0]);
                    var target  = analyst.Script.Normalize.NormalizedFields[43].DeNormalize(item.Ideal[0]);

                    PredictResult.Add(new PredictResultModel {
                        Target = target, Predict = predict
                    });

                    var resultLine = string.Format("{0},{1}", target, predict);
                    file.WriteLine(resultLine);
                }
            }

            return(this);
        }
Esempio n. 7
0
        public string Evaluate(FileInfo TrainedNetworkFile, FileInfo AnalystFile, FileInfo NormalizedEvaluateFile)
        {
            var network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(TrainedNetworkFile);
            var analyst = new EncogAnalyst();

            analyst.Load(AnalystFile.ToString());
            var evaluationSet = EncogUtility.LoadCSV2Memory(NormalizedEvaluateFile.ToString(),
                                                            network.InputCount, network.OutputCount, true, CSVFormat.English, false);
            var career = string.Empty;

            foreach (var item in evaluationSet)
            {
                var output = network.Compute(item.Input);

                int    classCount        = analyst.Script.Normalize.NormalizedFields[3].Classes.Count;
                double normalizationHigh = analyst.Script.Normalize.NormalizedFields[3].NormalizedHigh;
                double normalizationLow  = analyst.Script.Normalize.NormalizedFields[3].NormalizedLow;

                var eq = new Encog.MathUtil.Equilateral(classCount, normalizationHigh, normalizationLow);
                var predictedClassInt = eq.Decode(output);

                career = analyst.Script.Normalize.NormalizedFields[3].Classes[predictedClassInt].Name;
            }

            return(career);
        }
Esempio n. 8
0
        public void Wizard(AnalystGoal goal, WizardMethodType methodType, bool headers)
        {
            EncogAnalyst.MaxIteration = MaxIterations;
            var wiz = new AnalystWizard(EncogAnalyst)
            {
                Goal = goal, MethodType = methodType, EvidenceSegements = 3
            };

            wiz.Wizard(_rawFile, headers, FileFormat);

            EncogAnalyst.Save(_analystFile);
            EncogAnalyst.Load(_analystFile);
        }
Esempio n. 9
0
        public void Evaluate(FileInfo networkFile, FileInfo analystFile, FileInfo EvaluationFile)
        {
            var network = EncogDirectoryPersistence.LoadObject(networkFile) as BasicNetwork;
            var analyst = new EncogAnalyst();

            analyst.Load(analystFile);

            var evaluationSet = EncogUtility.LoadCSV2Memory(EvaluationFile.ToString(), network.InputCount,
                                                            network.OutputCount, true, CSVFormat.English, false);

            int count        = 0;
            int correctCount = 0;

            foreach (var item in evaluationSet)
            {
                var sepal_l = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(item.Input[0]);
                var sepal_w = analyst.Script.Normalize.NormalizedFields[1].DeNormalize(item.Input[1]);
                var petal_l = analyst.Script.Normalize.NormalizedFields[2].DeNormalize(item.Input[2]);
                var petal_w = analyst.Script.Normalize.NormalizedFields[3].DeNormalize(item.Input[3]);

                int classCount = analyst.Script.Normalize.NormalizedFields[4].Classes.Count;

                double normalizationHigh = analyst.Script.Normalize.NormalizedFields[4].NormalizedHigh;
                double normalizationLow  = analyst.Script.Normalize.NormalizedFields[4].NormalizedLow;

                var output            = network.Compute(item.Input);
                var resulter          = new Equilateral(classCount, normalizationHigh, normalizationLow);
                var predictedClassInt = resulter.Decode(output);
                var predictedClass    = analyst.Script.Normalize.NormalizedFields[4].Classes[predictedClassInt].Name;

                var idealClassInt = resulter.Decode(item.Ideal);
                var idealClass    = analyst.Script.Normalize.NormalizedFields[4].Classes[idealClassInt].Name;

                if (predictedClassInt == idealClassInt)
                {
                    ++correctCount;
                }

                Console.WriteLine($"Count: {++count} | Ideal: {idealClass} Predicted:{predictedClass}");
            }

            Console.WriteLine($"Total test count: {count}");
            Console.WriteLine($"Total correct test count: {correctCount}");
            Console.WriteLine($"% Success: {(correctCount*100.0)/count}");
        }
Esempio n. 10
0
        /// <summary>
        /// Metodo responsavel por avaliar a rede neural treinada com a massa de testes criada no metodo Segregate e normalizada no metodo Normalization
        /// </summary>
        private static void Evaluate()
        {
            var network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(Config.TrainedNetworkClassificationFile);
            var analyst = new EncogAnalyst();

            analyst.Load(Config.AnalystClassificationFile.ToString());
            var evaluationSet = EncogUtility.LoadCSV2Memory(Config.NormalizedEvaluateClassificationFile.ToString(),
                                                            network.InputCount, network.OutputCount, true, CSVFormat.English, false);

            int count        = 0;
            int CorrectCount = 0;

            foreach (var item in evaluationSet)
            {
                count++;
                var output = network.Compute(item.Input);

                var sepal_l = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(item.Input[0]);
                var sepal_w = analyst.Script.Normalize.NormalizedFields[1].DeNormalize(item.Input[1]);
                var petal_l = analyst.Script.Normalize.NormalizedFields[2].DeNormalize(item.Input[2]);
                var petal_w = analyst.Script.Normalize.NormalizedFields[3].DeNormalize(item.Input[3]);

                int    classCount        = analyst.Script.Normalize.NormalizedFields[4].Classes.Count;
                double normalizationHigh = analyst.Script.Normalize.NormalizedFields[4].NormalizedHigh;
                double normalizationLow  = analyst.Script.Normalize.NormalizedFields[4].NormalizedLow;

                var eq = new Encog.MathUtil.Equilateral(classCount, normalizationHigh, normalizationLow);
                var predictedClassInt = eq.Decode(output);
                var predictedClass    = analyst.Script.Normalize.NormalizedFields[4].Classes[predictedClassInt].Name;
                var idealClassInt     = eq.Decode(item.Ideal);
                var idealClass        = analyst.Script.Normalize.NormalizedFields[4].Classes[idealClassInt].Name;

                if (predictedClassInt == idealClassInt)
                {
                    CorrectCount++;
                }
                Console.WriteLine("Count :{0} Properties [{1},{2},{3},{4}] ,Ideal : {5} Predicted : {6} ",
                                  count, sepal_l, sepal_w, petal_l, petal_w, idealClass, predictedClass);
            }

            Console.WriteLine("Quantidade de itens: {0}", count);
            Console.WriteLine("Quantidade de acertos: {0}", CorrectCount);
            Console.WriteLine("Porcentagem de acertos: {0}", ((CorrectCount * 100.0) / count));
        }
Esempio n. 11
0
        private static void Evaluate()
        {
            var network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(Config.TrainedNetworkFile);
            var analyst = new EncogAnalyst();

            analyst.Load(Config.AnalystFile.ToString());
            var evaluationSet = EncogUtility.LoadCSV2Memory(Config.NormalizedEvaluateFile.ToString(), network.InputCount,
                                                            network.OutputCount, true, CSVFormat.English, false);

            var count        = 0;
            var correctCount = 0;

            foreach (var item in evaluationSet)
            {
                count++;
                var output             = network.Compute(item.Input);
                var analystNormalize   = analyst.Script.Normalize;
                var normalizedFields   = analystNormalize.NormalizedFields;
                var sourceElement      = normalizedFields[0].DeNormalize(item.Input[0]);
                var destinationElement = normalizedFields[1].DeNormalize(item.Input[1]);

                var classField        = normalizedFields[2];
                var classCount        = classField.Classes.Count;
                var normalizationHigh = classField.NormalizedHigh;
                var normalizationLow  = classField.NormalizedLow;

                var eq = new Encog.MathUtil.Equilateral(classCount, normalizationHigh, normalizationLow);
                var predictedClassInt = eq.Decode(output);
                var predictedClass    = classField.Classes[predictedClassInt].Name;
                var idealClassInt     = eq.Decode(output);
                var idealClass        = classField.Classes[predictedClassInt].Name;

                if (predictedClassInt == idealClassInt)
                {
                    correctCount++;
                }
                Console.WriteLine("Count :{0} Properties [{1},{2}] ,Ideal : {3} Predicted : {4}", count, sourceElement, destinationElement, idealClass, predictedClass);
            }
            Console.WriteLine("Total Test Count : {0}", count);
            Console.WriteLine("Total Correct Predicted Count  : {0}", correctCount);
            Console.WriteLine("% Success : {0}", ((correctCount * 100.0) / count));
        }
Esempio n. 12
0
        public void EvaluateNetwork(FileInfo trainedNetwork, FileInfo analystFile, FileInfo normalisedTestFile, FileInfo finalResultsFile)
        {
            try
            {
                var network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(trainedNetwork);
                var analyst = new EncogAnalyst();
                analyst.Load(analystFile.ToString());
                var evaluationSet = EncogUtility.LoadCSV2Memory(normalisedTestFile.ToString(),
                                                                network.InputCount, network.OutputCount, true, CSVFormat.English, false);

                using (var file = new StreamWriter(finalResultsFile.ToString()))
                {
                    foreach (var item in evaluationSet)
                    {
                        var normalizedActualoutput = (BasicMLData)network.Compute(item.Input);
                        //var actualoutput = analyst.Script.Normalize.NormalizedFields[11].DeNormalize(normalizedActualoutput.Data[0]);
                        //var idealOutput = analyst.Script.Normalize.NormalizedFields[11].DeNormalize(item.Ideal[0]);

                        int    classCount        = analyst.Script.Normalize.NormalizedFields[11].Classes.Count;
                        double normalizationHigh = analyst.Script.Normalize.NormalizedFields[11].NormalizedHigh;
                        double normalizationLow  = analyst.Script.Normalize.NormalizedFields[11].NormalizedLow;

                        var eq = new Encog.MathUtil.Equilateral(classCount, normalizationHigh, normalizationLow);
                        var predictedClassInt = eq.Decode(normalizedActualoutput);
                        var idealClassInt     = eq.Decode(item.Ideal);

                        //Write to File
                        var resultLine = idealClassInt.ToString() + "," + predictedClassInt.ToString();
                        file.WriteLine(resultLine);
                        Console.WriteLine("Ideal : {0}, Actual : {1}", idealClassInt, predictedClassInt);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        /// <summary> Button to test network settings. </summary>
        private void NetworkBtn_Click(object sender, EventArgs e)
        {
            //Setup paths and lists.
            string dataFile = "";
            string path     = "";

            //Normalise file.
            List <string> outputTitles = GetFile(false, ref path, ref dataFile, (int)(outputsUpDown.Value));

            if (outputTitles == null)
            {
                return;
            }

            //False when percentage split, true when cross validation.
            bool validation = !radBtnSplit.Checked;

            //Setup training dataset.
            Data info = new Data(); info = info.ReturnInfo(path + @"normal\" + dataFile.Replace(".csv", "Normal.csv"), outputTitles, sampleBar.Value, validation);

            if (info == null)
            {
                return;
            }

            //Load analyst from earlier.
            var analyst = new EncogAnalyst();

            analyst.Load(new FileInfo(path + @"normal\" + "normalizationData" + dataFile.Replace(".csv", "") + ".ega"));

            var sourcefile = new FileInfo(path + dataFile);

            var norm = new AnalystNormalizeCSV();

            norm.Analyze(sourcefile, true, CSVFormat.English, analyst);

            //Setup network.
            NeuralNetwork network;

            //If to decide which network type to use.
            if (radBtnEncog.Checked)
            {
                if (!deepNetworkBox.Checked)
                {
                    output.Text += "\n@Encog:\n\n";
                    network      = new EncogNeuralNetwork();
                }
                else
                {
                    output.Text += "\n@Deep Encog:\n\n";
                    network      = new EncogDeepNeuralNetwork();
                }
            }
            else
            {
                if (!deepNetworkBox.Checked)
                {
                    output.Text += "\n@Accord:\n\n";
                    network      = new AccordNeuralNetwork();
                }
                else
                {
                    output.Text += "\n@Deep Accord:\n\n";
                    network      = new AccordDeepNeuralNetwork();
                }
            }

            //If using cross-validation.
            if (validation)
            {
                //Setup pool size.
                decimal tmpPoolSize = info.InputData.Length * decimal.Divide(sampleBar.Value, 100);
                int     poolSize    = (int)tmpPoolSize;

                double[][] arrayIn = info.InputData; double[][] arrayOut = info.OutputData;

                info.InputData  = Data.CreateArray <double>(poolSize, info.InputData[0].Length);
                info.OutputData = Data.CreateArray <double>(poolSize, info.OutputData[0].Length);

                //Random to randomise pool selection.
                Random rnd = new Random();

                int[] index = new int[poolSize];

                //Radomly allocate items for training pool.
                for (int j = 0; j < info.InputData.Length; j++)
                {
                    index[j]          = rnd.Next(0, arrayIn.Length);
                    info.InputData[j] = arrayIn[index[j]]; info.OutputData[j] = arrayOut[index[j]];
                }

                //Remove pooled items from array.
                arrayIn  = Data.RemoveFromArray(arrayIn, index, poolSize);
                arrayOut = Data.RemoveFromArray(arrayOut, index, poolSize);

                //Start allocating sample pools.
                for (int i = 0; i <= arrayIn.Length / poolSize; i++)
                {
                    info.InputDataSample  = Data.CreateArray <double>(poolSize, arrayIn[0].Length);
                    info.OutputDataSample = Data.CreateArray <double>(poolSize, arrayOut[0].Length);

                    //Radomly allocate items for [i] sample pool.
                    for (int j = 0; j < info.InputDataSample.Length; j++)
                    {
                        index[j] = rnd.Next(0, arrayIn.Length);
                        info.InputDataSample[j] = arrayIn[index[j]]; info.OutputDataSample[j] = arrayOut[index[j]];
                    }

                    arrayIn  = Data.RemoveFromArray(arrayIn, index, poolSize);
                    arrayOut = Data.RemoveFromArray(arrayOut, index, poolSize);

                    //Create network.
                    network.Create(info.InputNumber, layersBar.Value, neuronsBar.Value, info.OutputNumber);
                    output.Text += "Training complete with an inaccuracy of: " + Math.Round(network.Train(info, (float)(learningRateBar.Value) / 10, (float)(momentumBar.Value) / 10), 10) + "\n\n";

                    double[][] answers = Data.CreateArray <double>(poolSize, info.InputData[0].Length);

                    //Compute outputs.
                    for (int j = 0; j < answers.Length; j++)
                    {
                        if (radBtnAccord.Checked)
                        {
                            if (!deepNetworkBox.Checked)
                            {
                                answers[j] = network.AccordNetwork.Compute(info.InputDataSample[j]);
                            }
                            else if (deepNetworkBox.Checked)
                            {
                                answers[j] = network.DeepAccordNetwork.Compute(info.InputDataSample[j]);
                            }
                        }
                        else
                        {
                            network.EncogNetwork.Compute(info.InputDataSample[j], answers[j]);
                        }
                    }

                    //Display network.
                    output.Text += network.Display(answers, analyst, info, outputTitles, path + @"normal\" + dataFile.Replace(".csv", "Normal.csv"));
                }
            }
            //Else percentage split.
            else
            {
                //Create network.
                network.Create(info.InputNumber, layersBar.Value, neuronsBar.Value, info.OutputNumber);
                output.Text += "Training complete with an inaccuracy of: " + Math.Round(network.Train(info, (float)(learningRateBar.Value) / 10, (float)(momentumBar.Value) / 10), 5) + "\n\n";

                double[][] answers = Data.CreateArray <double>(info.InputDataSample.Length, info.InputDataSample[0].Length);

                //Compute outputs.
                for (int i = 0; i < answers.Length; i++)
                {
                    if (radBtnAccord.Checked)
                    {
                        if (!deepNetworkBox.Checked)
                        {
                            answers[i] = network.AccordNetwork.Compute(info.InputDataSample[i]);
                        }
                        else if (deepNetworkBox.Checked)
                        {
                            answers[i] = network.DeepAccordNetwork.Compute(info.InputDataSample[i]);
                        }
                    }
                    else
                    {
                        network.EncogNetwork.Compute(info.InputDataSample[i], answers[i]);
                    }
                }

                //Display network.
                output.Text += network.Display(answers, analyst, info, outputTitles, path + @"normal\" + dataFile.Replace(".csv", "Normal.csv"));
            }
        }
        /// <summary> Button to save current network settings </summary>
        private void NetworkSaveBtn_Click(object sender, EventArgs e)
        {
            //Setup paths and lists.
            string dataFile = "";
            string path     = "";

            //Normalise file.
            List <string> outputTitles = GetFile(false, ref path, ref dataFile, (int)(outputsUpDown.Value));
            List <string> inputTitles  = new List <string>();

            if (outputTitles == null)
            {
                return;
            }

            if (nameTxt.Text?.Length == 0)
            {
                MessageBox.Show("You must give your network a name.", "No Network Name.");
                return;
            }

            char[] dirty = Path.GetInvalidFileNameChars();

            foreach (char c in dirty)
            {
                if (nameTxt.Text.Contains(c.ToString()))
                {
                    MessageBox.Show("Your name contains invalid characters. Error at character " + c, "Invalid Network Name.");
                    return;
                }
            }

            //False when percentage split, true when cross validation.
            const bool validation = true;

            //Setup dataset.
            Data info = new Data();

            info = info.ReturnInfo(path + @"normal\" + dataFile.Replace(".csv", "Normal.csv"), outputTitles, 0, validation);

            //Load analyst from earlier.
            var analyst = new EncogAnalyst();

            analyst.Load(new FileInfo(path + @"normal\" + "normalizationData" + dataFile.Replace(".csv", "") + ".ega"));

            var sourcefile = new FileInfo(path + dataFile);

            var norm = new AnalystNormalizeCSV();

            norm.Analyze(sourcefile, true, CSVFormat.English, analyst);

            //Store input headings from analyst.
            for (int i = 0; i < analyst.Script.Fields.Length - outputTitles.Count; i++)
            {
                inputTitles.Add(analyst.Script.Fields[i].Name);
            }

            //Setup network.
            NeuralNetwork network;

            //If to decide which network type to use.
            if (radBtnEncog.Checked)
            {
                if (!deepNetworkBox.Checked)
                {
                    output.Text += "\n@Encog:\n\n";
                    network      = new EncogNeuralNetwork();
                }
                else
                {
                    output.Text += "\n@Deep Encog:\n\n";
                    network      = new EncogDeepNeuralNetwork();
                }
            }
            else
            {
                if (!deepNetworkBox.Checked)
                {
                    output.Text += "\n@Accord:\n\n";
                    network      = new AccordNeuralNetwork();
                }
                else
                {
                    output.Text += "\n@Deep Accord:\n\n";
                    network      = new AccordDeepNeuralNetwork();
                }
            }

            //Create network.
            network.Create(info.InputNumber, layersBar.Value, neuronsBar.Value, info.OutputNumber);

            //Save network to file.
            if (!Directory.Exists(path + "networks"))
            {
                Directory.CreateDirectory(path + "networks");
            }

            //network.Save(path + @"networks\" + nameTxt.Text);

            if ((path + @"networks\" + nameTxt.Text)?.Length < 260)
            {
                network.Save(path + @"networks\" + nameTxt.Text);
            }
            else
            {
                MessageBox.Show("Your file name or total file path is too long for the windows limit of 260.", "Invalid Network Name Size.");
                return;
            }

            //Save network data to object.
            NetworkSaveData networkSave = new NetworkSaveData
            {
                NetworkFile    = path + @"networks\" + nameTxt.Text,
                NetworkType    = network.GetType().ToString().Replace("ENP1.", ""), //"ENP1" must change to reflect solution name (name.) if ever changed.
                AnalystFile    = path + @"normal\" + "normalizationData.ega",
                CsvFile        = dataFile,
                Path           = path,
                InputHeadings  = inputTitles,
                OutputHeadings = outputTitles,
                Name           = nameTxt.Text,

                //Train network.
                Inaccuracy = Math.Round(network.Train(info, (float)(learningRateBar.Value) / 10, (float)(momentumBar.Value) / 10), 5).ToString()
            };

            //Write network object to json file.
            using (var sw = new StreamWriter(path + @"networks\networks.json", true))
            {
                using (var jsw = new JsonTextWriter(sw))
                {
                    //jsw.Formatting = Formatting.Indented;
                    JsonSerializer serial = new JsonSerializer();
                    serial.Serialize(jsw, networkSave);
                    sw.WriteLine();
                }
            }

            output.Text += "Successfully saved network " + nameTxt.Text + " with a training inaccuracy of: " + networkSave.Inaccuracy;
        }
        /// <summary> Predict network outputs. </summary>
        private void NetworkBtn_Click(object sender, EventArgs e)
        {
            if (networkSaveDataList.Count == 0)
            {
                MessageBox.Show("You must select a network file first. If you do not have one you can create one in the network creater window", "No Network File Error");
                return;
            }

            notIncluded.Clear();

            //Setup network.
            NeuralNetwork network;

            //Switch to set network type based on type stored in json file.
            switch (networkSaveDataList[selectedNetwork].NetworkType)
            {
            case "EncogNeuralNetwork":
            {
                network = new EncogNeuralNetwork();
                break;
            }

            case "EncogDeepNeuralNetwork":
            {
                network = new EncogDeepNeuralNetwork();
                break;
            }

            case "AccordNeuralNetwork":
            {
                network = new AccordNeuralNetwork();
                break;
            }

            default:
            {
                network = new AccordDeepNeuralNetwork();
                break;
            }
            }

            //Initialize variables
            info = new Data();
            string dataFile = networkSaveDataList[selectedNetwork].CsvFile;
            string path     = networkSaveDataList[selectedNetwork].Path;

            double[][] answers;

            if (!Directory.Exists(path + "normal"))
            {
                MessageBox.Show("You have no \"normal\" folder, please ensure that you are selecting the same csv as the one used in network creation. It may also be the case that you have moved the working directory of the csv file without also moving its dependant folders.", "File Access Error");
                return;
            }

            if (!Directory.Exists(path + "networks"))
            {
                MessageBox.Show("You have no \"networks\" folder, please ensure that you have created at least one network. It may also be the case that you have moved the working directory of the csv file without also moving its dependant folders.", "File Access Error");
                return;
            }

            //Load analyst from earlier.
            analyst = new EncogAnalyst();
            analyst.Load(new FileInfo(path + @"normal\normalizationData" + dataFile.Replace(".csv", ".ega")));

            FileInfo sourcefile = new FileInfo(path + dataFile);

            AnalystNormalizeCSV norm = new AnalystNormalizeCSV();

            //norm.InputHeadings = networkSaveDataList[selectedNetwork].Headings.ToArray();
            network.Load(networkSaveDataList[selectedNetwork].NetworkFile);

            List <bool> vb = new List <bool>();

            foreach (string heading in networkSaveDataList[selectedNetwork].InputHeadings)
            {
                vb.Add(false);
            }

            notIncluded.Add(vb);

            if (!csvBox.Checked)
            {
                string outString = "";

                for (int i = 0; i < items[selectedNetwork].Count; i++)
                {
                    notIncluded[0][i] = string.IsNullOrWhiteSpace(items[selectedNetwork][i]);

                    outString += items[selectedNetwork][i] + ",";
                }

                outString += ",";

                outString.Remove(outString.Length - 1);

                if (File.Exists(path + dataFile.Replace(".csv", "Temp.csv")))
                {
                    File.Delete(path + dataFile.Replace(".csv", "Temp.csv"));
                }

                using (var sw = new StreamWriter(path + dataFile.Replace(".csv", "Temp.csv"), true))
                {
                    for (int i = 0; i < networkSaveDataList[selectedNetwork].InputHeadings.Count; i++)
                    {
                        sw.Write(networkSaveDataList[selectedNetwork].InputHeadings[i] + ",");
                    }

                    for (int i = 0; i < networkSaveDataList[selectedNetwork].OutputHeadings.Count; i++)
                    {
                        if (i != networkSaveDataList[selectedNetwork].OutputHeadings.Count - 1)
                        {
                            sw.Write(networkSaveDataList[selectedNetwork].OutputHeadings[i] + ",");
                        }
                        else
                        {
                            sw.Write(networkSaveDataList[selectedNetwork].OutputHeadings[i]);
                        }
                    }

                    sw.WriteLine();
                    sw.WriteLine(outString);
                }

                var inputFile     = new FileInfo(path + dataFile.Replace(".csv", "Temp.csv"));
                var inputFileNorm = new FileInfo(path + @"normal\" + dataFile.Replace(".csv", "TempNormal.csv"));
                norm.Analyze(inputFile, true, CSVFormat.English, analyst);

                try
                {
                    norm.Normalize(inputFileNorm);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\nThe inputs you have entered do not correctly follow the current normalisation data. This may because you " +
                                    "have entered values above or below the currently stored highs and lows for numbers. It is also possible you have " +
                                    "entered a textual word that has not been used before. Finally it is possible that you are have not used the correct " +
                                    "case for a word as they are case sensitive.", "Normalisation Failure");
                    return;
                }

                info    = info.ReturnInfo(path + @"normal\" + dataFile.Replace(".csv", "TempNormal.csv"), networkSaveDataList[selectedNetwork].OutputHeadings, 0, true);
                answers = Data.CreateArray <double>(1, info.OutputNumber);
            }
            else
            {
                //Reset paths.
                path = null; dataFile = null;

                //Get csv path.
                openFileDialog1.Filter = "csv files (*.csv)|*.csv";
                DialogResult dialogResult = openFileDialog1.ShowDialog();

                //Exit function if file selection was cancelled.
                if (dialogResult == DialogResult.Cancel)
                {
                    output.Text += "Cancelling File Selection. . .\n";
                    return;
                }

                //Check the file is .csv format.
                if (!openFileDialog1.SafeFileName.EndsWith(".csv"))
                {
                    MessageBox.Show("The file you have selected is not in the correct format (.csv)", "File Access Error");
                    return;
                }

                //Setup paths from file.
                dataFile = openFileDialog1.SafeFileName;
                path     = openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "");
                var sourceFile = new FileInfo(openFileDialog1.FileName);
                var normalFile = new FileInfo(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, @"normal\" + openFileDialog1.SafeFileName.Replace(".csv", "Normal.csv")));

                output.Text += "Loading File: " + dataFile + ". . .\n";

                Data.Normalise(sourceFile, normalFile, path, dataFile, networkSaveDataList[selectedNetwork].OutputHeadings.Count, false);

                norm.Analyze(sourceFile, true, CSVFormat.English, analyst);

                try
                {
                    norm.Normalize(normalFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\nThe inputs you have entered do not correctly follow the current normalisation data. This may because you " +
                                    "have entered values above or below the currently stored highs and lows for numbers. It is also possible you have " +
                                    "entered a textual word that has not been used before. Finally it is possible that you are have not used the correct" +
                                    "case for a word as they are case sensitive.", "Normalisation Failure");
                    return;
                }

                info = info.ReturnInfo(path + @"normal\" + dataFile.Replace(".csv", "Normal.csv"), networkSaveDataList[selectedNetwork].OutputHeadings, 0, true);

                answers = Data.CreateArray <double>(info.InputData.Length, networkSaveDataList[selectedNetwork].OutputHeadings.Count);

                //Get length of CSV, Inputs and Outputs.
                using (var reader = new StreamReader(openFileDialog1.FileName))
                {
                    reader.ReadLine();
                    int lineNo = 0;

                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(',');

                        if (lineNo > 0)
                        {
                            notIncluded.Add(new List <bool>(vb));
                        }

                        for (int i = 0; i < notIncluded[0].Count; i++)
                        {
                            notIncluded[lineNo][i] = string.IsNullOrWhiteSpace(values[i]);
                        }

                        lineNo++;
                    }
                }
            }

            //Compute network predictions.
            for (int i = 0; i < answers.Length; i++)
            {
                //Switch to set network type based on type stored in json file.
                switch (networkSaveDataList[selectedNetwork].NetworkType)
                {
                case "AccordNeuralNetwork":
                {
                    answers[i] = network.AccordNetwork.Compute(info.InputData[i]);
                    break;
                }

                case "AccordDeepNeuralNetwork":
                {
                    answers[i] = network.DeepAccordNetwork.Compute(info.InputData[i]);
                    break;
                }

                default:
                {
                    network.EncogNetwork.Compute(info.InputData[i], answers[i]);
                    break;
                }
                }
            }

            info.Prediction = answers;

            //Output answers to text box.
            output.Text += network.Display(answers, analyst, networkSaveDataList[selectedNetwork].OutputHeadings, path + @"normal\" + dataFile.Replace(".csv", "Normal.csv"));
        }