public double logValue (Assignment assn) {return subFactor.logValue (assn);}
public double logValue (int loc) {return subFactor.logValue (loc);}
public double logValue (AssignmentIterator it) {return subFactor.logValue (it);}
public double logValue (int loc) {return subFactor.logValue (loc);}
public double logValue (AssignmentIterator it) {return subFactor.logValue (it);}
public double logValue (Assignment assn) {return subFactor.logValue (assn);}
public double logValue (AssignmentIterator it) {return subFactor.logValue (it);}
public double logValue (int loc) {return subFactor.logValue (loc);}
public double logValue (Assignment assn) {return subFactor.logValue (assn);}
protected void divideByInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = prev - newVal; /* by convention, let -Inf + Inf (corresponds to 0/0) be -Inf */ if (Double.isInfinite (newVal)) { product = Double.NEGATIVE_INFINITY; } this.probs.setValueAtLocation (singleLoc, product); } Flops.increment (numLocs); // handle the pluses }
protected void divideByInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = prev - newVal; /* by convention, let -Inf + Inf (corresponds to 0/0) be -Inf */ if (Double.isInfinite (newVal)) { product = Double.NEGATIVE_INFINITY; } this.probs.setValueAtLocation (singleLoc, product); } Flops.increment (numLocs); // handle the pluses }
protected void divideByInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = prev - newVal; /* by convention, let -Inf + Inf (corresponds to 0/0) be -Inf */ if (Double.isInfinite (newVal)) { product = Double.NEGATIVE_INFINITY; } this.probs.setValueAtLocation (singleLoc, product); } Flops.increment (numLocs); // handle the pluses }
/** * Does the conceptual equivalent of this *= pot. * Assumes that pot's variables are a subset of * this potential's. */ protected void multiplyByInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = prev + newVal; this.probs.setValueAtLocation (singleLoc, product); } Flops.increment (numLocs); // handle the pluses }
/** * Does the conceptual equivalent of this *= pot. * Assumes that pot's variables are a subset of * this potential's. */ protected void multiplyByInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = prev + newVal; this.probs.setValueAtLocation (singleLoc, product); } Flops.increment (numLocs); // handle the pluses }
/** * Does the conceptual equivalent of this *= pot. * Assumes that pot's variables are a subset of * this potential's. */ protected void multiplyByInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = prev + newVal; this.probs.setValueAtLocation (singleLoc, product); } Flops.increment (numLocs); // handle the pluses }
/** * Does the conceptual equivalent of this += pot. * Assumes that pot's variables are a subset of * this potential's. */ protected void plusEqualsInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = Maths.sumLogProb (prev, newVal); this.probs.setValueAtLocation (singleLoc, product); } Flops.sumLogProb (numLocs); }
/** * Does the conceptual equivalent of this += pot. * Assumes that pot's variables are a subset of * this potential's. */ protected void plusEqualsInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = Maths.sumLogProb (prev, newVal); this.probs.setValueAtLocation (singleLoc, product); } Flops.sumLogProb (numLocs); }
/** * Does the conceptual equivalent of this += pot. * Assumes that pot's variables are a subset of * this potential's. */ protected void plusEqualsInternal (DiscreteFactor ptl) { int[] projection = largeIdxToSmall (ptl); int numLocs = probs.numLocations (); for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) { int smallIdx = projection[singleLoc]; double prev = this.probs.valueAtLocation (singleLoc); double newVal = ptl.logValue (smallIdx); double product = Maths.sumLogProb (prev, newVal); this.probs.setValueAtLocation (singleLoc, product); } Flops.sumLogProb (numLocs); }
public static TableFactor retainMass (DiscreteFactor ptl, double alpha) { int[] idxs = new int [ptl.numLocations ()]; double[] vals = new double [ptl.numLocations ()]; for (int i = 0; i < idxs.length; i++) { idxs[i] = ptl.indexAtLocation (i); vals[i] = ptl.logValue (i); } RankedFeatureVector rfv = new RankedFeatureVector (new Alphabet(), idxs, vals); TIntArrayList idxList = new TIntArrayList (); TDoubleArrayList valList = new TDoubleArrayList (); double mass = Double.NEGATIVE_INFINITY; double logAlpha = Math.log (alpha); for (int rank = 0; rank < rfv.numLocations (); rank++) { int idx = rfv.getIndexAtRank (rank); double val = rfv.value (idx); mass = Maths.sumLogProb (mass, val); idxList.add (idx); valList.add (val); if (mass > logAlpha) { break; } } int[] szs = computeSizes (ptl); SparseMatrixn m = new SparseMatrixn (szs, idxList.toNativeArray (), valList.toNativeArray ()); TableFactor result = new TableFactor (computeVars (ptl)); result.setValues (m); return result; }
public static TableFactor retainMass (DiscreteFactor ptl, double alpha) { int[] idxs = new int [ptl.numLocations ()]; double[] vals = new double [ptl.numLocations ()]; for (int i = 0; i < idxs.length; i++) { idxs[i] = ptl.indexAtLocation (i); vals[i] = ptl.logValue (i); } RankedFeatureVector rfv = new RankedFeatureVector (new Alphabet(), idxs, vals); TIntArrayList idxList = new TIntArrayList (); TDoubleArrayList valList = new TDoubleArrayList (); double mass = Double.NEGATIVE_INFINITY; double logAlpha = Math.log (alpha); for (int rank = 0; rank < rfv.numLocations (); rank++) { int idx = rfv.getIndexAtRank (rank); double val = rfv.value (idx); mass = Maths.sumLogProb (mass, val); idxList.add (idx); valList.add (val); if (mass > logAlpha) { break; } } int[] szs = computeSizes (ptl); SparseMatrixn m = new SparseMatrixn (szs, idxList.toNativeArray (), valList.toNativeArray ()); TableFactor result = new TableFactor (computeVars (ptl)); result.setValues (m); return result; }