|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttuffy.infer.MRF
public class MRF
In-memory data structure representing an MRF.
Nested Class Summary | |
---|---|
static class |
MRF.INIT_STRATEGY
|
Field Summary | |
---|---|
protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<GClause>> |
adj
Index from GAtom ID to GClause. |
java.util.HashMap<java.lang.Integer,GAtom> |
atoms
Map from GAtom ID to GAtom object. |
java.util.HashMap<java.lang.String,java.lang.Long> |
clauseNiNjViolationTallies
This map records the tallies for calculating E(v_i*v_j). |
java.util.ArrayList<GClause> |
clauses
Array of all GClause objects in this MRF. |
java.util.HashMap<java.lang.String,java.lang.Long> |
clauseSatTallies
This array records total number of satisfaction for a clause. |
java.util.HashMap<java.lang.String,java.lang.Long> |
clauseSquareVioTallies
This array records total number of square violation for a clause. |
java.util.HashMap<java.lang.String,java.lang.Long> |
clauseVioTallies
This array records total number of violation for a clause. |
protected java.util.HashSet<java.lang.Integer> |
dirtyAtoms
Atoms that have been flipped since last saving to low. |
java.util.HashMap<java.lang.String,java.lang.Double> |
expectationOfNiNjViolation
This map records the expectation of E(v_i*v_j). |
java.util.HashMap<java.lang.String,java.lang.Double> |
expectationOfSatisfication
This array records the expection of #satisfaction for each clause. |
java.util.HashMap<java.lang.String,java.lang.Double> |
expectationOfSquareViolation
This map records the expectation of square #violation for each clause. |
java.util.HashMap<java.lang.String,java.lang.Double> |
expectationOfViolation
This map records the expectation of #violation for each clause. |
long |
inferOps
|
protected MRF.INIT_STRATEGY |
initStrategy
|
KeyBlock |
keyBlock
|
double |
lowCost
Lowest cost ever seen. |
boolean |
ownsAllAtoms
|
protected boolean |
sampleSatMode
The flag indicating whether MCSAT is running WalkSAT or SampleSAT. |
protected int |
totalAlive
Number of GClauses that is selected, and therefore must be satisfied by next SampleSAT invocation of MCSAT. |
protected double |
totalCost
The total cost of this MRF under current atoms' truth setting. |
protected HashArray<GClause> |
unsat
Array of unsatisfied GClauses under current atoms' truth setting. |
Constructor Summary | |
---|---|
MRF(MarkovLogicNetwork mln)
Default constructor. |
|
MRF(MarkovLogicNetwork mln,
int partID,
java.util.HashMap<java.lang.Integer,GAtom> gatoms)
|
Method Summary | |
---|---|
void |
addAtom(int aid)
Add an atom into this MRF. |
void |
auditClauseViolations()
Track ground clause violations to fo-clauses. |
protected void |
buildIndices()
Build literal-->clauses index. |
protected double |
calcCosts()
Compute total cost and per-atom delta cost. |
void |
calcExpViolation()
Calculating the different expectations by filling the HashMaps related to expectations in this class. |
void |
discard()
Discard all data structures, in hope of facilitating faster GC. |
protected void |
enableAllClauses()
Reset all clauses to be alive. |
protected void |
fixAtom(int aid,
boolean t)
Fix the truth value of an atom. |
java.util.HashSet<java.lang.Integer> |
getCoreAtoms()
|
double |
getCost()
|
MRF.INIT_STRATEGY |
getInitStrategy()
|
MarkovLogicNetwork |
getMLN()
|
void |
inferWalkSAT(int nTries,
int nSteps)
Run WalkSAT. |
void |
initMRF()
Initialize the state of the MRF. |
void |
invalidateLowCost()
Reset low-cost to infinity. |
protected boolean |
isAlwaysTrue(GClause gc)
Test if a clause is always true no matter how we flip flippable atoms. |
protected boolean |
isTrueLit(int lit)
Check if a given literal is true under current truth assignment. |
void |
mcsat(int numSamples,
int numFlips)
Execute the MC-SAT algorithm. |
protected boolean |
ownsAtom(int aid)
Test if a given atom is "owned" by this MRF. |
double |
recalcCost()
Recalculate total cost. |
void |
restoreLowTruth()
Assign the recorded low-cost truth values to current truth values. |
protected int |
retainOnlyHardClauses()
Kill soft clauses. |
protected int |
retainSomeGoodClauses()
Retain a subset of currently satisfied clauses, according to the sampling method of MC-SAT. |
protected boolean |
sampleSAT(int nSteps)
SampleSAT (with WalkSAT inside), used to uniformly sample a zero-cost world. |
protected void |
saveLowTruth(double cost)
If current truths have the lowest cost, save them. |
void |
setInitStrategy(MRF.INIT_STRATEGY strategy)
|
protected boolean |
testChance(double p)
Coin flipping. |
protected void |
unfixAllAtoms()
Unfix all atoms. |
void |
updateAtomMarginalProbs(int numSamples)
|
void |
updateClauseVoiTallies()
Update the number of violations of a clause. |
void |
updateClauseWeights(java.util.HashMap<java.lang.String,java.lang.Double> currentWeight)
Change the weight of GClause based on updated weight of Clause. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<GClause>> adj
public java.util.HashMap<java.lang.Integer,GAtom> atoms
public java.util.HashMap<java.lang.String,java.lang.Long> clauseNiNjViolationTallies
public java.util.ArrayList<GClause> clauses
public java.util.HashMap<java.lang.String,java.lang.Long> clauseSatTallies
public java.util.HashMap<java.lang.String,java.lang.Long> clauseSquareVioTallies
MCSAT#nClauseVioTallies
will give the estimated expectation of #violation.
public java.util.HashMap<java.lang.String,java.lang.Long> clauseVioTallies
MCSAT#nClauseVioTallies
will give the estimated expectation of #violation.
protected java.util.HashSet<java.lang.Integer> dirtyAtoms
public java.util.HashMap<java.lang.String,java.lang.Double> expectationOfNiNjViolation
MCSAT#calcExpViolation()
.
public java.util.HashMap<java.lang.String,java.lang.Double> expectationOfSatisfication
MCSAT#calcExpViolation()
.
public java.util.HashMap<java.lang.String,java.lang.Double> expectationOfSquareViolation
MCSAT#calcExpViolation()
.
public java.util.HashMap<java.lang.String,java.lang.Double> expectationOfViolation
MCSAT#calcExpViolation()
.
public long inferOps
protected MRF.INIT_STRATEGY initStrategy
public KeyBlock keyBlock
public double lowCost
public boolean ownsAllAtoms
protected boolean sampleSatMode
protected int totalAlive
protected double totalCost
protected HashArray<GClause> unsat
Constructor Detail |
---|
public MRF(MarkovLogicNetwork mln)
public MRF(MarkovLogicNetwork mln, int partID, java.util.HashMap<java.lang.Integer,GAtom> gatoms)
partID
- id of this MRFgatoms
- ground atomsMethod Detail |
---|
public void addAtom(int aid)
aid
- id of the atompublic void auditClauseViolations()
Stats.reportMostViolatedClauses(tuffy.infer.MRF, int)
protected void buildIndices()
protected double calcCosts()
public void calcExpViolation()
public void discard()
protected void enableAllClauses()
protected void fixAtom(int aid, boolean t)
aid
- id of the atomt
- truth value to be fixedpublic java.util.HashSet<java.lang.Integer> getCoreAtoms()
public double getCost()
public MRF.INIT_STRATEGY getInitStrategy()
public MarkovLogicNetwork getMLN()
public void inferWalkSAT(int nTries, int nSteps)
nTries
- number of triesnSteps
- number of steps per trypublic void initMRF()
public void invalidateLowCost()
protected boolean isAlwaysTrue(GClause gc)
gc
- the clauseprotected boolean isTrueLit(int lit)
lit
- the literal represented as an integerpublic void mcsat(int numSamples, int numFlips)
numSamples
- number of MC-SAT samplesnumFlips
- number of SampleSAT steps in each iterationprotected boolean ownsAtom(int aid)
aid
- id of the atompublic double recalcCost()
public void restoreLowTruth()
protected int retainOnlyHardClauses()
protected int retainSomeGoodClauses()
protected boolean sampleSAT(int nSteps)
nSteps
-
protected void saveLowTruth(double cost)
cost
- the current costpublic void setInitStrategy(MRF.INIT_STRATEGY strategy)
protected boolean testChance(double p)
p
- probability of returning trueprotected void unfixAllAtoms()
public void updateAtomMarginalProbs(int numSamples)
public void updateClauseVoiTallies()
public void updateClauseWeights(java.util.HashMap<java.lang.String,java.lang.Double> currentWeight)
currentWeight
- The weight of clauses to be flushed
in this MCSAT instance.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |