Inheritance: IMLDataPair
Beispiel #1
0
        /// <summary>
        /// Load a CSV file into a memory dataset.  
        /// </summary>
        ///
        /// <param name="format">The CSV format to use.</param>
        /// <param name="filename">The filename to load.</param>
        /// <param name="headers">True if there is a header line.</param>
        /// <param name="inputSize">The input size.  Input always comes first in a file.</param>
        /// <param name="idealSize">The ideal size, 0 for unsupervised.</param>
        /// <returns>A NeuralDataSet that holds the contents of the CSV file.</returns>
        public static IMLDataSet LoadCSVTOMemory(CSVFormat format, String filename,
                                                bool headers, int inputSize, int idealSize)
        {
            var result = new BasicMLDataSet();
            var csv = new ReadCSV(filename, headers, format);
            while (csv.Next())
            {
                BasicMLData ideal = null;
                int index = 0;

                var input = new BasicMLData(inputSize);
                for (int i = 0; i < inputSize; i++)
                {
                    double d = csv.GetDouble(index++);
                    input[i] = d;
                }

                if (idealSize > 0)
                {
                    ideal = new BasicMLData(idealSize);
                    for (int i = 0; i < idealSize; i++)
                    {
                        double d = csv.GetDouble(index++);
                        ideal[i] = d;
                    }
                }

                IMLDataPair pair = new BasicMLDataPair(input, ideal);
                result.Add(pair);
            }

            return result;
        }
        /// <summary>
        /// Generate a random training set. 
        /// </summary>
        /// <param name="seed">The seed value to use, the same seed value will always produce
        /// the same results.</param>
        /// <param name="count">How many training items to generate.</param>
        /// <param name="inputCount">How many input numbers.</param>
        /// <param name="idealCount">How many ideal numbers.</param>
        /// <param name="min">The minimum random number.</param>
        /// <param name="max">The maximum random number.</param>
        /// <returns>The random training set.</returns>
        public static BasicMLDataSet Generate(long seed,
                                              int count, int inputCount,
                                              int idealCount, double min, double max)
        {
            var rand =
                new LinearCongruentialGenerator(seed);

            var result = new BasicMLDataSet();
            for (int i = 0; i < count; i++)
            {
                IMLData inputData = new BasicMLData(inputCount);

                for (int j = 0; j < inputCount; j++)
                {
                    inputData.Data[j] = rand.Range(min, max);
                }

                IMLData idealData = new BasicMLData(idealCount);

                for (int j = 0; j < idealCount; j++)
                {
                    idealData[j] = rand.Range(min, max);
                }

                var pair = new BasicMLDataPair(inputData,
                                               idealData);
                result.Add(pair);
            }
            return result;
        }
        /// <summary>
        /// Clone this object.
        /// </summary>
        /// <returns>A clone of this object.</returns>
        public object Clone()
        {
            Object result;

            if (Ideal == null)
            {
                result = new BasicMLDataPair((IMLData)_input.Clone());
            }
            else
            {
                result = new BasicMLDataPair((IMLData)_input.Clone(),
                                             (IMLData)_ideal.Clone());
            }

            return(result);
        }
        /// <summary>
        /// Create a new neural data pair object of the correct size for the neural
        /// network that is being trained. This object will be passed to the getPair
        /// method to allow the neural data pair objects to be copied to it.
        /// </summary>
        /// <param name="inputSize">The size of the input data.</param>
        /// <param name="idealSize">The size of the ideal data.</param>
        /// <returns>A new neural data pair object.</returns>
        public static BasicMLDataPair CreatePair(int inputSize, int idealSize)
        {
            BasicMLDataPair result;

            if (idealSize > 0)
            {
                result = new BasicMLDataPair(new BasicMLData(inputSize),
                                             new BasicMLData(idealSize));
            }
            else
            {
                result = new BasicMLDataPair(new BasicMLData(inputSize));
            }

            return(result);
        }
Beispiel #5
0
 public static IMLDataSet CreateNoisyXORDataSet(int count)
 {
     var result = new BasicMLDataSet();
     for (int i = 0; i < count; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             var inputData = new BasicMLData(XORInput[j]);
             var idealData = new BasicMLData(XORIdeal[j]);
             var pair = new BasicMLDataPair(inputData, idealData);
             inputData[0] = inputData[0] + RangeRandomizer.Randomize(-0.1, 0.1);
             inputData[1] = inputData[1] + RangeRandomizer.Randomize(-0.1, 0.1);
             result.Add(pair);
         }
     }
     return result;
 }
