The Encog Analyst Wizard can be used to create Encog Analyst script files from a CSV file. This class is typically used by the Encog Workbench, but it can easily be used from any program to create a starting point for an Encog Analyst Script. Several items must be provided to the wizard. Desired Machine Learning Method: This is the machine learning method that you would like the wizard to use. This might be a neural network, SVM or other supported method. Normalization Range: This is the range that the data should be normalized into. Some machine learning methods perform better with different ranges. The two ranges supported by the wizard are -1 to 1 and 0 to 1. Goal: What are we trying to accomplish. Is this a classification, regression or autoassociation problem.
        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);
        }
        public void Execute(IExampleInterface app)
        {
            if (app.Args.Length != 2)
            {
                Console.WriteLine(@"Note: This example assumes that headers are present in the CSV files.");
                Console.WriteLine(@"NormalizeFile [input file] [target file]");
            }
            else
            {
                var sourceFile = new FileInfo(app.Args[0]);
                var targetFile = new FileInfo(app.Args[1]);

                var analyst = new EncogAnalyst();
                var wizard = new AnalystWizard(analyst);
                wizard.Wizard(sourceFile, true, AnalystFileFormat.DecpntComma);

                DumpFieldInfo(analyst);

                var norm = new AnalystNormalizeCSV();
                norm.Analyze(sourceFile, true, CSVFormat.English, analyst);
                norm.ProduceOutputHeaders = true;
                norm.Normalize(targetFile);
                EncogFramework.Instance.Shutdown();
            }
        }
        public static IMLDataSet LoadAndNormalizeData(FileInfo fileInfo, AnalystGoal problemType, NormalizationAction normalizationType, bool randomize = true)
        {
            var analyst = new EncogAnalyst();
            var wizard = new AnalystWizard(analyst);
            wizard.Goal = problemType;
            wizard.Wizard(fileInfo, true, AnalystFileFormat.DecpntComma);
            var fields = analyst.Script.Normalize.NormalizedFields;

            if (problemType == AnalystGoal.Classification)
                fields[fields.Count - 1].Action = normalizationType;

            var norm = new AnalystNormalizeCSV();
            norm.Analyze(fileInfo, true, CSVFormat.DecimalPoint, analyst);

            var normalizedDataFileInfo = new FileInfo("temp/temp.csv");
            norm.Normalize(normalizedDataFileInfo);

            var inputNeurons = fields.Count - 1;
            int outputNeurons;
            if (problemType == AnalystGoal.Classification)
                outputNeurons = fields.Last().Classes.Count - (normalizationType == NormalizationAction.Equilateral ? 1 : 0);
            else
                outputNeurons = fields.Count - inputNeurons;
            var result = CSVHelper.LoadCSVToDataSet(normalizedDataFileInfo, inputNeurons, outputNeurons, randomize);
            normalizedDataFileInfo.Delete();
            return result;
        }
예제 #4
0
        private static void Normalise()
        {
            var analyst = new EncogAnalyst();
            var wizard = new AnalystWizard(analyst);

            wizard.Wizard(sourceFile, true, AnalystFileFormat.DecpntComma);

            //for numerical vals:
            analyst.Script.Normalize.NormalizedFields[0].Action = Encog.Util.Arrayutil.NormalizationAction.Normalize;

            //for enumerations:
            analyst.Script.Normalize.NormalizedFields[0].Action = Encog.Util.Arrayutil.NormalizationAction.Equilateral;
        }
        public static void Normalise(FileOps fileOps)
        {
            var analyst = new EncogAnalyst();

            var wizard = new AnalystWizard(analyst);
            wizard.Wizard(fileOps.BaseFile,true,AnalystFileFormat.DecpntComma);

            var norm = new AnalystNormalizeCSV{ProduceOutputHeaders = true};
            norm.Analyze(fileOps.TrainingFile, true, CSVFormat.English, analyst);
            norm.Normalize(fileOps.NormalisedTrainingFile);
            norm.Analyze(fileOps.EvaluationFile, true, CSVFormat.English, analyst);
            norm.Normalize(fileOps.NormalisedEvaluationFile);

            analyst.Save(fileOps.AnalystFile);
        }
