public override void AddParents(int numberOfEntries) { Observed = Variable.Array <int>(N).Named(node.name); Observed.SetValueRange(node.states); Range parentRange = new Range(node.parents.Count); x = Variable.Array <Vector>(N).Named("x" + node.name); for (int ii = 0; ii < numberOfEntries; ii++) { VariableArray <double> row = Variable <double> .Array(parentRange); for (int jj = 0; jj < node.parents.Count; jj++) { row[jj] = Variable.GaussianFromMeanAndPrecision((node.parents[jj].distributions.ObservedNumerical[ii]), 1); } x[ii] = Variable.Vector(row); } var g = Variable.Array(Variable.Array <double>(node.states), N).Named("g" + node.name); g[N][node.states] = Variable.InnerProduct(B[node.states], (x[N])) + m[node.states]; var p = Variable.Array <Vector>(N).Named("p" + node.name); p[N] = Variable.Softmax(g[N]); using (Variable.ForEach(N)) Observed[N] = Variable.Discrete(p[N]); }
public override void AddParents(int numberOfEntries) { Observed = Variable.Array <int>(N).Named(node.name); Observed.SetValueRange(node.states); Range parentRange = new Range(node.parents.Count - 1); Range parentStates = null; foreach (var parent in node.parents) { if (parent.distributionType == DistributionType.Categorical) { parentStates = parent.states; } } x = Variable.Array <Vector>(N).Named("x" + node.name); for (int ii = 0; ii < numberOfEntries; ii++) { VariableArray <double> row = Variable <double> .Array(parentRange).Named(node.name + "row" + ii); int offset = 0; for (int jj = 0; jj < node.parents.Count; jj++) { if (node.parents[jj].distributionType == DistributionType.Categorical) { offset = -1; } else { row[jj + offset] = Variable.GaussianFromMeanAndPrecision((node.parents[jj].distributions.ObservedNumerical[ii]), 1); } } x[ii] = Variable.Vector(row); } var g = Variable.Array(Variable.Array(Variable.Array <double>(node.states), N), parentStates).Named("g" + node.name); g[parentStates][N][node.states] = Variable.InnerProduct(B[node.states][parentStates], (x[N])) + m[node.states][parentStates]; var p = Variable.Array(Variable.Array <Vector>(N), parentStates).Named("p" + node.name); p[parentStates][N] = Variable.Softmax(g[parentStates][N]); if (node.name == "doorGoTo") { bool stophere = true; } VariableArray <int> parentObserved = null; foreach (var parent in node.parents) { if (parent.distributionType == DistributionType.Categorical) { parentObserved = parent.distributions.Observed; } } using (Variable.ForEach(N)) using (Variable.Switch(parentObserved[N])) Observed[N] = Variable.Discrete(p[parentObserved[N]][N]); }