Ejemplo n.º 1
0
		public void CreateModel()
		{
			CommonEngine = new InferenceEngine();

			cyclist1 = new CyclistPrediction() { InferenceEngine = CommonEngine };
			cyclist1.CreateModel();
			cyclist2 = new CyclistPrediction() { InferenceEngine = CommonEngine };
			cyclist2.CreateModel();

			TimeDifference = cyclist1.TomorrowsTime - cyclist2.TomorrowsTime;
			Cyclist1IsFaster = cyclist1.TomorrowsTime < cyclist2.TomorrowsTime;
		}
Ejemplo n.º 2
0
		public static void RunCyclingTime2()
		{
			double[] trainingData = new double[] { 13, 17, 16, 12, 13, 12, 14, 18, 16, 16 };
			ModelData initPriors = new ModelData(
				Gaussian.FromMeanAndPrecision(1.0, 0.01),
				Gamma.FromShapeAndScale(2.0, 0.5));

			//Train the model
			CyclistTraining cyclistTraining = new CyclistTraining();
			cyclistTraining.CreateModel();
			cyclistTraining.SetModelData(initPriors);

			ModelData posteriors1 = cyclistTraining.InferModelData(trainingData);
			Console.WriteLine("Average travel time = " + posteriors1.AverageTimeDist);
			Console.WriteLine("Traffic noise = " + posteriors1.TrafficNoiseDist);

			//Make predictions based on the trained model
			CyclistPrediction cyclistPrediction = new CyclistPrediction();
			cyclistPrediction.CreateModel();
			cyclistPrediction.SetModelData(posteriors1);

			Gaussian tomorrowsTimeDist = cyclistPrediction.InferTomorrowsTime();

			double tomorrowsMean = tomorrowsTimeDist.GetMean();
			double tomorrowsStdDev = Math.Sqrt(tomorrowsTimeDist.GetVariance());

			Console.WriteLine("Tomorrows average time: {0:f2}", tomorrowsMean);
			Console.WriteLine("Tomorrows standard deviation: {0:f2}", tomorrowsStdDev);
			Console.WriteLine("Probability that tomorrow's time is < 18 min: {0}",
			                  cyclistPrediction.InferProbabilityTimeLessThan(18.0));
			//Second round of training
			double[] trainingData2 = new double[] { 17, 19, 18, 21, 15 };

			cyclistTraining.SetModelData(posteriors1);
			ModelData posteriors2 = cyclistTraining.InferModelData(trainingData2);

			Console.WriteLine("\n2nd training pass");
			Console.WriteLine("Average travel time = " + posteriors2.AverageTimeDist);
			Console.WriteLine("Traffic noise = " + posteriors2.TrafficNoiseDist);

			//Predictions based on two rounds of training
			cyclistPrediction.SetModelData(posteriors2);

			tomorrowsTimeDist = cyclistPrediction.InferTomorrowsTime();
			tomorrowsMean = tomorrowsTimeDist.GetMean();
			tomorrowsStdDev = Math.Sqrt(tomorrowsTimeDist.GetVariance());

			Console.WriteLine("Tomorrows average time: {0:f2}", tomorrowsMean);
			Console.WriteLine("Tomorrows standard deviation: {0:f2}", tomorrowsStdDev);
			Console.WriteLine("Probability that tomorrow's time is < 18 min: {0}",
                              cyclistPrediction.InferProbabilityTimeLessThan(18));
		}
Ejemplo n.º 3
0
        public void CreateModel()
        {
            CommonEngine = new InferenceEngine();

            cyclist1 = new CyclistPrediction()
            {
                InferenceEngine = CommonEngine
            };
            cyclist1.CreateModel();
            cyclist2 = new CyclistPrediction()
            {
                InferenceEngine = CommonEngine
            };
            cyclist2.CreateModel();

            TimeDifference   = cyclist1.TomorrowsTime - cyclist2.TomorrowsTime;
            Cyclist1IsFaster = cyclist1.TomorrowsTime < cyclist2.TomorrowsTime;
        }