edu.ucla.belief.recursiveconditioning
Class RC

Object
  extended by RC
All Implemented Interfaces:
KnowledgeBase.KnowledgeBaseListener
Direct Known Subclasses:
RCDgraph, RCDtree

public abstract class RC
extends Object
implements KnowledgeBase.KnowledgeBaseListener

This abstract class helps with removing code from the RCDgraph and RCDtree classes.

Author:
David Allen

Nested Class Summary
static class RC.RCCounters
           
static class RC.RCCreationException
           
static class RC.RCCreationParams
           
 class RC.RCStats
           
 class RC.RCStats_All
          Handle storing and computing computational statistics based on doing All computations (on graphs it would be for all marginals, and for trees it would be the same as Pe).
 class RC.RCStats_Pe
          Handle storing and computing computational statistics based on doing Pe computations.
static interface RC.RecCondThreadListener
           
 
Field Summary
 boolean allowKB
           
 RC.RCCounters counters
           
static boolean DEBUG_RC_CALC
           
static boolean DEBUG_RC_EVID
           
static double DOUBLE_OUTOFMEMORY
           
 PrintWriter outputConsole
           
 double scalar
           
static String STR_EXCEPTION_EVIDENCE
           
static String STR_OUTOFMEMORY_MSG
           
static String STR_STACKOVERFLOW_MSG
           
static boolean TODO_REMOVE_DO_EXTRA_LOOKAHEAD
           
static boolean TODO_REMOVE_DO_INDEX_CACHING_DURING_CREATION
          This variable needs to be set during RC creation and stay the same during computations!
static boolean TODO_REMOVE_DO_LEAF_CACHING_DURING_CREATION
          This variable is only used during RC creation, not dynamically!
static boolean TODO_REMOVE_DO_LOOKAHEAD_LOWERBOUND
           
static boolean TODO_REMOVE_DO_PROP_UP
           
static boolean TODO_REMOVE_REVERSE_ORDER
           
 MappedList vars
           
 
Constructor Summary
RC(RC.RCCreationParams params)
          RC Object constructor.
 
Method Summary
 double allContexts()
           
 double allContextsMinusLeafs()
           
 void allocRCCaches()
           
 void allocRCMPE3Caches()
           
 void allocRCMPE4Caches()
           
 void allocRCMPECaches()
           
 void assertLearnedPositive(int fv, int state)
          This is called if the KB learns about a variable from unit propagation, and was not told about this from the user.
 void assertUnLearnedPositive(int fv)
          Called when transitioning from 1 possible state to two possibe states (for any variable, whether the KB learned it or was told it).
 boolean canComputeFamilyMarginals()
           
 void clearKB()
           
static long collOfFinVarsToStateSpace(Collection col)
          Will return the state space of all the variables in the collection, and if the collection is empty it will return 1.
 void createKB()
           
 int[] generateNumParents(MappedList nds)
          Will not change nds if it is non-null & non-empty
abstract  RCNode getAnyRoot()
           
 Map getCFMap()
           
 RCIterator getIterator()
           
 RCIterator getIteratorParentChild()
           
abstract  RCIterator getIteratorRoots()
           
abstract  RCIteratorTraversal getIteratorTraversal()
           
abstract  RCIterator getIteratorTree()
           
 RCNode[] getRoots()
           
 String getStatistics()
           
 String getStatistics(boolean shortStr)
           
abstract  String getTagName()
           
 Thread getThreadRunning()
           
static Collection getVars(Collection A)
          Get all the vars contained within a collection of RCNodes.
static Collection getVars(Collection A, Collection ret)
          Get all the vars contained within a collection of RCNodes.
 boolean isRunning()
           
 void kbCallAssertOnVar(int fv)
           
 void kbDontCallAssertOnVar(int fv)
           
 KnowledgeBase knowledgeBase()
           
 double limitedContexts(boolean rtChildAsOne)
           
 double numCacheEntries_MPE()
          Number of Caches being used by this RC object.
 int numRoots()
           
 void observe(FiniteVariable var, Object value)
          Add var=value to the list of observations.
 RCNode[] parentChildOrdering()
          Guarantees a parent before a child.
 void pauseRecCondAsThread()
           