Beispiel #6
0
 /// <summary>
 /// Construct the centroid.
 /// </summary>
 /// <param name="o"> The pair to base the centroid on.</param>
 public BasicMLDataPairCentroid(BasicMLDataPair o)
 {
     _value = (BasicMLData)o.Input.Clone();
     _size  = 1;
 }
        /// <inheritdoc/>
        public IMLDataPair this[int x]
        {
            get
            {
                var input = new double[InputSize];
                var ideal = new double[IdealSize];

                _egb.SetLocation(x);
                _egb.Read(input);
                _egb.Read(ideal);

                var inputData = new BasicMLData(input, false);
                var idealData = new BasicMLData(ideal, false);

                var result = new BasicMLDataPair(inputData, idealData);
                result.Significance = _egb.Read();
                return result;
            }
        }
        /// <summary>
        /// Process the data array and returns an IMLdatapair.
        /// </summary>
        ///
        /// <param name="data">The array to process.</param>
        /// <returns>An IMLDatapair containing data.</returns>
        public IMLDataPair ProcessToPair(double[] data)
        {
            // not sure this method works right: it's only using the last pair?
            IMLDataPair pair = null;
            int totalWindowSize = _inputWindow + _predictWindow;
            int stopPoint = data.Length - totalWindowSize;

            for (int i = 0; i < stopPoint; i++)
            {
                var inputData = new BasicMLData(_inputWindow);
                var idealData = new BasicMLData(_predictWindow);

                int index = i;

                // handle input window
                for (int j = 0; j < _inputWindow; j++)
                {
                    inputData[j] = data[index++];
                }

                // handle predict window
                for (int j = 0; j < _predictWindow; j++)
                {
                    idealData[j] = data[index++];
                }

                pair = new BasicMLDataPair(inputData, idealData);
            }
            return pair;
        }
Beispiel #9
0
 public static IMLDataSet LoadCSVTOMemory(CSVFormat format, string filename, bool headers, int inputSize, int idealSize)
 {
     ReadCSV dcsv;
     IMLData data;
     int num;
     IMLData data2;
     int num4;
     IMLDataSet set = new BasicMLDataSet();
     goto Label_00FF;
     Label_000B:
     if (idealSize > 0)
     {
         data = new BasicMLData(idealSize);
         num4 = 0;
         while (num4 < idealSize)
         {
             double num5 = dcsv.GetDouble(num++);
             data[num4] = num5;
             num4++;
         }
     }
     IMLDataPair inputData = new BasicMLDataPair(data2, data);
     set.Add(inputData);
     Label_0022:
     if (!dcsv.Next())
     {
         return set;
     }
     Label_00C4:
     data = null;
     num = 0;
     if (((uint) num4) < 0)
     {
         goto Label_0108;
     }
     data2 = new BasicMLData(inputSize);
     int num2 = 0;
     Label_006A:
     if (num2 < inputSize)
     {
         double num3 = dcsv.GetDouble(num++);
         if (-2147483648 != 0)
         {
             data2[num2] = num3;
             if ((((uint) idealSize) + ((uint) num)) >= 0)
             {
                 num2++;
             }
             if ((((uint) num) - ((uint) idealSize)) >= 0)
             {
                 goto Label_006A;
             }
             goto Label_0125;
         }
     }
     else
     {
         if (0 == 0)
         {
             goto Label_000B;
         }
         if (0 == 0)
         {
             goto Label_0125;
         }
     }
     goto Label_00C4;
     Label_00FF:
     dcsv = new ReadCSV(filename, headers, format);
     Label_0108:
     if ((((uint) num) + ((uint) num2)) < 0)
     {
         goto Label_00FF;
     }
     goto Label_0022;
     Label_0125:
     if (((uint) num4) >= 0)
     {
         goto Label_000B;
     }
     return set;
 }
        /// <summary>
        /// Clone this object.
        /// </summary>
        /// <returns>A clone of this object.</returns>
        public object Clone()
        {
            Object result;

            if (Ideal == null)
                result = new BasicMLDataPair((IMLData) _input.Clone());
            else
                result = new BasicMLDataPair((IMLData) _input.Clone(),
                                             (IMLData) _ideal.Clone());

            return result;
        }
        /// <summary>
        /// Read an object.
        /// </summary>
        public Object Read(Stream mask0)
        {
            var ins0 = new EncogReadHelper(mask0);
            EncogFileSection section;
            var samples = new BasicMLDataSet();
            IDictionary<String, String> networkParams = null;
            PNNKernelType kernel = default(PNNKernelType) /* was: null */;
            PNNOutputMode outmodel = default(PNNOutputMode) /* was: null */;
            int inputCount = 0;
            int outputCount = 0;
            double error = 0;
            double[] sigma = null;

            while ((section = ins0.ReadNextSection()) != null)
            {
                if (section.SectionName.Equals("PNN")
                    && section.SubSectionName.Equals("PARAMS"))
                {
                    networkParams = section.ParseParams();
                }
                if (section.SectionName.Equals("PNN")
                    && section.SubSectionName.Equals("NETWORK"))
                {
                    IDictionary<String, String> paras = section.ParseParams();
                    inputCount = EncogFileSection.ParseInt(paras,
                                                           PersistConst.InputCount);
                    outputCount = EncogFileSection.ParseInt(paras,
                                                            PersistConst.OutputCount);
                    kernel = StringToKernel(paras[PersistConst.Kernel]);
                    outmodel = StringToOutputMode(paras[PropertyOutputMode]);
                    error = EncogFileSection
                        .ParseDouble(paras, PersistConst.Error);
                    sigma = section.ParseDoubleArray(paras, PersistConst.Sigma);
                }
                if (section.SectionName.Equals("PNN")
                    && section.SubSectionName.Equals("SAMPLES"))
                {
                    foreach (String line  in  section.Lines)
                    {
                        IList<String> cols = EncogFileSection
                            .SplitColumns(line);
                        int index = 0;
                        var inputData = new BasicMLData(inputCount);
                        for (int i = 0; i < inputCount; i++)
                        {
                            inputData[i] =
                                CSVFormat.EgFormat.Parse(cols[index++]);
                        }
                        var idealData = new BasicMLData(inputCount);

                        idealData[0] = CSVFormat.EgFormat.Parse(cols[index++]);

                        IMLDataPair pair = new BasicMLDataPair(inputData,
                                                              idealData);
                        samples.Add(pair);
                    }
                }
            }

            var result = new BasicPNN(kernel, outmodel, inputCount,
                                      outputCount);
            if (networkParams != null)
            {
                EngineArray.PutAll(networkParams, result.Properties);
            }
            result.Samples = samples;
            result.Error = error;
            if (sigma != null)
            {
                EngineArray.ArrayCopy(sigma, result.Sigma);
            }

            return result;
        }
        /// <summary>
        /// Process the data array and returns an IMLdatapair.
        /// </summary>
        ///
        /// <param name="data">The array to process.</param>
        /// <returns>An IMLDatapair containing data.</returns>
        public IMLDataPair ProcessToPair(double[] data)
        {
            IMLDataPair pair = null;
            int totalWindowSize = _inputWindow + _predictWindow;
            int stopPoint = data.Length - totalWindowSize;

            for (int i = 0; i < stopPoint; i++)
            {
                IMLData inputData = new BasicMLData(_inputWindow);
                IMLData idealData = new BasicMLData(_predictWindow);

                int index = i;

                // handle input window
                for (int j = 0; j < _inputWindow; j++)
                {
                    inputData[j] = data[index++];
                }

                // handle predict window
                for (int j = 0; j < _predictWindow; j++)
                {
                    idealData[j] = data[index++];
                }

                pair = new BasicMLDataPair(inputData, idealData);
            }
            return pair;
        }
