Ejemplo n.º 1
0
        /// <summary>
        /// Executes a run of processing the stock data
        /// </summary>
        /// <param name="session">The session configuration</param>
        public static void Run(StockSession session)
        {
            // Create the stock processor
            StockProcessor processor = new StockProcessor(session);

            // Get the sizes of the features and labels
            int dstIdx = 0;
            int numDataPoints = 0;
            int numFeatures, numLabels;

            float[,] tmpDst  = new float[1, 1024];
            int[,] tmpLabels = new int[1, 1];
            var tmpDataPoint = processor.DerivedData.First().Value[0];

            tmpDataPoint.Load(session);
            PopulateData(tmpDataPoint, tmpDst, tmpLabels, ref dstIdx, out numFeatures, out numLabels);

            // Determine the total number of data points
            List <string> symbols = new List <string>()
            {
                "GNTX"
            };

            foreach (var s in symbols)
            {
                List <StockDataSet <StockDataSink> > sources;
                if (!processor.DerivedData.TryGetValue(s, out sources))
                {
                    continue;
                }
                for (int i = 0; i < sources.Count; i++)
                {
                    sources[i].Load(session);
                    numDataPoints += sources[i].Count;
                }
            }

            // Allocate the feature and label arrays
            float[,] features = new float[numDataPoints, numFeatures];
            int[,] labels     = new int[numDataPoints, numLabels];

            // Load the data
            dstIdx = 0;
            foreach (var s in symbols)
            {
                List <StockDataSet <StockDataSink> > sources;
                if (!processor.DerivedData.TryGetValue(s, out sources))
                {
                    continue;
                }

                // Create a table of each data point in the specified range
                for (int i = 0; i < sources.Count; i++)
                {
                    sources[i].Load(session);
                    PopulateData(sources[i], features, labels, ref dstIdx, out numFeatures, out numLabels);
                }
            }

            // Create the Machine Learning instance
            MLInstance ml = new MLInstance();

            ml.BuildFullyConnectedGraph(new int[] { numFeatures, numFeatures, numLabels });
            ml.PrepareData(features, labels);
            ml.Train();
        }