/// <summary>
 ///     Find the specified data field and return its index.
 /// </summary>
 /// <param name="df">The data field to search for.</param>
 /// <returns>The index of the specified data field, or -1 if not found.</returns>
 public int FindDataFieldIndex(DataField df)
 {
     for (int result = 0; result < _fields.Length; result++)
     {
         if (df == _fields[result])
         {
             return result;
         }
     }
     return -1;
 }
        /// <summary>
        ///     Finalize the field, and create a DataField.
        /// </summary>
        /// <returns>The new DataField.</returns>
        public DataField FinalizeField()
        {
            var result = new DataField(Name)
                {
                    Name = Name,
                    Min = Min,
                    Max = Max,
                    Mean = Mean,
                    StandardDeviation = StandardDeviation,
                    Integer = Integer,
                    Real = Real,
                    Class = Class,
                    Complete = Complete
                };

            // if max and min are the same, we are dealing with a zero-sized range,
            // which will cause other issues.  This is caused by ever number in the
            // column having exactly (or nearly exactly) the same value.  Provide a
            // small range around that value so that every value in this column normalizes
            // to the midpoint of the desired normalization range, typically 0 or 0.5.
            if (Math.Abs(Max - Min) < EncogFramework.DefaultDoubleEqual)
            {
                result.Min = Min - 0.0001;
                result.Max = Min + 0.0001;
            }

            result.ClassMembers.Clear();

            if (result.Class)
            {
                IList<AnalystClassItem> list = AnalyzedClassMembers;
                foreach (AnalystClassItem item in list)
                {
                    result.ClassMembers.Add(item);
                }
            }

            return result;
        }
