public void CreateModel() { cyclist1 = new CyclistTraining(); cyclist1.CreateModel(); cyclist2 = new CyclistTraining(); cyclist2.CreateModel(); }
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); //Print the training results Console.WriteLine("Average travel time = {0:f2}", posteriors1.AverageTimeDist); Console.WriteLine("Traffic noise = {0:f2}", posteriors1.TrafficNoiseDist); 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 phase online learning double[] trainingData2 = new double[] { 17, 19, 18, 21, 15 }; cyclistTraining.SetModelData(posteriors1); ModelData posteriors2 = cyclistTraining.InferModelData(trainingData2); //Print the training results Console.WriteLine("Average travel time = {0:f2}", posteriors2.AverageTimeDist); Console.WriteLine("Traffic noise = {0:f2}", posteriors2.TrafficNoiseDist); 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.0) ); }