예제 #1
0
 public Form1()
 {
     InitializeComponent();
     forecaster = new Forecaster(Appid);
     getWeather(currentCityName);
     getForecast(currentCityName);
 }
 public GameState()
 {
     FastCoord.Init();
     FastShipPosition.Init();
     forecaster = new Forecaster(this);
     admiral    = new Admiral(this);
     strateg    = new Strateg(this);
 }
        public void Run()
        {
            base.Prepare(segment);

            var trainer    = new Trainer(base.MLContext, base.DataLoader, horizon);
            var evaluator  = new Evaluator(base.MLContext, base.DataLoader, trainer);
            var forecaster = new Forecaster(base.MLContext, trainer);

            //UI
            var grid = new Grid(90);

            //General info
            grid.PrintLine();
            grid.PrintRow("Mean Absolute Error", evaluator.MAE.ToString("F3"));
            grid.PrintRow("Root Mean Squared Error", evaluator.RMSE.ToString("F3"));
            grid.PrintLine();

            //Evaluation results
            var testData    = base.DataLoader.TestData;
            var predictions = forecaster.Predict();

            var forecastOutput =
                base.MLContext.Data.CreateEnumerable <ModelInput>(testData, reuseRowObject: false)
                .Take(horizon)
                .Select((ModelInput model, int index) =>
            {
                var date          = model.Date;
                var actualTemps   = model.LandAverageTemperature;
                var lowerEstimate = predictions.LowerBoundLandAverageTemperature[index];
                var estimate      = predictions.ForecastedLandAverageTemperature[index];
                var upperEstimate = predictions.UpperBoundLandAverageTemperature[index];
                return(new List <string> {
                    date.ToShortDateString(),
                    "Yellow|" + actualTemps.ToString("F3"),
                    "Yellow|" + estimate.ToString("F3"),
                    lowerEstimate.ToString("F3"),
                    upperEstimate.ToString("F3")
                });
            });

            grid.PrintLine();
            grid.PrintRow("Date", "Yellow|Actual", "Yellow|Forecase", "Lower", "Upper");
            grid.PrintLine();

            // Output predictions
            foreach (var prediction in forecastOutput)
            {
                grid.PrintRow(prediction.ToArray());
                grid.PrintLine();
            }
        }
예제 #4
0
        static int Main(string[] args)
        {
            ServiceProvider serviceProvider = CreateServiceProvider();
            var             logger          = serviceProvider.GetService <ILogger <Program> >();
            var             writer          = serviceProvider.GetService <FileWriter>();

            return(Parser.Default.ParseArguments <NormalizeOptions, GenerateOptions, PaintOptions, ClusterizationOptions, ForecastOptions>(args)
                   .MapResult(
                       (GenerateOptions opts) => Generator.Generate(opts, logger, writer),
                       (NormalizeOptions opts) => Normalizer.Normalize(opts, logger),
                       (PaintOptions opts) => Painter.Paint(opts, writer, logger),
                       (ClusterizationOptions opts) => Clusterizer.Clusterize(opts, logger, writer),
                       (ForecastOptions opts) => Forecaster.Forecast(opts, writer, logger),
                       errs => HandleParseError(errs, logger)));
        }
예제 #5
0
        public async Task ShouldReturnForecastWeCalled()
        {
            // Assign
            var forecaster = new Forecaster();
            var client     = new Mock <IWeatherServiceClient>();
            IWeatherForecast forecastToReturn = new WeatherForecast(10);

            client.Setup(c => c.FetchForecast()).Returns(Task.FromResult(forecastToReturn));
            // Act
            var result = await forecaster.Forecast(client.Object);

            // Assert
            var expected = 10;

            Assert.AreEqual(expected, result.DegreesForToday);
        }
예제 #6
0
        public void Run(int year, int month)
        {
            var predictionForIndex = ((year - segment.Year) * 12) + month;

            var trainer    = new Trainer(base.MLContext, base.DataLoader, predictionForIndex);
            var forecaster = new Forecaster(base.MLContext, trainer);

            //UI
            var grid = new Grid(90);

            //Results
            var predictions = forecaster.Predict(predictionForIndex);

            grid.PrintLine();
            //grid.PrintRow("Date", "Yellow|Forecase", "Lower", "Upper");
            //grid.PrintLine();
            grid.PrintRow(
                DateTime.Parse(year + "-" + month + "-1").ToShortDateString(),
                "Yellow|" + predictions.ForecastedLandAverageTemperature[predictionForIndex - 1].ToString("F3"),
                predictions.LowerBoundLandAverageTemperature[predictionForIndex - 1].ToString("F3"),
                predictions.UpperBoundLandAverageTemperature[predictionForIndex - 1].ToString("F3")
                );
        }