コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        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.");
        }
コード例 #5
0
        /// <summary>
        ///     Perform the analysis.
        /// </summary>
        /// <param name="target">The Encog analyst object to analyze.</param>
        public void Process(EncogAnalyst target)
        {
            int       count     = 0;
            CSVFormat csvFormat = ConvertStringConst
                                  .ConvertToCSVFormat(_format);
            var csv = new ReadCSV(_filename, _headers, csvFormat);

            // pass one, calculate the min/max
            while (csv.Next())
            {
                if (_fields == null)
                {
                    GenerateFields(csv);
                }

                for (int i = 0; i < csv.ColumnCount; i++)
                {
                    if (_fields != null)
                    {
                        _fields[i].Analyze1(csv.Get(i));
                    }
                }
                count++;
            }

            if (count == 0)
            {
                throw new AnalystError("Can't analyze file, it is empty.");
            }

            if (_fields != null)
            {
                foreach (AnalyzedField field in _fields)
                {
                    field.CompletePass1();
                }
            }

            csv.Close();

            // pass two, standard deviation
            csv = new ReadCSV(_filename, _headers, csvFormat);

            while (csv.Next())
            {
                for (int i = 0; i < csv.ColumnCount; i++)
                {
                    if (_fields != null)
                    {
                        _fields[i].Analyze2(csv.Get(i));
                    }
                }
            }

            if (_fields != null)
            {
                foreach (AnalyzedField field in _fields)
                {
                    field.CompletePass2();
                }
            }

            csv.Close();

            String str = _script.Properties.GetPropertyString(
                ScriptProperties.SetupConfigAllowedClasses) ?? "";

            bool allowInt  = str.Contains("int");
            bool allowReal = str.Contains("real") ||
                             str.Contains("double");
            bool allowString = str.Contains("string");

            // remove any classes that did not qualify
            foreach (AnalyzedField field in _fields)
            {
                if (field.Class)
                {
                    if (!allowInt && field.Integer)
                    {
                        field.Class = false;
                    }

                    if (!allowString && (!field.Integer && !field.Real))
                    {
                        field.Class = false;
                    }

                    if (!allowReal && field.Real && !field.Integer)
                    {
                        field.Class = false;
                    }
                }
            }

            // merge with existing
            if ((target.Script.Fields != null) &&
                (_fields.Length == target.Script.Fields.Length))
            {
                for (int i = 0; i < _fields.Length; i++)
                {
                    // copy the old field name
                    _fields[i].Name = target.Script.Fields[i].Name;

                    if (_fields[i].Class)
                    {
                        IList <AnalystClassItem> t = _fields[i].AnalyzedClassMembers;
                        IList <AnalystClassItem> s = target.Script.Fields[i].ClassMembers;

                        if (s.Count == t.Count)
                        {
                            for (int j = 0; j < s.Count; j++)
                            {
                                if (t[j].Code.Equals(s[j].Code))
                                {
                                    t[j].Name = s[j].Name;
                                }
                            }
                        }
                    }
                }
            }

            // now copy the fields
            var df = new DataField[_fields.Length];

            for (int i_4 = 0; i_4 < df.Length; i_4++)
            {
                df[i_4] = _fields[i_4].FinalizeField();
            }

            target.Script.Fields = df;
        }