# How to extend Bayesian Network from conditional distribution given two variables to three variables?

• ### Question

• Hello everyone,

I am new to infer.net. In my building Bayesian network, I would like to use number of cars, distance to work and income to simulate how people choose their transportation tool like by bike or car. However, the Bayesian network of WetgrassSprinklerRainCloudy example in infer.net packages use the conditional probability of wetgrass given on sprinkler or rain. This is cpt given one variable. In my case, I would like to use the conditional probability of tansportationmode given on the three variables above. My code is shown as below:

//random variable definition

public VariableArray<int> ifcar;
public VariableArray<int> distowork;
public VariableArray<int> income;
public VariableArray<int> trainsportationmode;
public Variable<int> NumberOfExamples;

public Variable<Vector> Probifcar;
public Variable<Vector> Probdistowork;
public Variable<Vector> Probincome;
public VariableArray3D<VariableArray<Vector>, Vector[][][]> CPTTrain_if_dist_in;

public Variable<Dirichlet> ProbifcarPrior;

public Variable<Dirichlet> ProbdistoworkPrior;
public Variable<Dirichlet> ProbincomePrior;
public VariableArray3D<VariableArray<Dirichlet>, Dirichlet[][][]> CPTTrain_if_dist_inPrior;

public Dirichlet ProbifcarPosterior;
public Dirichlet ProbdistoworkPosterior;
public Dirichlet ProbincomePosterior;
public Dirichlet[][][] CPTTrain_if_dist_inPosterior;

"CPTTrain_if_dist_inPrior = Variable.Array(Variable.New<Dirichlet>(car),dis,co).Named("CPTTrain_if_dist_inPrior");
CPTTrain_if_dist_in = Variable.Array(Variable.Array<Vector>(car),dis,co).Named("CPTTrain_if_dist_in");
CPTTrain_if_dist_in[co][dis][car] = Variable<Vector>.Random(CPTTrain_if_dist_inPrior[co][dis][car]);
CPTTrain_if_dist_in.SetValueRange(mode);"

This part code is always wrong. I think I don't know how to use "variable.Array()". Could you help me with this case. Thank you so much.

Friday, February 19, 2016 7:13 PM