|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tuffy.infer.MRF
public class MRF
In-memory data structure representing an MRF.
Nested Class Summary | |
---|---|
static class |
MRF.INIT_STRATEGY
|
private class |
MRF.myInt
|
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. |
private java.util.HashSet<java.lang.Integer> |
coreAtoms
|
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. |
private MarkovLogicNetwork |
mln
The MLN object. |
private int |
nClauseVioTallies
Number of iterations of tallies. |
(package private) int |
numClausesInCut
|
(package private) int |
numCriticalNodesLocal
|
boolean |
ownsAllAtoms
|
(package private) int |
partID
|
private java.util.Random |
rand
|
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. |
private boolean |
usingBlocks
|
(package private) double |
weightClausesInCut
|
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. |
private void |
adjustAtomClauseRelation(java.util.ArrayList<GClause> tlfac,
java.util.ArrayList<GClause> flfac,
int picked)
|
private void |
assignAllFalseTruthValues()
Set all atoms to false. |
private void |
assignGreedyTruthValues()
Assign inital truth values according to some ad hoc and heuristic stats. |
private void |
assignRandomTruthValues()
Set random atom truth values. |
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. |
private double |
calcCostsForWalkSAT(java.util.HashSet<java.lang.Integer> needToBeReset)
|
void |
calcExpViolation()
Calculating the different expectations by filling the HashMaps related to expectations in this class. |
private void |
calcNSAT(GClause f)
Calculate the number of true literals in a clause. |
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. |
private java.util.HashSet<java.lang.Integer> |
getAtomNeighbors(int aid)
For research experiments! Get all neighboring atoms of one atom. |
java.util.HashSet<java.lang.Integer> |
getCoreAtoms()
|
double |
getCost()
|
private java.util.ArrayList<GAtom> |
getFlipSequence(GAtom a)
|
MRF.INIT_STRATEGY |
getInitStrategy()
|
MarkovLogicNetwork |
getMLN()
|
void |
inferSweepSAT(int nTries,
int nSteps)
Deprecated. |
void |
inferWalkSAT(int nTries,
int nSteps)
Run WalkSAT. |
private void |
inferWalkSATwithBlocks(int nTries,
int nSteps)
Run WalkSAT with blocks. |
private void |
inferWalkSATwithoutBlocking(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. |
private void |
maintainKeyConstraints()
|
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. |
private void |
performMCSatStep(int numFlips)
Perform one sample of MC-SAT |
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. |
private void |
saveTruthAsLow()
|
void |
setInitStrategy(MRF.INIT_STRATEGY strategy)
|
private java.util.ArrayList<MRF> |
split(int np)
For research experiments! Split the MRF into multiple pieces by agglomerative clustering. |
protected boolean |
testChance(double p)
Coin flipping. |
private void |
testKeyConstraints()
|
protected void |
unfixAllAtoms()
Unfix all atoms. |
private void |
unitPropagation()
Try to satisfy as many clauses as possible with unit propagation. |
void |
updateAtomMarginalProbs(int numSamples)
|
private void |
updateAtomTruthTallies()
For each atom, increment its truth tally by one if it's currently true. |
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 MRF.INIT_STRATEGY initStrategy
public KeyBlock keyBlock
public java.util.HashMap<java.lang.Integer,GAtom> atoms
public boolean ownsAllAtoms
private boolean usingBlocks
private java.util.HashSet<java.lang.Integer> coreAtoms
public java.util.ArrayList<GClause> clauses
protected HashArray<GClause> unsat
protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<GClause>> adj
int numCriticalNodesLocal
int numClausesInCut
double weightClausesInCut
protected java.util.HashSet<java.lang.Integer> dirtyAtoms
protected double totalCost
public double lowCost
protected int totalAlive
protected boolean sampleSatMode
int partID
public long inferOps
private MarkovLogicNetwork mln
private java.util.Random rand
public java.util.HashMap<java.lang.String,java.lang.Double> expectationOfViolation
MCSAT#calcExpViolation()
.
public java.util.HashMap<java.lang.String,java.lang.Double> expectationOfSquareViolation
MCSAT#calcExpViolation()
.
public java.util.HashMap<java.lang.String,java.lang.Long> clauseNiNjViolationTallies
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.Long> clauseVioTallies
MCSAT#nClauseVioTallies
will give the estimated expectation of #violation.
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> clauseSatTallies
private int nClauseVioTallies
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 MRF.INIT_STRATEGY getInitStrategy()
public void setInitStrategy(MRF.INIT_STRATEGY strategy)
public double getCost()
public MarkovLogicNetwork getMLN()
public void invalidateLowCost()
private java.util.ArrayList<MRF> split(int np)
np
- number of pieces
private java.util.HashSet<java.lang.Integer> getAtomNeighbors(int aid)
aid
- id of the core atom
public void discard()
public void addAtom(int aid)
aid
- id of the atomprotected boolean ownsAtom(int aid)
aid
- id of the atomprotected void saveLowTruth(double cost)
cost
- the current costprivate void saveTruthAsLow()
protected boolean isTrueLit(int lit)
lit
- the literal represented as an integerprotected boolean isAlwaysTrue(GClause gc)
gc
- the clauseprotected void fixAtom(int aid, boolean t)
aid
- id of the atomt
- truth value to be fixedprotected int retainSomeGoodClauses()
protected void unfixAllAtoms()
public void restoreLowTruth()
protected void enableAllClauses()
protected void buildIndices()
protected boolean testChance(double p)
p
- probability of returning trueprivate void testKeyConstraints()
public void inferWalkSAT(int nTries, int nSteps)
nTries
- number of triesnSteps
- number of steps per tryprivate void inferWalkSATwithoutBlocking(int nTries, int nSteps)
nTries
- number of triesnSteps
- number of steps per tryprivate void inferWalkSATwithBlocks(int nTries, int nSteps)
nTries
- number of triesnSteps
- number of steps per tryprivate void adjustAtomClauseRelation(java.util.ArrayList<GClause> tlfac, java.util.ArrayList<GClause> flfac, int picked)
public void inferSweepSAT(int nTries, int nSteps)
nTries
- number of triesnSteps
- number of steps per trypublic void initMRF()
private void maintainKeyConstraints()
private void assignAllFalseTruthValues()
private void assignRandomTruthValues()
private void assignGreedyTruthValues()
private void calcNSAT(GClause f)
f
- private java.util.ArrayList<GAtom> getFlipSequence(GAtom a)
protected double calcCosts()
private double calcCostsForWalkSAT(java.util.HashSet<java.lang.Integer> needToBeReset)
public void auditClauseViolations()
Stats.reportMostViolatedClauses(tuffy.infer.MRF, int)
public double recalcCost()
public java.util.HashSet<java.lang.Integer> getCoreAtoms()
protected int retainOnlyHardClauses()
protected boolean sampleSAT(int nSteps)
nSteps
-
public void updateAtomMarginalProbs(int numSamples)
private void updateAtomTruthTallies()
public void mcsat(int numSamples, int numFlips)
numSamples
- number of MC-SAT samplesnumFlips
- number of SampleSAT steps in each iterationpublic void updateClauseVoiTallies()
public void calcExpViolation()
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.private void performMCSatStep(int numFlips)
numFlips
- number of sampleSAT flipsprivate void unitPropagation()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |