/// <summary>
        /// Write an array.
        /// </summary>
        /// <param name="data">The data to write.</param>
        /// <param name="inputCount">How much of the data is input.</param>
        public void Write(double[] data, int inputCount)
        {
            if (_idealCount == 0)
            {
                var inputData = new BasicMLData(data);
                _dataset.Add(inputData);
            }
            else
            {
                var inputData = new BasicMLData(
                    _inputCount);
                var idealData = new BasicMLData(
                    _idealCount);

                int index = 0;
                for (int i = 0; i < _inputCount; i++)
                {
                    inputData[i] = data[index++];
                }

                for (int i = 0; i < _idealCount; i++)
                {
                    idealData[i] = data[index++];
                }

                _dataset.Add(inputData, idealData);
            }
        }
Ejemplo n.º 2
0
        /// <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(IMLDataSet 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++)
            {
                IMLData inputData = new BasicMLData(inputCount);

                for (int j = 0; j < inputCount; j++)
                {
                    inputData[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);
                training.Add(pair);
            }
        }
        /// <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(IMLDataSet 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++)
            {
                IMLData inputData = new BasicMLData(inputCount);

                for (int j = 0; j < inputCount; j++)
                {
                    inputData[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);
                training.Add(pair);
            }
        }
Ejemplo n.º 4
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;
 }
        /// <summary>
        /// Called to load training data for a company.  This is how the training data is actually created.
        /// To prepare input data for recognition use the CreateData method.  The training set will be
        /// added to.  This allows the network to learn from multiple companies if this method is called
        /// multiple times.
        /// </summary>
        /// <param name="symbol">The ticker symbol.</param>
        /// <param name="training">The training set to add to.</param>
        /// <param name="from">Beginning date</param>
        /// <param name="to">Ending date</param>
        public void LoadCompany(String symbol, IMLDataSet training, DateTime from, DateTime to)
        {
            IMarketLoader loader = new YahooFinanceLoader();
            TickerSymbol ticker = new TickerSymbol(symbol);
            IList<MarketDataType> dataNeeded = new List<MarketDataType>();
            dataNeeded.Add(MarketDataType.AdjustedClose);
            dataNeeded.Add(MarketDataType.Close);
            dataNeeded.Add(MarketDataType.Open);
            dataNeeded.Add(MarketDataType.High);
            dataNeeded.Add(MarketDataType.Low);
            List<LoadedMarketData> results = (List<LoadedMarketData>)loader.Load(ticker, dataNeeded, from, to);
            results.Sort();

            for (int index = PredictWindow; index < results.Count - EvalWindow; index++)
            {
                LoadedMarketData data = results[index];

                // determine bull or bear position, or neither
                bool bullish = false;
                bool bearish = false;

                for (int search = 1; search <= EvalWindow; search++)
                {
                    LoadedMarketData data2 = results[index + search];
                    double priceBase = data.GetData(MarketDataType.AdjustedClose);
                    double priceCompare = data2.GetData(MarketDataType.AdjustedClose);
                    double diff = priceCompare - priceBase;
                    double percent = diff / priceBase;
                    if (percent > BullPercent)
                    {
                        bullish = true;
                    }
                    else if (percent < BearPercent)
                    {
                        bearish = true;
                    }
                }

                IMLDataPair pair = null;

                if (bullish)
                {
                    pair = CreateData(results, index, true);
                }
                else if (bearish)
                {
                    pair = CreateData(results, index, false);
                }

                if (pair != null)
                {
                    training.Add(pair);
                }
            }
        }