コード例 #1
0
        public IHttpActionResult MakePrediction(PredictionSeed seed)
        {
            NNPredictor predictor = BlobConverter <NNPredictor> .Decode(db.Stocks.Find(seed.id).Data);

            List <StockHistory> history  = new List <StockHistory>();
            StockHistory        firstDay = new StockHistory
            {
                Close  = seed.day1.Close,
                Volume = seed.day1.Volume
            };

            history.Add(firstDay);
            StockHistory secondDay = new StockHistory
            {
                Close  = seed.day2.Close,
                Volume = seed.day2.Volume
            };

            history.Add(secondDay);
            StockHistory thirdDay = new StockHistory
            {
                Close  = seed.day3.Close,
                Volume = seed.day3.Volume
            };

            history.Add(thirdDay);

            var output = predictor.Predict(history)[0][0];

            return(Ok(output));
        }
コード例 #2
0
        private void savePredictedStockHistory(List <StockHistory> history, int id, NNPredictor predictor)
        {
            int size = parameters.LagWindowSize;

            for (int i = 0; i < history.Count - size; i++)
            {
                var output    = predictor.Predict(history.GetRange(i, size));
                var predicted = new PredictedStockHistory
                {
                    Date    = history[i + size].Date,
                    Close   = output[0][0],
                    StockId = id
                };
                db.PredictedStockHistories.Add(predicted);
            }
        }