Infer.NETのチュートリアル 4: ベイズ ポイント マシンを変更して、より多くの結果を含めるにはどうすればよいですか?
たとえば、どうすれば willRent を追加して、willBuy と willRent の個別の確率を取得できますか?
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 };
編集 - コピー/貼り付け形式の例を次に示します。
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 < xdata.Length; i++)
xdata[i] = Vector.FromArray(incomes[i], ages[i], 1);
VariableArray<Vector> x = Variable.Observed(xdata);
// Create target y
VariableArray<bool> y = Variable.Observed(willBuy, x.Range);
Variable<Vector> 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) > 0;
InferenceEngine engine = new InferenceEngine(new ExpectationPropagation());
VectorGaussian wPosterior = engine.Infer<VectorGaussian>(w);
Console.WriteLine("Dist over w=\n" + wPosterior);
double[] incomesTest = { 58, 18, 22 };
double[] agesTest = { 36, 24, 37 };
VariableArray<bool> ytest = Variable.Array<bool>(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<Vector> w,VariableArray<bool> y)
{
// Create x vector, augmented by 1
Range j = y.Range;
Vector[] xdata = new Vector[incomes.Length];
for (int i = 0; i < xdata.Length; i++)
xdata[i] = Vector.FromArray(incomes[i], ages[i], 1);
VariableArray<Vector> x = Variable.Observed(xdata, j);
// Bayes Point Machine
double noise = 0.1;
y[j] = Variable.GaussianFromMeanAndVariance(Variable.InnerProduct(w, x[j]), noise) > 0;
}