Beispiel #13
0
 public IMLDataSet External2Memory()
 {
     double[] numArray;
     double[] numArray2;
     int num;
     int num2;
     double num3;
     IMLData data;
     IMLData data2;
     IMLDataPair pair;
     this.x658c509a55e4e71a.Report(0, 0, "Importing to memory");
     goto Label_0166;
     Label_0017:
     if (1 == 0)
     {
         goto Label_011C;
     }
     Label_0021:
     if (this._x75d376891c19d365.Read(numArray, numArray2, ref num3))
     {
         data = null;
         data2 = new BasicMLData(numArray);
         goto Label_00FF;
     }
     this._x75d376891c19d365.Close();
     this.x658c509a55e4e71a.Report(0, 0, "Done importing to memory");
     return this.Result;
     Label_0065:
     this.x658c509a55e4e71a.Report(0, num, "Importing...");
     goto Label_0017;
     Label_00B8:
     pair = new BasicMLDataPair(data2, data);
     pair.Significance = num3;
     if (0 != 0)
     {
         goto Label_0166;
     }
     this.Result.Add(pair);
     if ((((uint) num3) - ((uint) num2)) >= 0)
     {
         num++;
         if ((((uint) num) & 0) != 0)
         {
             goto Label_016E;
         }
         if ((((uint) num) + ((uint) num)) < 0)
         {
             goto Label_00B8;
         }
     }
     if (3 != 0)
     {
         num2++;
         if (num2 < 0x2710)
         {
             goto Label_0021;
         }
         num2 = 0;
         goto Label_0065;
     }
     goto Label_0017;
     Label_00FF:
     if (this._x75d376891c19d365.IdealSize <= 0)
     {
         goto Label_00B8;
     }
     Label_011C:
     data = new BasicMLData(numArray2);
     if (0x7fffffff == 0)
     {
         goto Label_00FF;
     }
     goto Label_00B8;
     Label_0166:
     if (this.Result == null)
     {
         this.Result = new BasicMLDataSet();
         if (0 == 0)
         {
             if (((uint) num3) > uint.MaxValue)
             {
                 goto Label_0065;
             }
         }
         else
         {
             goto Label_01A6;
         }
     }
     Label_016E:
     numArray = new double[this._x75d376891c19d365.InputSize];
     numArray2 = new double[this._x75d376891c19d365.IdealSize];
     this._x75d376891c19d365.PrepareRead();
     num = 0;
     num2 = 0;
     num3 = 1.0;
     Label_01A6:
     if ((((uint) num2) + ((uint) num)) <= uint.MaxValue)
     {
         goto Label_0021;
     }
     goto Label_00B8;
 }
 /// <summary>
 /// Processes the specified double serie into an IMLDataset.
 /// To use this method, you must provide a formated double array with the input data and the ideal data in another double array.
 /// The number of points in the input window makes the input array , and the predict window will create the array used in ideal.
 /// This method will use ALL the data inputs and ideals you have provided.
 /// </summary>
 /// <param name="datainput">The datainput.</param>
 /// <param name="ideals">The ideals.</param>
 /// <param name="_inputWindow">The _input window.</param>
 /// <param name="_predictWindow">The _predict window.</param>
 /// <returns></returns>
 public static IMLDataSet ProcessDoubleSerieIntoIMLDataset(List<double> datainput,List<double>ideals, int _inputWindow, int _predictWindow)
 {
     var result = new BasicMLDataSet();
     //int count = 0;
     ////lets check if there is a modulo , if so we move forward in the List of doubles in inputs.This is just a check
     ////as the data of inputs should be able to fill without having .
     //while (datainput.Count % _inputWindow !=0)
     //{
     //    count++;
     //}
     var inputData = new BasicMLData(_inputWindow);
     var idealData = new BasicMLData(_predictWindow);
     foreach (double d in datainput)
     {
         // handle input window
         for (int j = 0; j < _inputWindow; j++)
         {
             inputData[j] = d;
         }
     }
     foreach (double ideal in ideals)
     {
          // handle predict window
         for (int j = 0; j < _predictWindow; j++)
         {
             idealData[j] =ideal;
         }
     }
     var pair = new BasicMLDataPair(inputData, idealData);
     result.Add(pair);
     return result;
 }
Beispiel #15
0
 public static BasicMLDataSet Generate(long seed, int count, int inputCount, int idealCount, double min, double max)
 {
     IMLData data;
     int num2;
     IMLData data2;
     BasicMLDataPair pair;
     LinearCongruentialGenerator generator = new LinearCongruentialGenerator(seed);
     BasicMLDataSet set = new BasicMLDataSet();
     int num = 0;
     goto Label_0018;
     Label_000C:
     set.Add(pair);
     Label_0014:
     num++;
     Label_0018:
     if (num < count)
     {
         data = new BasicMLData(inputCount);
         num2 = 0;
         while (num2 < inputCount)
         {
             data.Data[num2] = generator.Range(min, max);
             num2++;
         }
         data2 = new BasicMLData(idealCount);
         if (((uint) count) < 0)
         {
             goto Label_000C;
         }
         if ((((uint) idealCount) & 0) != 0)
         {
             goto Label_0014;
         }
         int num3 = 0;
     Label_002D:
         if (num3 < idealCount)
         {
             data2[num3] = generator.Range(min, max);
             if ((((uint) idealCount) - ((uint) max)) <= uint.MaxValue)
             {
                 num3++;
                 goto Label_002D;
             }
         }
         else
         {
             goto Label_0032;
         }
         goto Label_00C6;
     }
     if (0 == 0)
     {
         return set;
     }
     Label_0032:
     pair = new BasicMLDataPair(data, data2);
     Label_00C6:
     if ((((uint) num2) & 0) == 0)
     {
         goto Label_000C;
     }
     goto Label_0018;
 }