abstract  double[] recCond_All()
          Run Recursive conditioning P(e) for each root node (special for testing & output of timing/memory...).
 double recCond_MPE(Map varToValue)
          Run Recursive conditioning MPE.
 double recCond_MPE3(double cutoff)
          Run Recursive conditioning MPE3.
 double recCond_MPE4(double cutoff)
          Run Recursive conditioning MPE4.
 Thread recCond_MPEAsThread(RC.RecCondThreadListener finished)
          Run rEccond_Mpe In A Separate Thread, And Call Finished.Rcfinishedmpe( Double, Map) When Done.
 double recCond_Pe_Scaled()
          Run Recursive conditioning P(e).
 void recCond_Pe_ScaledAsThread(RC.RecCondThreadListener finished)
          Run recCond_Pe_Scaled in a separate thread, and call finished.rcFinished( double) when done.
 double recCond_Pe()
          Run Recursive conditioning P(e).
 void recCond_PeAsThread(RC.RecCondThreadListener finished)
          Run recCond_Pe in a separate thread, and call finished.rcFinished( double) when done.
abstract  void recCond_PreCompute()
          Run RC for each root node to "precompute" the marginals.
 void resetEvidence()
          Returns the evidence to the state of no observations.
 void resetRC()
           
 void resetStatistics()
           
 void resumeKB()
          Warning: This function should not really be public and should not be called from outside of the package unless you are sure it will not lead to computation errors!
 void resumeRecCondAsThread()
           
 void reSynchEvidWithBN(boolean resetEvid)
          Should not normally be called from outside the package, usually it should be handled by the inference engine.
 RCNode root(int i)
           
 void setCPT(FiniteVariable var)
           
 boolean setInst(int indx, int newvalue)
          When using KnowledgeBase, be careful about how algorithms will react to KB making changes.
 RC.RCStats statsAll()
           
 RC.RCStats statsPe()
           
 void stopAndWaitRecCondAsThread()
          Will stop any running functions and wait for them to finish.
 void suspendKB()
          Warning: This function should not really be public and should not be called from outside of the package unless you are sure it will not lead to computation errors!
 double toRealPr(double in)
           
 double[] toRealPr(double[] in)
           
 void unobserve(FiniteVariable var)
           
 void useKB()
           
 boolean useKBflag()
           
 Map varToRoot()
           
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_RC_CALC

public static final boolean DEBUG_RC_CALC
See Also:
Constant Field Values

DEBUG_RC_EVID

public static final boolean DEBUG_RC_EVID
See Also:
Constant Field Values

STR_STACKOVERFLOW_MSG

public static final String STR_STACKOVERFLOW_MSG
See Also:
Constant Field Values

STR_OUTOFMEMORY_MSG

public static final String STR_OUTOFMEMORY_MSG
See Also:
Constant Field Values

TODO_REMOVE_REVERSE_ORDER

public static boolean TODO_REMOVE_REVERSE_ORDER

TODO_REMOVE_DO_PROP_UP

public static boolean TODO_REMOVE_DO_PROP_UP

TODO_REMOVE_DO_EXTRA_LOOKAHEAD

public static boolean TODO_REMOVE_DO_EXTRA_LOOKAHEAD

TODO_REMOVE_DO_LOOKAHEAD_LOWERBOUND

public static boolean TODO_REMOVE_DO_LOOKAHEAD_LOWERBOUND

TODO_REMOVE_DO_LEAF_CACHING_DURING_CREATION

public static boolean TODO_REMOVE_DO_LEAF_CACHING_DURING_CREATION
This variable is only used during RC creation, not dynamically!


TODO_REMOVE_DO_INDEX_CACHING_DURING_CREATION

public static boolean TODO_REMOVE_DO_INDEX_CACHING_DURING_CREATION
This variable needs to be set during RC creation and stay the same during computations!


outputConsole

