INFER 101 Sample 5 Question

• Question

• In sample 5 of the 101 examples, we see two cyclists being compared for the prediction of tomorrows cycling time.

I am trying to expand the example to 3 cyclists.  This is ok, however, how do predict if Cyclists 1's time for tomorrow is greater than Cyclist 2 and Cyclist 3 ?

Thanks

Sunday, October 14, 2012 9:06 AM

• The probabilities don't add up to 1 because the inference is approximate.  To guarantee that the probabilities add to 1 (though still approximate), you can introduce an explicit 'winner' variable and branch on it:

```Variable<int> winner = Variable.DiscreteUniform(3);
using(Variable.Case(winner,0)) {
Variable.ConstrainTrue(cyclist1.TomorrowsTime < cyclist3.TomorrowsTime & cyclist1.TomorrowsTime < cyclist2.TomorrowsTime);
}
using(Variable.Case(winner,1)) {
Variable.ConstrainTrue(cyclist2.TomorrowsTime < cyclist1.TomorrowsTime & cyclist2.TomorrowsTime < cyclist3.TomorrowsTime);
}
using(Variable.Case(winner,2)) {
Variable.ConstrainTrue(cyclist3.TomorrowsTime < cyclist1.TomorrowsTime & cyclist3.TomorrowsTime < cyclist2.TomorrowsTime);
}```

If you infer 'winner', you will get a normalized distribution over the 3 possibilities.  This technique is used in the multi-class Bayes Point Machine.
• Marked as answer by Tuesday, October 16, 2012 9:20 AM
Tuesday, October 16, 2012 9:14 AM

All replies

•
```Cyclist1IsFaster =
cyclist[0].TomorrowsTime < cyclist[1].TomorrowsTime &
cyclist[0].TomorrowsTime < cyclist[2].TomorrowsTime;```
Monday, October 15, 2012 3:29 PM
• Since the question is about the time being greater, you could compare to the max of the other two:

`Cyclist1IsSlower = cyclist[0].TomorrowsTime > Variable.Max(cyclist[1].TomorrowsTime, cyclist[2].TomorrowsTime);`

Monday, October 15, 2012 4:51 PM
• Thanks Tom and John for the answers.  Hopefully I haven't misled you by the way I have framed my question.  Essentially, what I am trying to do is imagining that tomorrow the three cyclists are going to race each other.  My goal is to find the probability of each cyclist winning.

So my training data is set up as follows :

double[] trainingData1 = new double[] { 29.70, 29.91, 29.71, 29.71, 29.86, 32.24 };
double[] trainingData2 = new double[] { 30.07, 32.42, 29.64, 30.49, 30.36, 29.71 };
double[] trainingData3 = new double[] { 30.02, 28.42, 29.74, 30.22, 29.36, 29.51 };

ModelData initPriors = new ModelData(Gaussian.FromMeanAndPrecision(30.0, 0.01), Gamma.FromShapeAndScale(2.0, 0.5));

Taking Johns example I then have the following code:

Cyclist1IsFaster = cyclist1.TomorrowsTime < cyclist3.TomorrowsTime & cyclist1.TomorrowsTime < cyclist2.TomorrowsTime;
Cyclist2IsFaster = cyclist2.TomorrowsTime < cyclist1.TomorrowsTime & cyclist2.TomorrowsTime < cyclist3.TomorrowsTime;
Cyclist3IsFaster = cyclist3.TomorrowsTime < cyclist1.TomorrowsTime & cyclist3.TomorrowsTime < cyclist2.TomorrowsTime;

Howver, I am confused by  the results. I get :

Cyclist1IsFaster = 0.1911

Cyclist2IsFaster = 0.1261

Cyclist3IsFaster = 0.4699

Why do the probabilities not add up to 1 ?  Someone has to win the race, so I would assume the probabilities should sum to 1.

Thanks for any insight you can give.

Tuesday, October 16, 2012 7:54 AM
• The probabilities don't add up to 1 because the inference is approximate.  To guarantee that the probabilities add to 1 (though still approximate), you can introduce an explicit 'winner' variable and branch on it:

```Variable<int> winner = Variable.DiscreteUniform(3);
using(Variable.Case(winner,0)) {
Variable.ConstrainTrue(cyclist1.TomorrowsTime < cyclist3.TomorrowsTime & cyclist1.TomorrowsTime < cyclist2.TomorrowsTime);
}
using(Variable.Case(winner,1)) {
Variable.ConstrainTrue(cyclist2.TomorrowsTime < cyclist1.TomorrowsTime & cyclist2.TomorrowsTime < cyclist3.TomorrowsTime);
}
using(Variable.Case(winner,2)) {
Variable.ConstrainTrue(cyclist3.TomorrowsTime < cyclist1.TomorrowsTime & cyclist3.TomorrowsTime < cyclist2.TomorrowsTime);
}```

If you infer 'winner', you will get a normalized distribution over the 3 possibilities.  This technique is used in the multi-class Bayes Point Machine.
• Marked as answer by Tuesday, October 16, 2012 9:20 AM
Tuesday, October 16, 2012 9:14 AM