Beispiel #16
0
 public static void Generate(IMLDataSet training, long seed, int count, double min, double max)
 {
     int num;
     int idealSize;
     int num3;
     IMLData data;
     int num4;
     IMLData data2;
     int num5;
     LinearCongruentialGenerator generator = new LinearCongruentialGenerator(seed);
     goto Label_0111;
     Label_0023:
     if (num3 < count)
     {
         data = new BasicMLData(num);
         num4 = 0;
         while (true)
         {
             if (num4 < num)
             {
                 data[num4] = generator.Range(min, max);
             }
             else
             {
                 data2 = new BasicMLData(idealSize);
                 num5 = 0;
                 goto Label_004D;
             }
             num4++;
         }
     }
     if ((((uint) num) - ((uint) num)) >= 0)
     {
         if ((((uint) num4) - ((uint) num3)) >= 0)
         {
             if ((((uint) seed) + ((uint) seed)) >= 0)
             {
                 return;
             }
             goto Label_0111;
         }
         goto Label_00F5;
     }
     Label_0047:
     num5++;
     Label_004D:
     if (num5 >= idealSize)
     {
         if ((((uint) max) + ((uint) num3)) <= uint.MaxValue)
         {
             BasicMLDataPair inputData = new BasicMLDataPair(data, data2);
             training.Add(inputData);
             num3++;
         }
     }
     else
     {
         data2[num5] = generator.Range(min, max);
         if (((uint) num5) >= 0)
         {
             goto Label_0047;
         }
     }
     goto Label_0023;
     Label_00F5:
     num3 = 0;
     goto Label_0023;
     Label_0111:
     num = training.InputSize;
     idealSize = training.IdealSize;
     goto Label_00F5;
 }