예제 #6
0
        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"));
        }
예제 #7
0
        public void ForestExample(FileInfo dir)
        {
            Console.WriteLine("Starting forest cover dataset example.");
            Uri url = new Uri(FOREST_SOURCE);
            FileInfo analystFile = FileUtil.CombinePath(dir, "forest.ega");
            FileInfo rawFile = FileUtil.CombinePath(dir, "forest_raw.csv");

            EncogAnalyst encog = new EncogAnalyst();
            encog.AddAnalystListener(new ConsoleAnalystListener());
            AnalystWizard wiz = new AnalystWizard(encog);
            wiz.TaskBalance = true;

            wiz.Wizard(url, analystFile, rawFile, false, AnalystFileFormat.DecpntComma);

            encog.ExecuteTask("task-full");

            encog.Save(analystFile);

            AnalystReport report = new AnalystReport(encog);
            report.ProduceReport(FileUtil.CombinePath(dir, "report.html"));
        }
예제 #8
0
        public void IrisExample(FileInfo dir)
        {
            Console.WriteLine("Starting Iris dataset example.");
            Uri url = new Uri(IRIS_SOURCE);
            FileInfo analystFile = FileUtil.CombinePath(dir, "iris.ega");
            FileInfo rawFile = FileUtil.CombinePath(dir, "iris_raw.csv");

            EncogAnalyst encog = new EncogAnalyst();
            encog.AddAnalystListener(new ConsoleAnalystListener());
            AnalystWizard wiz = new AnalystWizard(encog);
            //wiz.TaskRandomize = false;
            wiz.Wizard(url, analystFile, rawFile, false, AnalystFileFormat.DecpntComma);
            encog.Save(analystFile);

            encog.ExecuteTask("task-full");

            

            AnalystReport report = new AnalystReport(encog);
            report.ProduceReport(FileUtil.CombinePath(dir, "report.html"));
        }
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="app">Holds arguments and other info.</param>
        public void Execute(IExampleInterface app)
        {
            Console.WriteLine("Running wizard...");
            var analyst = new EncogAnalyst();

            var wizard = new AnalystWizard(analyst);
            wizard.TargetFieldName = "field:1";
            wizard.Wizard(sourceCSV,
                false, AnalystFileFormat.DecpntComma);
            

            // customer id
            analyst.Script.Normalize.NormalizedFields[0].Action = Encog.Util.Arrayutil.NormalizationAction.PassThrough;

            var norm = new AnalystNormalizeCSV();
            norm.Report = new ConsoleStatusReportable();
            Console.WriteLine("Analyze for normalize...");
            norm.Analyze(sourceCSV, false, CSVFormat.English, analyst);
            norm.ProduceOutputHeaders = true;
            Console.WriteLine("Normalize...");
            norm.Normalize(targetCSV);
            analyst.Save(scriptEGA);
        }
        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);
        }
        /// <summary>
        /// Metodo responsavel por normalizar as informacoes para adequar a execucao da rede neural
        /// </summary>
        private static void Normalization()
        {
            var analyst = new EncogAnalyst();

            var wizard = new AnalystWizard(analyst);
            wizard.Wizard(Config.ClassificationFile, true, AnalystFileFormat.DecpntComma);

            var norm = new AnalystNormalizeCSV();
            norm.Analyze(Config.TrainingClassificationFile, true, CSVFormat.English, analyst);
            norm.ProduceOutputHeaders = true;
            norm.Normalize(Config.NormalizedTrainingClassificationFile);

            norm.Analyze(Config.EvaluateClassificationFile, true, CSVFormat.English, analyst);
            norm.Normalize(Config.NormalizedEvaluateClassificationFile);

            analyst.Save(Config.AnalystClassificationFile);
        }