Esempio n. 3
0
 public void Process(EncogAnalyst target)
 {
     string text1;
     int num;
     int num2;
     string str;
     bool flag;
     bool flag2;
     bool flag3;
     AnalyzedField field3;
     int num3;
     IList<AnalystClassItem> analyzedClassMembers;
     IList<AnalystClassItem> classMembers;
     int num4;
     DataField[] fieldArray;
     int num5;
     AnalyzedField[] fieldArray2;
     int num6;
     AnalyzedField[] fieldArray3;
     int num7;
     AnalyzedField[] fieldArray4;
     int num8;
     CSVFormat format = ConvertStringConst.ConvertToCSVFormat(this._x5786461d089b10a0);
     ReadCSV dcsv = new ReadCSV(this._xb41a802ca5fde63b, this._x94e6ca5ac178dbd0, format);
     Label_0676:
     if (dcsv.Next())
     {
         if (this._xa942970cc8a85fd4 == null)
         {
             this.xd2a854890d89a856(dcsv);
         }
         num = 0;
         while (num < dcsv.ColumnCount)
         {
             if (this._xa942970cc8a85fd4 != null)
             {
                 this._xa942970cc8a85fd4[num].Analyze1(dcsv.Get(num));
             }
             num++;
         }
         if (((uint) num2) >= 0)
         {
             goto Label_0676;
         }
     }
     else if (this._xa942970cc8a85fd4 != null)
     {
         fieldArray2 = this._xa942970cc8a85fd4;
     }
     else
     {
         if ((((uint) num8) & 0) == 0)
         {
             goto Label_05F5;
         }
         goto Label_05D0;
     }
     if ((((uint) num2) - ((uint) flag2)) >= 0)
     {
         for (num6 = 0; num6 < fieldArray2.Length; num6++)
         {
             fieldArray2[num6].CompletePass1();
         }
         goto Label_05F5;
     }
     goto Label_05D0;
     Label_0011:
     num5++;
     if (((uint) num2) < 0)
     {
         goto Label_0251;
     }
     Label_002C:
     if (num5 < fieldArray.Length)
     {
         fieldArray[num5] = this._xa942970cc8a85fd4[num5].FinalizeField();
         if ((((uint) num6) + ((uint) num)) <= uint.MaxValue)
         {
             goto Label_0011;
         }
         if ((((uint) num8) | 3) != 0)
         {
             goto Label_00E8;
         }
     }
     else
     {
         if (((uint) flag2) > uint.MaxValue)
         {
             goto Label_0336;
         }
         target.Script.Fields = fieldArray;
         return;
     }
     Label_00A6:
     if (this._xa942970cc8a85fd4.Length == target.Script.Fields.Length)
     {
         num3 = 0;
         goto Label_00EE;
     }
     if ((((uint) flag3) & 0) != 0)
     {
         goto Label_0248;
     }
     Label_00D7:
     fieldArray = new DataField[this._xa942970cc8a85fd4.Length];
     if ((((uint) num6) + ((uint) num4)) >= 0)
     {
         num5 = 0;
         goto Label_002C;
     }
     goto Label_0011;
     Label_00E8:
     num3++;
     Label_00EE:
     if (num3 < this._xa942970cc8a85fd4.Length)
     {
         this._xa942970cc8a85fd4[num3].Name = target.Script.Fields[num3].Name;
         if (!this._xa942970cc8a85fd4[num3].Class)
         {
             goto Label_00E8;
         }
         analyzedClassMembers = this._xa942970cc8a85fd4[num3].AnalyzedClassMembers;
         classMembers = target.Script.Fields[num3].ClassMembers;
         if (classMembers.Count != analyzedClassMembers.Count)
         {
             goto Label_00E8;
         }
         num4 = 0;
         if (((uint) num2) > uint.MaxValue)
         {
             goto Label_0341;
         }
         goto Label_0195;
     }
     goto Label_00D7;
     Label_018F:
     num4++;
     Label_0195:
     if (num4 < classMembers.Count)
     {
         if (analyzedClassMembers[num4].Code.Equals(classMembers[num4].Code))
         {
             analyzedClassMembers[num4].Name = classMembers[num4].Name;
         }
         goto Label_018F;
     }
     goto Label_00E8;
     Label_0238:
     if (num8 < fieldArray4.Length)
     {
         field3 = fieldArray4[num8];
         if ((((uint) num) & 0) != 0)
         {
             goto Label_02FF;
         }
         if (field3.Class)
         {
             if (flag)
             {
                 goto Label_0350;
             }
             if (((uint) num4) <= uint.MaxValue)
             {
                 goto Label_03E6;
             }
             goto Label_040F;
         }
         goto Label_0251;
     }
     if (target.Script.Fields != null)
     {
         goto Label_00A6;
     }
     if ((((uint) num8) + ((uint) num5)) > uint.MaxValue)
     {
         goto Label_0341;
     }
     goto Label_00D7;
     Label_0248:
     if (field3.Integer && (field3.AnalyzedClassMembers.Count <= 2))
     {
         if ((((uint) num6) - ((uint) num5)) >= 0)
         {
             if ((((uint) num7) | 4) == 0)
             {
                 goto Label_059B;
             }
             field3.Class = false;
         }
         else
         {
             if ((((uint) flag2) + ((uint) num8)) >= 0)
             {
                 goto Label_0350;
             }
             goto Label_02FF;
         }
     }
     Label_0251:
     num8++;
     goto Label_0238;
     Label_02FF:
     if (!flag2 && (field3.Real && !field3.Integer))
     {
         field3.Class = false;
     }
     goto Label_0248;
     Label_030B:
     if ((((uint) flag3) - ((uint) num2)) >= 0)
     {
         goto Label_02FF;
     }
     Label_0341:
     while (!field3.Real)
     {
         field3.Class = false;
         goto Label_02FF;
     Label_0336:
         if (field3.Integer)
         {
             goto Label_030B;
         }
     }
     goto Label_0368;
     Label_0350:
     if (flag3)
     {
         goto Label_02FF;
     }
     if ((((uint) num5) & 0) == 0)
     {
         goto Label_0336;
     }
     Label_0368:
     if ((((uint) flag) - ((uint) num4)) >= 0)
     {
         goto Label_02FF;
     }
     goto Label_030B;
     Label_03E6:
     if (!field3.Integer)
     {
         goto Label_0350;
     }
     Label_040F:
     field3.Class = false;
     if ((((uint) num7) + ((uint) flag)) < 0)
     {
         goto Label_05F5;
     }
     if ((((uint) num3) + ((uint) flag)) > uint.MaxValue)
     {
         goto Label_04D6;
     }
     if ((((uint) num3) & 0) == 0)
     {
         goto Label_0350;
     }
     goto Label_03E6;
     Label_04A8:
     dcsv.Close();
     Label_04AE:
     text1 = this._x594135906c55045c.Properties.GetPropertyString("SETUP:CONFIG_allowedClasses");
     if (text1 != null)
     {
         str = text1;
     }
     else
     {
         if (0 != 0)
         {
             goto Label_02FF;
         }
         str = "";
     }
     flag = str.Contains("int");
     if (str.Contains("real"))
     {
     }
     flag2 = true;
     flag3 = str.Contains("string");
     fieldArray4 = this._xa942970cc8a85fd4;
     num8 = 0;
     goto Label_0238;
     Label_04D6:
     if (num7 >= fieldArray3.Length)
     {
     }
     AnalyzedField field2 = fieldArray3[num7];
     if (((uint) num4) < 0)
     {
         goto Label_04AE;
     }
     field2.CompletePass2();
     num7++;
     if ((((uint) num4) + ((uint) num2)) < 0)
     {
         goto Label_018F;
     }
     if ((((uint) num3) + ((uint) flag)) >= 0)
     {
         goto Label_04D6;
     }
     Label_0554:
     if (((uint) flag) > uint.MaxValue)
     {
         goto Label_059B;
     }
     goto Label_04D6;
     if ((((uint) num2) | 0x7fffffff) != 0)
     {
         if ((((uint) flag2) - ((uint) num3)) >= 0)
         {
             goto Label_04A8;
         }
         goto Label_05D0;
     }
     Label_058B:
     num2++;
     Label_0591:
     if (num2 < dcsv.ColumnCount)
     {
         goto Label_05D0;
     }
     Label_059B:
     if (dcsv.Next())
     {
         num2 = 0;
         goto Label_0591;
     }
     if (this._xa942970cc8a85fd4 != null)
     {
         fieldArray3 = this._xa942970cc8a85fd4;
         num7 = 0;
         goto Label_0554;
     }
     goto Label_04A8;
     Label_05D0:
     if (this._xa942970cc8a85fd4 != null)
     {
         this._xa942970cc8a85fd4[num2].Analyze2(dcsv.Get(num2));
     }
     goto Label_058B;
     Label_05F5:
     dcsv.Close();
     if (((uint) num) >= 0)
     {
     }
     dcsv = new ReadCSV(this._xb41a802ca5fde63b, this._x94e6ca5ac178dbd0, format);
     goto Label_059B;
 }
        private void GenerateSourceData(IList<SourceElement> sourceData)
        {
            var fields = new DataField[sourceData.Count + 1];
            int index = 0;

            foreach (SourceElement element in sourceData)
            {
                var df = new DataField(element.Name);
                df.Source = element.Source;
                df.Integer = false;
                df.Class = false;
                df.Max = 100000;
                df.Mean = 0;
                df.Min = -100000;
                df.StandardDeviation = 0;
                fields[index++] = df;
            }

            // now add the prediction
            var df2 = new DataField("prediction");
            df2.Source = "prediction";
            df2.Integer = false;
            df2.Class = false;
            df2.Max = 100000;
            df2.Min = -100000;
            df2.Mean = 0;
            df2.StandardDeviation = 0;
            fields[index++] = df2;

            _script.Fields = fields;
        }