Beispiel #17
0
 public IMLDataSet Process(double[] data)
 {
     int num;
     int num2;
     int num3;
     IMLData data2;
     IMLData data3;
     int num4;
     int num6;
     IMLDataSet set = new BasicMLDataSet();
     goto Label_00F0;
     Label_0017:
     if (num3 < num2)
     {
         int num5;
         data2 = new BasicMLData(this._xdf118c3be13cc35d);
         do
         {
             data3 = new BasicMLData(this._x819dc6aed7346fc6);
             if ((((uint) num3) | 3) == 0)
             {
                 goto Label_004D;
             }
             num4 = num3;
         }
         while ((((uint) num3) - ((uint) num5)) < 0);
         num5 = 0;
         if ((((uint) num5) | 0xff) != 0)
         {
         Label_007A:
             if (num5 < this._xdf118c3be13cc35d)
             {
                 data2[num5] = data[num4++];
                 if ((((uint) num3) + ((uint) num5)) <= uint.MaxValue)
                 {
                     num5++;
                     goto Label_007A;
                 }
             }
             num6 = 0;
             goto Label_0053;
         }
         goto Label_00F0;
     }
     return set;
     Label_004D:
     num6++;
     Label_0053:
     if (num6 < this._x819dc6aed7346fc6)
     {
         data3[num6] = data[num4++];
         if ((((uint) num6) | 15) == 0)
         {
             return set;
         }
         goto Label_004D;
     }
     IMLDataPair inputData = new BasicMLDataPair(data2, data3);
     set.Add(inputData);
     num3++;
     goto Label_0017;
     Label_00F0:
     num = this._xdf118c3be13cc35d + this._x819dc6aed7346fc6;
     num2 = data.Length - num;
     num3 = 0;
     goto Label_0017;
 }
        /// <summary>
        /// Generate random training into a training set.
        /// </summary>
        /// <param name="training">The training set to generate into.</param>
        /// <param name="seed">The seed to use.</param>
        /// <param name="count">How much data to generate.</param>
        /// <param name="min">The low random value.</param>
        /// <param name="max">The high random value.</param>
        public static void Generate(IMLDataSetAddable training,
            long seed,
            int count,
            double min, double max)
        {
            var rand
                = new LinearCongruentialGenerator(seed);

            int inputCount = training.InputSize;
            int idealCount = training.IdealSize;

            for (int i = 0; i < count; i++)
            {
                var inputData = new BasicMLData(inputCount);

                for (int j = 0; j < inputCount; j++)
                {
                    inputData[j] = rand.Range(min, max);
                }

                var idealData = new BasicMLData(idealCount);

                for (int j = 0; j < idealCount; j++)
                {
                    idealData[j] = rand.Range(min, max);
                }

                var pair = new BasicMLDataPair(inputData,
                                               idealData);
                training.Add(pair);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Add the specified data to the set.  Add unsupervised data.
        /// </summary>
        /// <param name="data1">The data to add to the set.</param>
        public virtual void Add(IMLData data1)
        {
            IMLDataPair pair = new BasicMLDataPair(data1, null);

            _data.Add(pair);
        }
        /// <summary>
        /// Processes the specified double serie into an IMLDataset.
        /// To use this method, you must provide a formated double array.
        /// The number of points in the input window makes the input array , and the predict window will create the array used in ideal.
        /// Example you have an array with 1, 2, 3 , 4 , 5.
        /// You can use this method to make an IMLDataset 4 inputs and 1 ideal (5).
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="_inputWindow">The _input window.</param>
        /// <param name="_predictWindow">The _predict window.</param>
        /// <returns></returns>
        public static IMLDataSet ProcessDoubleSerieIntoIMLDataset(double[] data, int _inputWindow, int _predictWindow)
        {
            var result = new BasicMLDataSet();
            int totalWindowSize = _inputWindow + _predictWindow;
            int stopPoint = data.Length - totalWindowSize;
            for (int i = 0; i < stopPoint; i++)
            {
                var inputData = new BasicMLData(_inputWindow);
                var idealData = new BasicMLData(_predictWindow);
                int index = i;
                // handle input window
                for (int j = 0; j < _inputWindow; j++)
                {
                    inputData[j] = data[index++];
                }

                // handle predict window
                for (int j = 0; j < _predictWindow; j++)
                {
                    idealData[j] = data[index++];
                }
                var pair = new BasicMLDataPair(inputData, idealData);
                result.Add(pair);
            }

            return result;
        }
        /// <summary>
        /// Loads variables inputs and one ideal double series into an imldataset.
        /// </summary>
        /// <param name="idealsinputs"></param>
        /// <param name="WindoSize"></param>
        /// <param name="pparamInputs"></param>
        /// <returns></returns>
        public static Tuple<IMLDataSet, NormalizeArray> Load(double[] idealsinputs, int WindoSize, params double[][] pparamInputs)
        {
            try
            {
                var finalSet = new BasicMLDataSet();
                //We make a dic with the count of inputs being the number of double series we are sending in.
                Dictionary<int, double[]> inputsDics = new Dictionary<int, double[]>(pparamInputs.Length);
                int indexS = 0;
                //We make a normalizeArray which we will return as a tuple ready for denormalization.
                NormalizeArray Normer = new NormalizeArray(-1, 1);
                //Process each inputs.
                foreach (double[] doubleSeries in pparamInputs)
                {
                   inputsDics.Add(indexS++, Normer.Process(doubleSeries));
                }
             //Process the ideals.
                var idealNormed = Normer.Process(idealsinputs);

                //Make a list which will hold the inputs one after the others
                List<double> dtda = new List<double>();
                int listindex = 0;
                int currentindex = 0;
                //starts from zero so count -1..
                int dicinputsCount = inputsDics.Keys.Count - 1;
                //Process the input normed.
                foreach (double d in inputsDics[0])
                {
                    if (currentindex++ < WindoSize)
                    {
                        dtda.Add(d);
                        //we put all the fields which are in the dic.
                        while (dicinputsCount > 0)
                        {
                            dtda.Add(inputsDics[dicinputsCount--][listindex]);
                        }
                        //We reset the field count for a later pass.
                        dicinputsCount = inputsDics.Keys.Count - 1;
                    }

                    if (currentindex == WindoSize)
                    {
                        //Make an imldata pair, and add it to the imldataset...reset the temp list of inputs...
                        var pair = new BasicMLDataPair(
                                    new BasicMLData(dtda.ToArray()),
                                    new BasicMLData(new double[] { idealNormed[listindex] }));
                        currentindex = 0;
                        dtda.Clear();
                        finalSet.Add(pair);
                    }
                    //Lets increment the indexes..
                    listindex++;
                }
                //Return the dataset and the normalization array..
                return new Tuple<IMLDataSet, NormalizeArray>(finalSet,Normer);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Got an error : ", ex);
                throw new Exception("Error parsing points....");
            }
        }
 /// <summary>
 /// Processes a double array of data of input and a second array of data for ideals
 /// you must input the input and output size.
 /// this typically builds a supervised IMLDatapair, which you must add to a IMLDataset. 
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="ideal">The ideal.</param>
 /// <param name="_inputWindow">The _input window.</param>
 /// <param name="_predictWindow">The _predict window.</param>
 /// <returns></returns>
 public static IMLDataPair ProcessPairs(double[] data, double[] ideal, int _inputWindow, int _predictWindow)
 {
     var result = new BasicMLDataSet();
     for (int i = 0; i < data.Length; i++)
     {
         var inputData = new BasicMLData(_inputWindow);
         var idealData = new BasicMLData(_predictWindow);
         int index = i;
         // handle input window
         for (int j = 0; j < _inputWindow; j++)
         {
             inputData[j] = data[index++];
         }
         index = 0;
         // handle predict window
         for (int j = 0; j < _predictWindow; j++)
         {
             idealData[j] = ideal[index++];
         }
         IMLDataPair pair = new BasicMLDataPair(inputData, idealData);
         return pair;
     }
     return null;
 }
        /// <summary>
        /// Convert an external file format, such as CSV, to an Encog memory training set. 
        /// </summary>
        public IMLDataSet External2Memory()
        {
            Status.Report(0, 0, "Importing to memory");

            if (Result == null)
            {
                Result = new BasicMLDataSet();
            }

            var input = new double[_codec.InputSize];
            var ideal = new double[_codec.IdealSize];

            _codec.PrepareRead();

            int currentRecord = 0;
            int lastUpdate = 0;
            double significance = 1.0;

            while (_codec.Read(input, ideal, ref significance))
            {
                IMLData b = null;

                IMLData a = new BasicMLData(input);

                if (_codec.IdealSize > 0)
                    b = new BasicMLData(ideal);

                IMLDataPair pair = new BasicMLDataPair(a, b);
                pair.Significance = significance;
                Result.Add(pair);

                currentRecord++;
                lastUpdate++;
                if (lastUpdate >= 10000)
                {
                    lastUpdate = 0;
                    Status.Report(0, currentRecord, "Importing...");
                }
            }

            _codec.Close();
            Status.Report(0, 0, "Done importing to memory");
            return Result;
        }
        /// <inheritdoc/>
        public void Add(IMLData inputData, IMLData idealData)
        {
            IMLDataPair pair = new BasicMLDataPair(inputData, idealData);

            _currentSequence.Add(pair);
        }
        /// <summary>
        /// Create a new neural data pair object of the correct size for the neural
        /// network that is being trained. This object will be passed to the getPair
        /// method to allow the neural data pair objects to be copied to it.
        /// </summary>
        /// <param name="inputSize">The size of the input data.</param>
        /// <param name="idealSize">The size of the ideal data.</param>
        /// <returns>A new neural data pair object.</returns>
        public static IMLDataPair CreatePair(int inputSize, int idealSize)
        {
            IMLDataPair result;

            if (idealSize > 0)
            {
                result = new BasicMLDataPair(new BasicMLData(inputSize),
                                             new BasicMLData(idealSize));
            }
            else
            {
                result = new BasicMLDataPair(new BasicMLData(inputSize));
            }

            return result;
        }
Beispiel #26
0
        /// <summary>
        /// Add supervised data to the set.
        /// </summary>
        /// <param name="inputData">The input data.</param>
        /// <param name="idealData">The ideal data.</param>
        public virtual void Add(IMLData inputData, IMLData idealData)
        {
            IMLDataPair pair = new BasicMLDataPair(inputData, idealData);

            _data.Add(pair);
        }
Beispiel #27
0
 public object Read(Stream mask0)
 {
     EncogFileSection section;
     double num3;
     double[] numArray;
     IDictionary<string, string> dictionary2;
     int num4;
     int num5;
     int num6;
     BasicPNN cpnn;
     EncogReadHelper helper = new EncogReadHelper(mask0);
     BasicMLDataSet set = new BasicMLDataSet();
     IDictionary<string, string> source = null;
     PNNKernelType gaussian = PNNKernelType.Gaussian;
     PNNOutputMode unsupervised = PNNOutputMode.Unsupervised;
     int inputCount = 0;
     int outputCount = 0;
     goto Label_042A;
     Label_000C:
     cpnn.Error = num3;
     while (numArray != null)
     {
         EngineArray.ArrayCopy(numArray, cpnn.Sigma);
         return cpnn;
     }
     if ((((uint) num3) - ((uint) outputCount)) <= uint.MaxValue)
     {
         if ((((uint) num5) - ((uint) outputCount)) >= 0)
         {
             return cpnn;
         }
         if ((((uint) inputCount) - ((uint) inputCount)) >= 0)
         {
             goto Label_0319;
         }
         if (((uint) num4) >= 0)
         {
             goto Label_02F1;
         }
         goto Label_02BB;
     }
     goto Label_00D8;
     Label_0075:
     while (source != null)
     {
         EngineArray.PutAll<string, string>(source, cpnn.Properties);
         if ((((uint) outputCount) + ((uint) num3)) >= 0)
         {
             break;
         }
     }
     cpnn.Samples = set;
     goto Label_00A5;
     Label_0082:
     if ((section = helper.ReadNextSection()) != null)
     {
         if (section.SectionName.Equals("PNN") && (((((uint) num4) & 0) != 0) || section.SubSectionName.Equals("PARAMS")))
         {
             source = section.ParseParams();
         }
         if (section.SectionName.Equals("PNN") && section.SubSectionName.Equals("NETWORK"))
         {
             dictionary2 = section.ParseParams();
             if ((((uint) outputCount) + ((uint) num6)) <= uint.MaxValue)
             {
                 inputCount = EncogFileSection.ParseInt(dictionary2, "inputCount");
                 outputCount = EncogFileSection.ParseInt(dictionary2, "outputCount");
             }
             gaussian = StringToKernel(dictionary2["kernel"]);
             if (0 != 0)
             {
                 return cpnn;
             }
             unsupervised = StringToOutputMode(dictionary2["outputMode"]);
             goto Label_0319;
         }
         goto Label_02BB;
     }
     cpnn = new BasicPNN(gaussian, unsupervised, inputCount, outputCount);
     if (4 != 0)
     {
         goto Label_0075;
     }
     Label_00A5:
     if ((((uint) outputCount) | 15) != 0)
     {
         goto Label_000C;
     }
     goto Label_0082;
     Label_00D8:
     if (0 != 0)
     {
         goto Label_042A;
     }
     if ((((uint) num3) | 1) != 0)
     {
         goto Label_0082;
     }
     goto Label_000C;
     Label_02BB:
     if (section.SectionName.Equals("PNN"))
     {
         if (((uint) inputCount) > uint.MaxValue)
         {
             goto Label_0075;
         }
         if (section.SubSectionName.Equals("SAMPLES"))
         {
             using (IEnumerator<string> enumerator = section.Lines.GetEnumerator())
             {
                 string str;
                 IList<string> list;
                 IMLData data;
                 IMLData data2;
                 IMLDataPair pair;
                 goto Label_0193;
             Label_0174:
                 set.Add(pair);
                 if ((((uint) num4) & 0) != 0)
                 {
                     goto Label_0206;
                 }
             Label_0193:
                 if (enumerator.MoveNext())
                 {
                     goto Label_0255;
                 }
                 goto Label_0082;
             Label_01A1:
                 data2[num6] = CSVFormat.EgFormat.Parse(list[num4++]);
                 num6++;
             Label_01C8:
                 if (num6 < outputCount)
                 {
                     goto Label_01A1;
                 }
                 pair = new BasicMLDataPair(data, data2);
                 if (((uint) num3) >= 0)
                 {
                     goto Label_0174;
                 }
                 goto Label_0082;
             Label_01ED:
                 if (((uint) num5) > uint.MaxValue)
                 {
                     goto Label_0238;
                 }
                 num6 = 0;
                 goto Label_01C8;
             Label_0206:
                 num5 = 0;
                 while (num5 < inputCount)
                 {
                     data[num5] = CSVFormat.EgFormat.Parse(list[num4++]);
                     num5++;
                 }
             Label_0238:
                 data2 = new BasicMLData(inputCount);
                 goto Label_01ED;
             Label_0245:
                 num4 = 0;
                 data = new BasicMLData(inputCount);
                 goto Label_0206;
             Label_0255:
                 str = enumerator.Current;
                 list = EncogFileSection.SplitColumns(str);
                 if ((((uint) num6) + ((uint) num4)) <= uint.MaxValue)
                 {
                     goto Label_0245;
                 }
                 goto Label_0082;
             }
             if ((((uint) inputCount) + ((uint) num5)) <= uint.MaxValue)
             {
                 if ((((uint) outputCount) + ((uint) num6)) <= uint.MaxValue)
                 {
                     goto Label_033B;
                 }
                 goto Label_0319;
             }
             goto Label_02F1;
         }
     }
     goto Label_0082;
     Label_02F1:
     numArray = EncogFileSection.ParseDoubleArray(dictionary2, "sigma");
     goto Label_02BB;
     Label_0319:
     num3 = EncogFileSection.ParseDouble(dictionary2, "error");
     if ((((uint) inputCount) & 0) == 0)
     {
         goto Label_02F1;
     }
     Label_033B:
     if ((((uint) inputCount) & 0) == 0)
     {
         goto Label_00D8;
     }
     return cpnn;
     Label_042A:
     num3 = 0.0;
     numArray = null;
     if ((((uint) num4) - ((uint) num6)) < 0)
     {
         goto Label_0075;
     }
     goto Label_0082;
 }