public Load ( |
||
file | The file to load. | |
return | void |
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("Encog.Resources.simple.csv", rawFile); FileUtil.CopyResource("Encog.Resources.simple-c.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(); }
/// <summary> /// Constructs a new CSVData object, needs a CSV file to open /// </summary> /// <param name="fileName">Full path to the CSV file</param> public CSVData(string fileName) { // Open file in read mode and create new stream reader object var reader = new StreamReader(File.OpenRead(fileName)); // Read each row into memory while (!reader.EndOfStream) { String line = reader.ReadLine(); // Remove double quotes line = Regex.Replace(line, "\"", ""); m_data.Add(line.Split(',').ToList()); } reader.Close(); // Count the number of input and output nodes CountNodes(); m_fileName = fileName; // Check to see if there is an analyst file FileInfo analyst = new FileInfo(String.Format("{0}.ega", fileName.Split('.')[0])); if (analyst.Exists) { m_analyst = new EncogAnalyst(); m_analyst.Load(analyst); } }
public void TestRegression() { FileInfo rawFile = TEMP_DIR.CreateFile("simple.csv"); FileInfo egaFile = TEMP_DIR.CreateFile("simple.ega"); FileInfo outputFile = TEMP_DIR.CreateFile("simple_output.csv"); FileUtil.CopyResource("Encog.Resources.simple.csv", rawFile); FileUtil.CopyResource("Encog.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(); }
public void TestWizard() { FileInfo rawFile = TEMP_DIR.CreateFile("iris_raw.csv"); FileUtil.CopyResource("Encog.Resources.iris.csv", rawFile); FileInfo analystFile = TEMP_DIR.CreateFile("iris.ega"); EncogAnalyst encog = new EncogAnalyst(); AnalystWizard wiz = new AnalystWizard(encog); wiz.Goal = AnalystGoal.Classification; wiz.Wizard(rawFile, true, AnalystFileFormat.DecpntComma); encog.ExecuteTask("task-full"); encog.Save(analystFile); encog.Load(analystFile); AnalystReport report = new AnalystReport(encog); report.ProduceReport(TEMP_DIR.CreateFile("report.html")); Assert.AreEqual(5, encog.Script.Normalize.NormalizedFields.Count); Assert.AreEqual(4.3, encog.Script.Fields[0].Min, 0.001); Assert.AreEqual(7.9, encog.Script.Fields[0].Max, 0.001); Assert.AreEqual(5.8483221477, encog.Script.Fields[0].Mean, 0.001); Assert.AreEqual(encog.Script.Fields[0].Class, false); Assert.AreEqual(encog.Script.Fields[0].Real, true); Assert.AreEqual(encog.Script.Fields[0].Integer, false); Assert.AreEqual(encog.Script.Fields[0].Complete, true); Assert.AreEqual(-3.38833, encog.Script.Normalize.NormalizedFields[0].Normalize(0.001), 0.001); }
/// <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.TrainedNetworkRegressionFile); var analyst = new EncogAnalyst(); analyst.Load(Config.AnalystRegressionFile.ToString()); var evaluationSet = EncogUtility.LoadCSV2Memory(Config.NormalizedEvaluateRegressionFile.ToString(), network.InputCount, network.OutputCount, true, CSVFormat.English, false); using (var file = new System.IO.StreamWriter(Config.ValidationRegressionResult.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]); //Write to File var resultLine = IdealOutput.ToString() + "," + Actualoutput.ToString(); file.WriteLine(resultLine); Console.WriteLine("Ideal : {0}, Actual : {1}", IdealOutput, Actualoutput); } } }
private void dataNormalization(string f1, string f2) { var sourceFile = new FileInfo(f1); var targetFile = new FileInfo(f2); var analyst = new EncogAnalyst(); var wizard = new AnalystWizard(analyst); wizard.Wizard(sourceFile, true, AnalystFileFormat.DecpntComma); var norm = new AnalystNormalizeCSV(); norm.Analyze(sourceFile, true, CSVFormat.English, analyst); norm.ProduceOutputHeaders = true; norm.Normalize(targetFile); analyst.Save(new FileInfo("stats.ega")); analyst.Load(new FileInfo("stats.ega")); }
/// <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)); }
public static void Evaluate(FileOps fileOps) { var network = (BasicNetwork) EncogDirectoryPersistence.LoadObject(fileOps.TrainedNeuralNetworkFile); var analyst = new EncogAnalyst(); analyst.Load(fileOps.AnalystFile); var evaluationSet = EncogUtility.LoadCSV2Memory(fileOps.NormalisedEvaluationFile.ToString(), network.InputCount, network.OutputCount, true, CSVFormat.English, false); var iteration = 0; var hitCount = 0; foreach (var evaluation in evaluationSet) { iteration++; var output = network.Compute(evaluation.Input); var sepalL = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(evaluation.Input[0]); var sepalW = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(evaluation.Input[1]); var petalL = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(evaluation.Input[2]); var petalW = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(evaluation.Input[3]); var classCount = analyst.Script.Normalize.NormalizedFields[4].Classes.Count; var normalisationHigh = analyst.Script.Normalize.NormalizedFields[4].NormalizedHigh; var normalisationLow = analyst.Script.Normalize.NormalizedFields[4].NormalizedLow; var eq = new Equilateral(classCount, normalisationHigh, normalisationLow); var predictedClassInt = eq.Decode(output); var predictedClass = analyst.Script.Normalize.NormalizedFields[4].Classes[predictedClassInt].Name; var idealClassInt = eq.Decode(evaluation.Ideal); var idealClass = analyst.Script.Normalize.NormalizedFields[4].Classes[idealClassInt].Name; Console.WriteLine("Predicted: {0} Ideal: {1}",predictedClass,idealClass); if (predictedClass == idealClass) { hitCount++; } } Console.WriteLine("Total Test Count:{0}",iteration); Console.WriteLine("Total Correct Predictions: {0}",hitCount); Console.WriteLine("Success rate: {0}%", (((float)hitCount/(float)iteration)*100f)); Console.ReadKey(); }
private void getLearningSet(object sender, RoutedEventArgs e) { string filename1, filename2; var analyst = new EncogAnalyst(); Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = ".csv"; dlg.Filter = "CSV Files |*.csv"; // Display OpenFileDialog by calling ShowDialog method Nullable<bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document filename1 = dlg.FileName; filename2 = System.IO.Path.ChangeExtension(filename1, "ega"); dataNormalization(filename1, filename2); analyst.Load(new FileInfo("stats.ega")); int input = analyst.DetermineUniqueInputFieldCount(); int output = analyst.DetermineUniqueOutputFieldCount(); networkGenerate(input, output); } }
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); }