private void ConvertEGB2CSV() { if (_cmd.Args.Count != 2) { Console.WriteLine(@"Must specify a source and target."); return; } String sourceFile = _cmd.Args[0]; String targetFile = _cmd.Args[1]; AnalystFileFormat format1 = ConvertStringConst.String2AnalystFileFormat(_cmd.PromptString("format", "decpnt|comma")); CSVFormat format = ConvertStringConst.ConvertToCSVFormat(format1); new FileInfo(targetFile).Delete(); IDataSetCODEC codec = new CSVDataCODEC(targetFile, format, false); var loader = new BinaryDataLoader(codec) { Status = new ConsoleStatusReportable() }; _sw.Start(); loader.Binary2External(sourceFile); }
private void ConvertCSV2EGB() { if (_cmd.Args.Count != 2) { Console.WriteLine(@"Must specify a source and target."); return; } String sourceFile = _cmd.Args[0]; String targetFile = _cmd.Args[1]; bool headers = _cmd.PromptBoolean("headers", true); int inputCount = _cmd.PromptInteger("inputCount", 0); int outputCount = _cmd.PromptInteger("outputCount", 0); if (inputCount == 0) { Console.WriteLine(@"Must specify an input count."); return; } AnalystFileFormat format1 = ConvertStringConst.String2AnalystFileFormat(_cmd.PromptString("format", "decpnt|comma")); CSVFormat format = ConvertStringConst.ConvertToCSVFormat(format1); new FileInfo(targetFile).Delete(); IDataSetCODEC codec = new CSVDataCODEC(sourceFile, format, headers, inputCount, outputCount, false); var loader = new BinaryDataLoader(codec) { Status = new ConsoleStatusReportable() }; _sw.Start(); loader.External2Binary(targetFile); }
/// <summary> /// Get a property as a format. /// </summary> /// <param name="name">The property name.</param> /// <returns>A format value.</returns> public CSVFormat GetPropertyCSVFormat(String name) { String v = _data[name]; AnalystFileFormat code = ConvertStringConst .String2AnalystFileFormat(v); return(ConvertStringConst.ConvertToCSVFormat(code)); }
private void EvaluateCommand() { String methodFile = _cmd.Args[0]; String trainingFile = _cmd.Args[1]; String outputFile = _cmd.Args[2]; var method = (IMLRegression)EncogDirectoryPersistence.LoadObject(new FileInfo(methodFile)); bool headers = _cmd.PromptBoolean("headers", true); AnalystFileFormat format1 = ConvertStringConst.String2AnalystFileFormat(_cmd.PromptString("format", "decpnt|comma")); CSVFormat format = ConvertStringConst.ConvertToCSVFormat(format1); var e = new EvaluateRawCSV { Report = new ConsoleStatusReportable() }; e.Analyze(method, new FileInfo(trainingFile), headers, format); e.Process(new FileInfo(outputFile), method); Console.WriteLine(@"Done evaluating file."); }
private void WizardCommand() { String targetCSVFile = _cmd.Args[0]; String egaFile = FileUtil.ForceExtension(targetCSVFile, "ega"); var analyst = new EncogAnalyst(); var wizard = new AnalystWizard(analyst); bool headers = _cmd.PromptBoolean("headers", true); AnalystFileFormat format = ConvertStringConst.String2AnalystFileFormat(_cmd.PromptString("format", "decpnt|comma")); String goal = _cmd.PromptString("goal", "c").ToLower().Trim(); if (goal.Equals("c")) { wizard.Goal = AnalystGoal.Classification; } else if (goal.Equals("r")) { wizard.Goal = AnalystGoal.Regression; } else { Console.WriteLine(@"Invalid goal: " + goal); return; } wizard.TargetFieldName = _cmd.PromptString("targetField", ""); String m = _cmd.PromptString("method", "ff").ToLower(); if (m.Equals("ff")) { wizard.MethodType = WizardMethodType.FeedForward; } else if (m.Equals("neat")) { wizard.MethodType = WizardMethodType.NEAT; } else if (m.Equals("pnn")) { wizard.MethodType = WizardMethodType.PNN; } else if (m.Equals("rbf")) { wizard.MethodType = WizardMethodType.RBF; } else if (m.Equals("som")) { wizard.MethodType = WizardMethodType.SOM; } else if (m.Equals("svm")) { wizard.MethodType = WizardMethodType.SVM; } else { Console.WriteLine(@"Invalid method: " + m); return; } String r = _cmd.PromptString("range", "-1t1").Trim().ToLower(); if (r.Equals("-1t1")) { wizard.Range = NormalizeRange.NegOne2One; } else if (r.Equals("0t1")) { wizard.Range = NormalizeRange.Zero2One; } wizard.Missing = TranslateMissing(_cmd.PromptString("missing", "DiscardMissing")); wizard.LagWindowSize = _cmd.PromptInteger("lagWindow", 0); wizard.LeadWindowSize = _cmd.PromptInteger("leadWindow", 0); wizard.IncludeTargetField = _cmd.PromptBoolean("includeTarget", false); wizard.TaskNormalize = _cmd.PromptBoolean("normalize", true); wizard.TaskRandomize = _cmd.PromptBoolean("randomize", true); wizard.TaskSegregate = _cmd.PromptBoolean("segregate", true); wizard.TaskBalance = _cmd.PromptBoolean("balance", false); wizard.TaskCluster = _cmd.PromptBoolean("cluster", false); _sw.Start(); Console.WriteLine(@"Analyzing data"); wizard.Wizard(new FileInfo(targetCSVFile), headers, format); Console.WriteLine(@"Saving analyst file"); analyst.Save(egaFile); }
/// <summary> /// Get a property as a format. /// </summary> /// <param name="name">The property name.</param> /// <returns>A format value.</returns> public AnalystFileFormat GetPropertyFormat(String name) { String v = _data[name]; return(ConvertStringConst.String2AnalystFileFormat(v)); }
/// <summary> /// Validate the specified property. /// </summary> /// <param name="theSection">The section.</param> /// <param name="subSection">The sub section.</param> /// <param name="theName">The name of the property.</param> /// <param name="v">The value of the property.</param> public void Validate(String theSection, String subSection, String theName, String v) { if (string.IsNullOrEmpty(v)) { return; } try { switch (EntryType) { case PropertyType.TypeBoolean: if ((Char.ToUpper(v[0]) != 'T') && (Char.ToUpper(v[0]) != 'F')) { var result = new StringBuilder(); result.Append("Illegal boolean for "); result.Append(DotForm(_section, subSection, _name)); result.Append(", value is "); result.Append(v); result.Append("."); throw new AnalystError(result.ToString()); } break; case PropertyType.TypeDouble: CSVFormat.EgFormat.Parse(v); break; case PropertyType.TypeFormat: if (ConvertStringConst.String2AnalystFileFormat(v) == AnalystFileFormat.Unknown) { var result = new StringBuilder(); result.Append("Invalid file format for "); result.Append(DotForm(_section, subSection, _name)); result.Append(", value is "); result.Append(v); result.Append("."); throw new AnalystError(result.ToString()); } break; case PropertyType.TypeInteger: Int32.Parse(v); break; case PropertyType.TypeListString: break; case PropertyType.TypeString: break; default: throw new AnalystError("Unsupported property type."); } } catch (FormatException) { var result = new StringBuilder(); result.Append("Illegal value for "); result.Append(DotForm(_section, subSection, _name)); result.Append(", expecting a "); result.Append(EntryType.ToString()); result.Append(", but got "); result.Append(v); result.Append("."); throw new AnalystError(result.ToString()); } }