gpt4 book ai didi

machine-learning - 如何在 Infer.NET 的 BPM 中包含更多结果?

转载 作者:行者123 更新时间:2023-11-30 08:32:23 25 4
gpt4 key购买 nike

如何修改Infer.NETTutorial 4: Bayes Point Machine包含更多结果?

例如,如何添加 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;
}

最佳答案

这里有 4 个变量。

                   Will Buy?
^ ^
/ \
Age Income
\ /
v v
Will Rent?

给定(年龄,收入)将购买将租赁是自变量,即conditional independent

这样您就可以构建两个单独的贝叶斯点机:

  • 一项针对年龄收入意愿租房
  • 一项针对年龄收入意愿购买

关于machine-learning - 如何在 Infer.NET 的 BPM 中包含更多结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13421692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com