public Variable[] toVariableArray () { return subVarSet.toVariableArray (); }
/** * Creates a potential with the given variables and * the given probabilities. * * @param allVars Variables of the potential * @param probs All phi values of the potential, in row-major order. */ public AbstractTableFactor (VarSet allVars, double[] probs) { initVars (allVars.toVariableArray ()); setProbs (probs); }
/** * Creates a potential with the given variables and * the given probabilities. * * @param allVars Variables of the potential * @param probs All phi values of the potential, in row-major order. */ public AbstractTableFactor (VarSet allVars, double[] probs) { initVars (allVars.toVariableArray ()); setProbs (probs); }
/** * Creates a potential with the given variables and * the given probabilities. * * @param allVars Variables of the potential * @param probsIn All the phi values of the potential. */ public AbstractTableFactor (VarSet allVars, Matrix probsIn) { initVars (allVars.toVariableArray ()); probs = (Matrix) probsIn.cloneMatrix (); }
/** * Creates a potential with the given variables and * the given probabilities. * * @param allVars Variables of the potential * @param probs All phi values of the potential, in row-major order. */ public AbstractTableFactor (VarSet allVars, double[] probs) { initVars (allVars.toVariableArray ()); setProbs (probs); }
/** * Creates a potential with the given variables and * the given probabilities. * * @param allVars Variables of the potential * @param probsIn All the phi values of the potential. */ public AbstractTableFactor (VarSet allVars, Matrix probsIn) { initVars (allVars.toVariableArray ()); probs = (Matrix) probsIn.cloneMatrix (); }
private Factor sliceForAlpha (Assignment assn) { double alph = assn.getDouble (alpha); int[] sizes = sizesFromVarSet (xs); Matrix diag = Matrices.diag (sizes, alph); Matrix matrix = Matrices.constant (sizes, -alph); matrix.plusEquals (diag); return LogTableFactor.makeFromLogMatrix (xs.toVariableArray (), (SparseMatrixn) matrix); }
private Factor sliceForAlpha (Assignment assn) { double alph = assn.getDouble (alpha); int[] sizes = sizesFromVarSet (xs); Matrix diag = Matrices.diag (sizes, alph); Matrix matrix = Matrices.constant (sizes, -alph); matrix.plusEquals (diag); return LogTableFactor.makeFromLogMatrix (xs.toVariableArray (), (SparseMatrixn) matrix); }
private Factor sliceForAlpha (Assignment assn) { double alph = assn.getDouble (alpha); int[] sizes = sizesFromVarSet (xs); Matrix diag = Matrices.diag (sizes, alph); Matrix matrix = Matrices.constant (sizes, -alph); matrix.plusEquals (diag); return LogTableFactor.makeFromLogMatrix (xs.toVariableArray (), (SparseMatrixn) matrix); }
public void testValue () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); Assignment assn = new Assignment (fg.varSet ().toVariableArray (), new int[] { 0, 1, 0 }); assertEquals (0.08, fg.value (assn), 1e-5); }
public void testValue () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); Assignment assn = new Assignment (fg.varSet ().toVariableArray (), new int[] { 0, 1, 0 }); assertEquals (0.08, fg.value (assn), 1e-5); }
public Assignment sample (FactorGraph mdl, int N) { JunctionTreeInferencer jti = new JunctionTreeInferencer (); jti.computeMarginals (mdl); JunctionTree jt = jti.lookupJunctionTree (); VarSet vs = mdl.varSet (); Assignment assns = new Assignment (); for (int i = 0; i < N; i++) { Assignment assn = sampleOneAssn (jt); assns.addRow (vs.toVariableArray (), reorderCols (assn, vs)); } return assns; }
public Assignment sample (FactorGraph mdl, int N) { JunctionTreeInferencer jti = new JunctionTreeInferencer (); jti.computeMarginals (mdl); JunctionTree jt = jti.lookupJunctionTree (); VarSet vs = mdl.varSet (); Assignment assns = new Assignment (); for (int i = 0; i < N; i++) { Assignment assn = sampleOneAssn (jt); assns.addRow (vs.toVariableArray (), reorderCols (assn, vs)); } return assns; }
public void testRedundantDomains () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); fg.multiplyBy (ltbl1); assertEquals (3, fg.varSet ().size ()); assertEquals ("Wrong factors in FG, was "+fg.dumpToString (), 3, fg.factors ().size ()); Assignment assn = new Assignment (fg.varSet ().toVariableArray (), new int [3]); assertEquals (0.128, fg.value (assn), 1e-5); }
public void testRedundantDomains () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); fg.multiplyBy (ltbl1); assertEquals (3, fg.varSet ().size ()); assertEquals ("Wrong factors in FG, was "+fg.dumpToString (), 3, fg.factors ().size ()); Assignment assn = new Assignment (fg.varSet ().toVariableArray (), new int [3]); assertEquals (0.128, fg.value (assn), 1e-5); }
public void testTableTimesFg () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); Factor product = tbl3.multiply (fg); assertTrue (product instanceof AbstractTableFactor); assertEquals (4, product.varSet ().size ()); Assignment assn = new Assignment (product.varSet ().toVariableArray (), new int [4]); assertEquals (0.032, product.value (assn), 1e-5); }
protected Factor slice_general (Variable[] vars, Assignment observed) { VarSet toKeep = new HashVarSet (vars); toKeep.removeAll (observed.varSet ()); double[] vals = new double [toKeep.weight ()]; AssignmentIterator it = toKeep.assignmentIterator (); while (it.hasNext ()) { Assignment union = Assignment.union (observed, it.assignment ()); vals[it.indexOfCurrentAssn ()] = logValue (union); it.advance (); } return LogTableFactor.makeFromLogValues (toKeep.toVariableArray (), vals); }
public void testLogTableTimesFg () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); Factor product = ltbl1.multiply (fg); assertTrue (product instanceof AbstractTableFactor); assertEquals (3, product.varSet ().size ()); Assignment assn = new Assignment (product.varSet ().toVariableArray (), new int [3]); assertEquals (0.128, product.value (assn), 1e-5); }
public void testTableTimesFg () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); Factor product = tbl3.multiply (fg); assertTrue (product instanceof AbstractTableFactor); assertEquals (4, product.varSet ().size ()); Assignment assn = new Assignment (product.varSet ().toVariableArray (), new int [4]); assertEquals (0.032, product.value (assn), 1e-5); }
public void testLogTableTimesFg () { FactorGraph fg = new FactorGraph (); fg.multiplyBy (tbl1); fg.multiplyBy (tbl2); Factor product = ltbl1.multiply (fg); assertTrue (product instanceof AbstractTableFactor); assertEquals (3, product.varSet ().size ()); Assignment assn = new Assignment (product.varSet ().toVariableArray (), new int [3]); assertEquals (0.128, product.value (assn), 1e-5); }