Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to include more outcomes on Infer.NET's BPM?
    text
    copied!<p>How can I modify <a href="http://research.microsoft.com/infernet" rel="nofollow">Infer.NET</a>'s <a href="http://research.microsoft.com/en-us/um/cambridge/projects/infernet/docs/Bayes%20Point%20Machine%20tutorial.aspx" rel="nofollow">Tutorial 4: Bayes Point Machine</a> to include more outcomes?</p> <p>For example, how can I add willRent and get the separate probabilities for willBuy and willRent?</p> <pre><code> double[] incomes = { 63, 16, 28, 55, 22, 20 }; double[] ages = { 38, 23, 40, 27, 18, 40 }; bool[] willBuy = { true, false, true, true, false, false }; bool[] willRent = { false, false, true, false, true, false }; </code></pre> <p>Edit - Here's the example in copy/paste format:</p> <pre><code>static void Main() { double[] incomes = { 63, 16, 28, 55, 22, 20 }; double[] ages = { 38, 23, 40, 27, 18, 40 }; bool[] willBuy = { true, false, true, true, false, false }; // Create x vector, augmented by 1 Vector[] xdata = new Vector[incomes.Length]; for (int i = 0; i &lt; xdata.Length; i++) xdata[i] = Vector.FromArray(incomes[i], ages[i], 1); VariableArray&lt;Vector&gt; x = Variable.Observed(xdata); // Create target y VariableArray&lt;bool&gt; y = Variable.Observed(willBuy, x.Range); Variable&lt;Vector&gt; w = Variable.Random(new VectorGaussian(Vector.Zero(3), PositiveDefiniteMatrix.Identity(3))); Range j = y.Range; double noise = 0.1; y[j] = Variable.GaussianFromMeanAndVariance(Variable.InnerProduct(w, x[j]), noise) &gt; 0; InferenceEngine engine = new InferenceEngine(new ExpectationPropagation()); VectorGaussian wPosterior = engine.Infer&lt;VectorGaussian&gt;(w); Console.WriteLine("Dist over w=\n" + wPosterior); double[] incomesTest = { 58, 18, 22 }; double[] agesTest = { 36, 24, 37 }; VariableArray&lt;bool&gt; ytest = Variable.Array&lt;bool&gt;(new Range(agesTest.Length)); BayesPointMachine(incomesTest, agesTest, Variable.Random(wPosterior), ytest); Console.WriteLine("output=\n" + engine.Infer(ytest)); Console.ReadKey(); } static void BayesPointMachine(double[] incomes,double[] ages,Variable&lt;Vector&gt; w,VariableArray&lt;bool&gt; y) { // Create x vector, augmented by 1 Range j = y.Range; Vector[] xdata = new Vector[incomes.Length]; for (int i = 0; i &lt; xdata.Length; i++) xdata[i] = Vector.FromArray(incomes[i], ages[i], 1); VariableArray&lt;Vector&gt; x = Variable.Observed(xdata, j); // Bayes Point Machine double noise = 0.1; y[j] = Variable.GaussianFromMeanAndVariance(Variable.InnerProduct(w, x[j]), noise) &gt; 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload