infer
Class MRF

java.lang.Object
  extended by infer.MRF
Direct Known Subclasses:
MCSAT

public class MRF
extends java.lang.Object

In-memory data structure representing an MRF.


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.ArrayList<GClause> clauses
          Array of all GClause objects in this MRF.
protected  java.util.HashSet<java.lang.Integer> dirtyAtoms
           
 java.lang.String fout
          Name of output file.
 long inferOps
           
 double lowCost
          Lowest cost ever seen.
 MarkovLogicNetwork mln
          The MLN object.
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()
          Default constructor.
MRF(int id, 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.
 void buildIndices()
          Build literal-->clauses index.
 double calcCosts()
          Compute total cost and per-atom delta cost.
 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.
 void flushLowTruth(RDB db)
          Flush lowest-cost truth assignment to the database.
 void inferSweepSAT(int nTries, int nSteps)
          Run SweepSAT for MAP inference.
 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 loadMRF(RDB db)
          Load the entire grounding result into memory as an MRF.
protected  boolean ownsAtom(int aid)
          Test if a given atom is "owned" by this MRF.
 double recalcCost()
          Recalculate total cost.
protected  void restoreLowTruth()
          Assign the recorded low-cost truth values to current truth values.
protected  int retainSomeGoodClauses()
          Retain a subset of currently satisfied clauses, according to the sampling method of MC-SAT.
 void saveLowTruth(double cost)
          If current truths have the lowest cost, save them.
protected  boolean testChance(double p)
          Coin flipping.
protected  void unfixAllAtoms()
          Unfix all atoms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adj

protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<GClause>> adj
Index from GAtom ID to GClause.


atoms

public java.util.HashMap<java.lang.Integer,GAtom> atoms
Map from GAtom ID to GAtom object.


clauses

public java.util.ArrayList<GClause> clauses
Array of all GClause objects in this MRF.


dirtyAtoms

protected java.util.HashSet<java.lang.Integer> dirtyAtoms

fout

public java.lang.String fout
Name of output file.


inferOps

public long inferOps

lowCost

public double lowCost
Lowest cost ever seen.


mln

public MarkovLogicNetwork mln
The MLN object.


sampleSatMode

protected boolean sampleSatMode
The flag indicating whether MCSAT is running WalkSAT or SampleSAT.


totalAlive

protected int totalAlive
Number of GClauses that is selected, and therefore must be satisfied by next SampleSAT invocation of MCSAT.


totalCost

protected double totalCost
The total cost of this MRF under current atoms' truth setting.


unsat

protected HashArray<GClause> unsat
Array of unsatisfied GClauses under current atoms' truth setting.

Constructor Detail

MRF

public MRF()
Default constructor. Does not really do anything.


MRF

public MRF(int id,
           java.util.HashMap<java.lang.Integer,GAtom> gatoms)
Parameters:
id - id of this MRF
gatoms - ground atoms
Method Detail

addAtom

public void addAtom(int aid)
Add an atom into this MRF.

Parameters:
aid - id of the atom

auditClauseViolations

public void auditClauseViolations()
Track ground clause violations to fo-clauses. Stats are records on a per fo-clause basis.

See Also:
Stats.reportMostViolatedClauses(infer.MRF, int)

buildIndices

public void buildIndices()
Build literal-->clauses index. Used by WalkSAT.


calcCosts

public double calcCosts()
Compute total cost and per-atom delta cost. The delta cost of an atom is the change in the total cost if this atom is flipped.

Returns:
total cost

discard

public void discard()
Discard all data structures, in hope of facilitating faster GC.


enableAllClauses

protected void enableAllClauses()
Reset all clauses to be alive.


fixAtom

protected void fixAtom(int aid,
                       boolean t)
Fix the truth value of an atom.

Parameters:
aid - id of the atom
t - truth value to be fixed

flushLowTruth

public void flushLowTruth(RDB db)
Flush lowest-cost truth assignment to the database.

Parameters:
db -

inferSweepSAT

public void inferSweepSAT(int nTries,
                          int nSteps)
Run SweepSAT for MAP inference.

Parameters:
nTries - number of tries
nSteps - number of steps per try

inferWalkSAT

public void inferWalkSAT(int nTries,
                         int nSteps)
Run WalkSAT.

Parameters:
nTries - number of tries
nSteps - number of steps per try

initMRF

public void initMRF()
Initialize the state of the MRF.


invalidateLowCost

public void invalidateLowCost()
Reset low-cost to infinity.


isAlwaysTrue

protected boolean isAlwaysTrue(GClause gc)
Test if a clause is always true no matter how we flip flippable atoms.

Parameters:
gc - the clause

isTrueLit

protected boolean isTrueLit(int lit)
Check if a given literal is true under current truth assignment.

Parameters:
lit - the literal represented as an integer

loadMRF

public void loadMRF(RDB db)
Load the entire grounding result into memory as an MRF. Also build the atom-clause index.

Parameters:
db - the DB connection where the data resides

ownsAtom

protected boolean ownsAtom(int aid)
Test if a given atom is "owned" by this MRF. An atom may not belong to this MRF if this MRF represents a partition of a component that has multiple partitions.

Parameters:
aid - id of the atom

recalcCost

public double recalcCost()
Recalculate total cost.

Returns:
updated total cost

restoreLowTruth

protected void restoreLowTruth()
Assign the recorded low-cost truth values to current truth values.


retainSomeGoodClauses

protected int retainSomeGoodClauses()
Retain a subset of currently satisfied clauses, according to the sampling method of MC-SAT.

Returns:
the number of retained clauses

saveLowTruth

public void saveLowTruth(double cost)
If current truths have the lowest cost, save them.

Parameters:
cost - the current cost

testChance

protected boolean testChance(double p)
Coin flipping.

Parameters:
p - probability of returning true

unfixAllAtoms

protected void unfixAllAtoms()
Unfix all atoms.