Esempio n. 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;
        }
Esempio n. 6
0
        /// <summary>
        ///     Handle loading data stats.
        /// </summary>
        /// <param name="section">The section being loaded.</param>
        private void HandleDataStats(EncogFileSection section)
        {
            IList<DataField> dfs = new List<DataField>();
            bool first = true;

            foreach (String line in section.Lines)
            {
                if (!first)
                {
                    IList<String> cols = EncogFileSection.SplitColumns(line);
                    String name = cols[0];
                    bool isclass = Int32.Parse(cols[1]) > 0;
                    bool iscomplete = Int32.Parse(cols[2]) > 0;
                    bool isint = Int32.Parse(cols[ColumnThree]) > 0;
                    bool isreal = Int32.Parse(cols[ColumnFour]) > 0;
                    double amax = CSVFormat.EgFormat.Parse(cols[5]);
                    double amin = CSVFormat.EgFormat.Parse(cols[6]);
                    double mean = CSVFormat.EgFormat.Parse(cols[7]);
                    double sdev = CSVFormat.EgFormat.Parse(cols[8]);
                    String source = "";

                    // source was added in Encog 3.2, so it might not be there
                    if (cols.Count > 9)
                    {
                        source = cols[9];
                    }

                    var df = new DataField(name)
                        {
                            Class = isclass,
                            Complete = iscomplete,
                            Integer = isint,
                            Real = isreal,
                            Max = amax,
                            Min = amin,
                            Mean = mean,
                            StandardDeviation = sdev,
                            Source = source
                        };
                    dfs.Add(df);
                }
                else
                {
                    first = false;
                }
            }

            var array = new DataField[dfs.Count];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = dfs[i];
            }

            _script.Fields = array;
        }