public PrintWriter outputConsole

vars

public final MappedList vars

counters

public final RC.RCCounters counters

scalar

public final double scalar

DOUBLE_OUTOFMEMORY

public static final double DOUBLE_OUTOFMEMORY
See Also:
Constant Field Values

STR_EXCEPTION_EVIDENCE

public static final String STR_EXCEPTION_EVIDENCE
See Also:
Constant Field Values

allowKB

public final boolean allowKB
Constructor Detail

RC

public RC(RC.RCCreationParams params)
RC Object constructor.

Initializes the variables

Method Detail

canComputeFamilyMarginals

public boolean canComputeFamilyMarginals()
Since:
060303

varToRoot

public Map varToRoot()

getThreadRunning

public Thread getThreadRunning()

isRunning

public boolean isRunning()

resetStatistics

public void resetStatistics()

getStatistics

public String getStatistics()

getStatistics

public String getStatistics(boolean shortStr)

getIterator

public RCIterator getIterator()

getIteratorTraversal

public abstract RCIteratorTraversal getIteratorTraversal()

getIteratorRoots

public abstract RCIterator getIteratorRoots()

getIteratorTree

public abstract RCIterator getIteratorTree()

getAnyRoot

public abstract RCNode getAnyRoot()

getIteratorParentChild

public final RCIterator getIteratorParentChild()

allocRCCaches

public void allocRCCaches()

allocRCMPECaches

public void allocRCMPECaches()

allocRCMPE3Caches

public void allocRCMPE3Caches()

allocRCMPE4Caches

public void allocRCMPE4Caches()

recCond_All

public abstract double[] recCond_All()
Run Recursive conditioning P(e) for each root node (special for testing & output of timing/memory...).

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


recCond_PreCompute

public abstract void recCond_PreCompute()
Run RC for each root node to "precompute" the marginals.

This is meant mostly for dgraphs, where the marginal is saved in the root. For a dtree, it will just fill up the caches, but not at the root node.

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


limitedContexts

public double limitedContexts(boolean rtChildAsOne)

allContexts

public double allContexts()

allContextsMinusLeafs

public double allContextsMinusLeafs()

numCacheEntries_MPE

public double numCacheEntries_MPE()
Number of Caches being used by this RC object.


resetRC

public void resetRC()

getCFMap

public Map getCFMap()

assertLearnedPositive

public final void assertLearnedPositive(int fv,
                                        int state)
Description copied from interface: KnowledgeBase.KnowledgeBaseListener
This is called if the KB learns about a variable from unit propagation, and was not told about this from the user.

If this one is called, may not call AssertLearnedNegative for all the states.

Specified by:
assertLearnedPositive in interface KnowledgeBase.KnowledgeBaseListener

assertUnLearnedPositive

public final void assertUnLearnedPositive(int fv)
Description copied from interface: KnowledgeBase.KnowledgeBaseListener
Called when transitioning from 1 possible state to two possibe states (for any variable, whether the KB learned it or was told it).

Specified by:
assertUnLearnedPositive in interface KnowledgeBase.KnowledgeBaseListener

kbDontCallAssertOnVar

public final void kbDontCallAssertOnVar(int fv)
Specified by:
kbDontCallAssertOnVar in interface KnowledgeBase.KnowledgeBaseListener

kbCallAssertOnVar

public final void kbCallAssertOnVar(int fv)
Specified by:
kbCallAssertOnVar in interface KnowledgeBase.KnowledgeBaseListener

recCond_Pe_Scaled

public double recCond_Pe_Scaled()
Run Recursive conditioning P(e).

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


recCond_Pe

public double recCond_Pe()
Run Recursive conditioning P(e).

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


recCond_MPE

public double recCond_MPE(Map varToValue)
Run Recursive conditioning MPE.

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


recCond_MPE3

public double recCond_MPE3(double cutoff)
Run Recursive conditioning MPE3.

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


recCond_MPE4

public double recCond_MPE4(double cutoff)
Run Recursive conditioning MPE4.

Note: It is possible for the returned value to be NaN if the network contains that in a cpt.


recCond_PeAsThread

public void recCond_PeAsThread(RC.RecCondThreadListener finished)
Run recCond_Pe in a separate thread, and call finished.rcFinished( double) when done. This function can be stopped by using stopAndWaitRecCondAsThread and passing in the returned value from this function. In this case, finished.rcFinished is NOT called.

Since the only way to determine a result is through finished, if it is null nothing will be done.


recCond_Pe_ScaledAsThread

public void recCond_Pe_ScaledAsThread(RC.RecCondThreadListener finished)
Run recCond_Pe_Scaled in a separate thread, and call finished.rcFinished( double) when done. This function can be stopped by using stopAndWaitRecCondAsThread and passing in the returned value from this function. In this case, finished.rcFinished is NOT called.

Since the only way to determine a result is through finished, if it is null nothing will be done.


recCond_MPEAsThread

public Thread recCond_MPEAsThread(RC.RecCondThreadListener finished)
Run rEccond_Mpe In A Separate Thread, And Call Finished.Rcfinishedmpe( Double, Map) When Done. This Function Can Be Stopped By Using Stopandwaitreccondasthread And Passing In The Returned Value From This Function. In This Case, Finished.Rcfinishedmpe Is Not Called.

Since The Only Way To Determine A Result Is Through Finished, If It Is Null Nothing Will Be Done.


pauseRecCondAsThread

public void pauseRecCondAsThread()
Since:
072402

resumeRecCondAsThread

public void resumeRecCondAsThread()
Since:
072402

stopAndWaitRecCondAsThread

public void stopAndWaitRecCondAsThread()
Will stop any running functions and wait for them to finish.

Parameters:
waitFor - A non-Null thread (running ...AsThread) to wait for it to finish

resetEvidence

public void resetEvidence()
Returns the evidence to the state of no observations.


observe

public void observe(FiniteVariable var,
                    Object value)
Add var=value to the list of observations.


setCPT

public void setCPT(FiniteVariable var)

unobserve

public void unobserve(FiniteVariable var)

reSynchEvidWithBN

public void reSynchEvidWithBN(boolean resetEvid)
Should not normally be called from outside the package, usually it should be handled by the inference engine. Usually resetEvidence is true, but the constructor cannot call it.


statsPe

public RC.RCStats statsPe()

statsAll

public RC.RCStats statsAll()

collOfFinVarsToStateSpace

public static final long collOfFinVarsToStateSpace(Collection col)
Will return the state space of all the variables in the collection, and if the collection is empty it will return 1.


toRealPr

public double toRealPr(double in)

toRealPr

public double[] toRealPr(double[] in)

getRoots

public final RCNode[] getRoots()

root

public final RCNode root(int i)

numRoots

public final int numRoots()

parentChildOrdering

public RCNode[] parentChildOrdering()
Guarantees a parent before a child.


generateNumParents

public int[] generateNumParents(MappedList nds)
Will not change nds if it is non-null & non-empty


getTagName

public abstract String getTagName()
Since:
022603

getVars

public static Collection getVars(Collection A)
Get all the vars contained within a collection of RCNodes.


getVars

public static Collection getVars(Collection A,
                                 Collection ret)
Get all the vars contained within a collection of RCNodes.


setInst

public final boolean setInst(int indx,
                             int newvalue)
When using KnowledgeBase, be careful about how algorithms will react to KB making changes.

Can only fail if using the KB, otherwise it only sets the inst array.


knowledgeBase

public KnowledgeBase knowledgeBase()

useKBflag

public boolean useKBflag()

useKB

public void useKB()

createKB

public void createKB()

clearKB

public void clearKB()

suspendKB

public void suspendKB()
Warning: This function should not really be public and should not be called from outside of the package unless you are sure it will not lead to computation errors!


resumeKB

public void resumeKB()
Warning: This function should not really be public and should not be called from outside of the package unless you are sure it will not lead to computation errors!



Copyright 2010 UCLA Automated Reasoning Group