예제 #12
0
        public void Analyze(TextBox txtOut)
        {
            // Use analyst
            m_analyst = new EncogAnalyst();
            var source = new FileInfo(m_fileName);
            var wizard = new AnalystWizard(m_analyst);

            wizard.Wizard(source, true, AnalystFileFormat.DecpntComma);

            // Set the minimum value for normalization
            foreach (AnalystField field in m_analyst.Script.Normalize.NormalizedFields)
                field.NormalizedLow = 0.0;

            txtOut.AppendText("Fields found in file:" + Environment.NewLine);
            foreach (AnalystField field in m_analyst.Script.Normalize.NormalizedFields)
                txtOut.AppendText(String.Format("{0}, action = {1}, min = {2}, max = {3}{4}",
                    field.Name, field.Action, field.ActualLow, field.ActualHigh, Environment.NewLine));
        }
예제 #13
0
파일: Program.cs 프로젝트: jongh0/MTree
        private static void Normalize(string sourceFile, string targetFile)
        {
            var sourceFileInfo = new FileInfo(sourceFile);
            var targetFileInfo = new FileInfo(targetFile);

            var analyst = new EncogAnalyst();
            var wizard = new AnalystWizard(analyst);
            wizard.Goal = AnalystGoal.Unknown; // Default Classification으로하면 Wizard 동작 안함
            wizard.Wizard(sourceFileInfo, true, AnalystFileFormat.DecpntComma);

            var norm = new AnalystNormalizeCSV();
            norm.Analyze(sourceFileInfo, true, CSVFormat.English, analyst);
            norm.ProduceOutputHeaders = true;
            norm.Normalize(targetFileInfo);
        }
        /// <summary>
        /// Metodo responsavel por normalizar as informacoes para adequar a execucao da rede neural
        /// </summary>
        private static void Normalization()
        {
            var analyst = new EncogAnalyst();

            //Wizard
            var wizard = new AnalystWizard(analyst);
            wizard.Wizard(Config.RegressionFile, true, AnalystFileFormat.DecpntComma);

            //Cilindros
            analyst.Script.Normalize.NormalizedFields[0].Action = Encog.Util.Arrayutil.NormalizationAction.Equilateral;
            //displacement
            analyst.Script.Normalize.NormalizedFields[1].Action = Encog.Util.Arrayutil.NormalizationAction.Normalize;
            //HorsePower
            analyst.Script.Normalize.NormalizedFields[2].Action = Encog.Util.Arrayutil.NormalizationAction.Normalize;
            //Peso
            analyst.Script.Normalize.NormalizedFields[3].Action = Encog.Util.Arrayutil.NormalizationAction.Normalize;
            //Aceleração
            analyst.Script.Normalize.NormalizedFields[4].Action = Encog.Util.Arrayutil.NormalizationAction.Normalize;
            //Ano
            analyst.Script.Normalize.NormalizedFields[5].Action = Encog.Util.Arrayutil.NormalizationAction.Equilateral;
            //Origem
            analyst.Script.Normalize.NormalizedFields[6].Action = Encog.Util.Arrayutil.NormalizationAction.Equilateral;
            //Nome
            analyst.Script.Normalize.NormalizedFields[7].Action = Encog.Util.Arrayutil.NormalizationAction.Ignore;
            //MPG
            analyst.Script.Normalize.NormalizedFields[8].Action = Encog.Util.Arrayutil.NormalizationAction.Normalize;

            var norm = new AnalystNormalizeCSV();
            norm.ProduceOutputHeaders = true;

            norm.Analyze(Config.TrainingRegressionFile, true, CSVFormat.English, analyst);
            norm.Normalize(Config.NormalizedTrainingRegressionFile);

            //Norm of evaluation
            norm.Analyze(Config.EvaluateRegressionFile, true, CSVFormat.English, analyst);
            norm.Normalize(Config.NormalizedEvaluateRegressionFile);

            //save the analyst file
            analyst.Save(Config.AnalystRegressionFile);
        }
예제 #15
0
        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.TargetField = _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);
        }