Esempio n. 7
0
        /// <summary>
        /// Finalize the field, and create a DataField.
        /// </summary>
        ///
        /// <returns>The new DataField.</returns>
        public DataField FinalizeField()
        {
            var result = new DataField(Name)
                             {
                                 Name = Name,
                                 Min = Min,
                                 Max = Max,
                                 Mean = Mean,
                                 StandardDeviation = StandardDeviation,
                                 Integer = Integer,
                                 Real = Real,
                                 Class = Class,
                                 Complete = Complete
                             };

            result.ClassMembers.Clear();

            if (result.Class)
            {
                IList<AnalystClassItem> list = AnalyzedClassMembers;
                foreach (AnalystClassItem item in list)
                {
                    result.ClassMembers.Add(item);
                }
            }

            return result;
        }
Esempio n. 8
0
 public int FindDataFieldIndex(DataField df)
 {
     for (int i = 0; i < this._xa942970cc8a85fd4.Length; i++)
     {
         do
         {
             if (df == this._xa942970cc8a85fd4[i])
             {
                 return i;
             }
         }
         while (-1 == 0);
     }
     return -1;
 }
Esempio n. 9
0
 public DataField FinalizeField()
 {
     DataField field;
     IList<AnalystClassItem> analyzedClassMembers;
     DataField field2 = new DataField(base.Name) {
         Name = base.Name,
         Min = base.Min,
         Max = base.Max,
         Mean = base.Mean,
         StandardDeviation = base.StandardDeviation,
         Integer = base.Integer
     };
     if (0 == 0)
     {
         goto Label_0094;
     }
     goto Label_0068;
     if (0 != 0)
     {
         goto Label_0094;
     }
     if (0 == 0)
     {
         return field;
     }
     Label_0068:
     field2.Class = base.Class;
     field2.Complete = base.Complete;
     field = field2;
     field.ClassMembers.Clear();
     if (2 != 0)
     {
         if (!field.Class)
         {
             return field;
         }
         analyzedClassMembers = this.AnalyzedClassMembers;
     }
     foreach (AnalystClassItem item in analyzedClassMembers)
     {
         field.ClassMembers.Add(item);
     }
     return field;
     Label_0094:
     field2.Real = base.Real;
     goto Label_0068;
 }
Esempio n. 10
0
        /// <summary>
        ///     Handle loading the data classes.
        /// </summary>
        /// <param name="section">The section being loaded.</param>
        private void HandleDataClasses(EncogFileSection section)
        {
            var map = new Dictionary <String, List <AnalystClassItem> >();

            bool first = true;

            foreach (String line in section.Lines)
            {
                if (!first)
                {
                    IList <String> cols = EncogFileSection.SplitColumns(line);

                    if (cols.Count < ColumnFour)
                    {
                        throw new AnalystError("Invalid data class: " + line);
                    }

                    String field = cols[0];
                    String code  = cols[1];
                    String name  = cols[2];
                    int    count = Int32.Parse(cols[3]);

                    DataField df = _script.FindDataField(field);

                    if (df == null)
                    {
                        throw new AnalystError(
                                  "Attempting to add class to unknown field: " + name);
                    }

                    List <AnalystClassItem> classItems;

                    if (!map.ContainsKey(field))
                    {
                        classItems = new List <AnalystClassItem>();
                        map[field] = classItems;
                    }
                    else
                    {
                        classItems = map[field];
                    }

                    classItems.Add(new AnalystClassItem(code, name, count));
                }
                else
                {
                    first = false;
                }
            }


            foreach (DataField field in _script.Fields)
            {
                if (field.Class)
                {
                    List <AnalystClassItem> classList = map[field.Name];
                    if (classList != null)
                    {
                        classList.Sort();
                        field.ClassMembers.Clear();
                        foreach (AnalystClassItem item in classList)
                        {
                            field.ClassMembers.Add(item);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
 private void xeb630b6ed5f8b04a(EncogFileSection xb32f8dd719a105db)
 {
     bool flag;
     bool flag2;
     bool flag4;
     bool flag5;
     DataField[] fieldArray;
     int num5;
     IList<DataField> list = new List<DataField>();
     goto Label_0054;
     Label_0034:
     fieldArray[num5] = list[num5];
     num5++;
     Label_0047:
     if (num5 < fieldArray.Length)
     {
         goto Label_0034;
     }
     this._x594135906c55045c.Fields = fieldArray;
     if ((((uint) flag2) - ((uint) flag4)) >= 0)
     {
         return;
     }
     Label_0054:
     flag = true;
     using (IEnumerator<string> enumerator = xb32f8dd719a105db.Lines.GetEnumerator())
     {
         string str;
         IList<string> list2;
         string str2;
         bool flag3;
         double num;
         double num2;
         double num3;
         double num4;
         DataField field2;
         goto Label_007F;
     Label_0065:
         if (!flag)
         {
             goto Label_0257;
         }
         if (((uint) flag3) >= 0)
         {
         }
         flag = false;
     Label_007F:
         if (enumerator.MoveNext())
         {
             goto Label_0269;
         }
         goto Label_02A5;
     Label_008D:
         field2.StandardDeviation = num4;
         DataField item = field2;
     Label_009A:
         list.Add(item);
         goto Label_007F;
     Label_00AB:
         field2.Integer = flag4;
         field2.Real = flag5;
         field2.Max = num;
         field2.Min = num2;
         field2.Mean = num3;
         goto Label_008D;
     Label_00DD:
         field2.Complete = flag3;
         if ((((uint) flag) + ((uint) num)) >= 0)
         {
             goto Label_00AB;
         }
         if ((((uint) flag) + ((uint) flag)) >= 0)
         {
             goto Label_0182;
         }
     Label_0119:
         if ((((uint) num2) & 0) != 0)
         {
             goto Label_0257;
         }
     Label_0130:
         num2 = CSVFormat.EgFormat.Parse(list2[6]);
         num3 = CSVFormat.EgFormat.Parse(list2[7]);
         num4 = CSVFormat.EgFormat.Parse(list2[8]);
         field2 = new DataField(str2) {
             Class = flag2
         };
         if (0xff != 0)
         {
             goto Label_00DD;
         }
     Label_0182:
         if ((((uint) flag) | 0xfffffffe) == 0)
         {
             goto Label_0130;
         }
         if ((((uint) num2) | 8) != 0)
         {
             goto Label_0119;
         }
         goto Label_00DD;
     Label_01C4:
         num = CSVFormat.EgFormat.Parse(list2[5]);
         if ((((uint) num) & 0) == 0)
         {
             goto Label_0182;
         }
         goto Label_0269;
     Label_01F3:
         if (((uint) flag4) < 0)
         {
             goto Label_009A;
         }
         str2 = list2[0];
         flag2 = int.Parse(list2[1]) > 0;
         flag3 = int.Parse(list2[2]) > 0;
         flag4 = int.Parse(list2[3]) > 0;
         flag5 = int.Parse(list2[4]) > 0;
         goto Label_01C4;
     Label_0257:
         list2 = EncogFileSection.SplitColumns(str);
         goto Label_01F3;
     Label_0269:
         str = enumerator.Current;
         goto Label_0065;
     }
     if (((uint) flag5) > uint.MaxValue)
     {
         goto Label_0034;
     }
     Label_02A5:
     fieldArray = new DataField[list.Count];
     num5 = 0;
     goto Label_0047;
 }