t

# RecurringCollapseStrategy 

#### trait RecurringCollapseStrategy extends BaseUnweightedSampler with HeuristicCollapseStrategy

In the paper, the authors recommend updating the marginals every N samples and re-collapsing every few iterations. In practice, this is pretty slow. This trait will keep a running tally of samples of each of the used variables and re-collapse the factor graph (starting from the initial graph) periodically.

Ordering
1. Alphabetic
2. By Inheritance
Inherited
1. RecurringCollapseStrategy
2. HeuristicCollapseStrategy
3. CollapsedProbabilisticGibbs
4. ProbabilisticGibbs
5. Gibbs
6. FactoredAlgorithm
7. BaseUnweightedSampler
8. Sampler
9. Algorithm
10. AnyRef
11. Any
1. Hide All
2. Show All
Visibility
1. Public
2. All

### Type Members

1. class
Definition Classes
ProbabilisticGibbs
2. type LastUpdate[T] = (T, Int)
Attributes
protected
Definition Classes
BaseUnweightedSampler
3. type Sample = Map[Element[_], Any]

A sample is a map from elements to their values.

A sample is a map from elements to their values.

Definition Classes
BaseUnweightedSampler
4. type TimesSeen[T] = Map[T, Int]
Attributes
protected
Definition Classes
BaseUnweightedSampler

### Abstract Value Members

1. abstract def burnIn(): Int

Number of samples to throw away initially.

Number of samples to throw away initially.

Definition Classes
Gibbs
2. abstract def createBlocks(): List[Block]

Method to create a blocking scheme given information about the model and factors.

Method to create a blocking scheme given information about the model and factors.

Definition Classes
Gibbs
3. abstract val dependentAlgorithm: (Universe, List[NamedEvidence[_]]) ⇒ () ⇒ Double

The algorithm to compute probability of specified evidence in a dependent universe.

The algorithm to compute probability of specified evidence in a dependent universe. We use () => Double to represent this algorithm instead of an instance of ProbEvidenceAlgorithm. Typical usage is to return the result of ProbEvidenceAlgorithm.computeProbEvidence when invoked.

Definition Classes
FactoredAlgorithm
4. abstract val dependentUniverses: List[(Universe, List[NamedEvidence[_]])]

A list of universes that depend on this universe such that evidence on those universes should be taken into account in this universe.

A list of universes that depend on this universe such that evidence on those universes should be taken into account in this universe.

Definition Classes
FactoredAlgorithm
5. abstract def doKill(): Unit
Attributes
protected[com.cra.figaro.algorithm]
Definition Classes
Algorithm
6. abstract def doResume(): Unit
Attributes
protected[com.cra.figaro.algorithm]
Definition Classes
Algorithm
7. abstract def doStart(): Unit
Attributes
protected[com.cra.figaro.algorithm]
Definition Classes
Algorithm
8. abstract def doStop(): Unit
Attributes
protected[com.cra.figaro.algorithm]
Definition Classes
Algorithm
9. abstract def interval(): Int

Iterations thrown away between samples.

Iterations thrown away between samples.

Definition Classes
Gibbs
10. abstract val targetElements: List[Element[_]]

Elements whose samples will be recorded at each iteration.

Elements whose samples will be recorded at each iteration.

Definition Classes
Gibbs

### Concrete Value Members

1. final def !=(arg0: Any): Boolean
Definition Classes
AnyRef → Any
2. final def ##(): Int
Definition Classes
AnyRef → Any
3. final def ==(arg0: Any): Boolean
Definition Classes
AnyRef → Any
4. val active: Boolean
Attributes
protected
Definition Classes
Algorithm
5. def addFactor[T](factor: Factor[T], map: Map[Variable[_], MultiSet[Factor[T]]]): Unit

add a factor to the list

add a factor to the list

Definition Classes
CollapsedProbabilisticGibbs
Attributes
protected
Definition Classes
BaseUnweightedSampler
7. var allTimesSeen: Map[Element[_], TimesSeen[_]]
Attributes
protected
Definition Classes
BaseUnweightedSampler
8. val alpha: Int

Only variables with alpha or fewer neighbors in the primal graph are candidates for collapsing.

Only variables with alpha or fewer neighbors in the primal graph are candidates for collapsing.

Definition Classes
CollapsedProbabilisticGibbs
9. val alphaChoose2: Double

We use ( alpha C 2 ) often, may as well store it.

We use ( alpha C 2 ) often, may as well store it.

Definition Classes
CollapsedProbabilisticGibbs
10. final def asInstanceOf[T0]: T0
Definition Classes
Any
11. val blockSamplerCreate
Definition Classes
CollapsedProbabilisticGibbs
12. val blockSamplers: List[BlockSampler]
Attributes
protected
Definition Classes
ProbabilisticGibbs
13. def cleanUp(): Unit

Called when the algorithm is killed.

Called when the algorithm is killed. By default, does nothing. Can be overridden.

Definition Classes
Algorithm
14. def clone(): AnyRef
Attributes
protected[java.lang]
Definition Classes
AnyRef
Annotations
@throws( ... )
15. def collapseVariables(): Unit

Perform the collapsing step.

Perform the collapsing step.

Definition Classes
HeuristicCollapseStrategyCollapsedProbabilisticGibbs
16. def correctBlocks(originalBlocks: List[Block]): List[Block]

We want to alter the original blocks so that we filter out any variables which have been eliminated.

We want to alter the original blocks so that we filter out any variables which have been eliminated. If the original blocks overlapped a lot, then there'll be a lot of redundancy in the filtered blocks, so we take a further step of eliminating any block xs which is fully contained in another block ys.

Definition Classes
CollapsedProbabilisticGibbs
17. val currentSamples: Map[Variable[_], Int]

The most recent set of samples, used for sampling variables conditioned on the values of other variables.

The most recent set of samples, used for sampling variables conditioned on the values of other variables.

Definition Classes
Gibbs
18. def distributionDistance[T, U](var1: Variable[T], var2: Variable[U]): Double

Hellinger distance is defined in the source paper (amongst other places).

Hellinger distance is defined in the source paper (amongst other places). It's the sum over all values of X1 and X2 of (sqrt(P(X1,X2)) - sqrt(P(X1)*P(X2)))^2

Definition Classes
HeuristicCollapseStrategy
19. def doSample(): Unit
Attributes
protected
Definition Classes
ProbabilisticGibbsBaseUnweightedSamplerSampler
20. def eliminate(variable: Variable[_], factors: MultiSet[Factor[Double]], map: Map[Variable[_], MultiSet[Factor[Double]]]): Unit

Eliminate a variable.

Eliminate a variable. This follows the same approach as in VariableElimination.scala. }

Definition Classes
CollapsedProbabilisticGibbs
21. final def eq(arg0: AnyRef): Boolean
Definition Classes
AnyRef
22. def equals(arg0: Any): Boolean
Definition Classes
AnyRef → Any
23. val factors: List[Factor[Double]]

List of all factors.

List of all factors.

Definition Classes
Gibbs
24. def finalize(): Unit
Attributes
protected[java.lang]
Definition Classes
AnyRef
Annotations
@throws( classOf[java.lang.Throwable] )
25. val gamma: Int
Definition Classes
CollapsedProbabilisticGibbs
26. final def getClass(): Class[_]
Definition Classes
AnyRef → Any
27. def getFactors(neededElements: List[Element[_]], targetElements: List[Element[_]], upperBounds: Boolean = false): List[Factor[Double]]

All implementations of factored algorithms must specify a way to get the factors from the given universe and dependent universes.

All implementations of factored algorithms must specify a way to get the factors from the given universe and dependent universes.

Definition Classes
ProbabilisticGibbsFactoredAlgorithm
28. def getNeededElements(starterElements: List[Element[_]], depth: Int, parameterized: Boolean = false): (List[Element[_]], Boolean)

Get the elements that are needed by the query target variables and the evidence variables.

Get the elements that are needed by the query target variables and the evidence variables. Also compute the values of those variables to the given depth. Only get factors for elements that are actually used by the target variables. This is more efficient. Also, it avoids problems when values of unused elements have not been computed.

In addition to getting all the needed elements, it determines if any of the conditioned, constrained, or dependent universe parent elements has * in its range. If any of these elements has * in its range, the lower and upper bounds of factors will be different, so we need to compute both. If they don't, we don't need to compute bounds.

Definition Classes
FactoredAlgorithm
29. def getSampleCount: Int

Number of samples taken

Number of samples taken

Definition Classes
BaseUnweightedSampler
30. val globalGraph

globalGraph lets us traverse the primal graph.

globalGraph lets us traverse the primal graph.

Definition Classes
CollapsedProbabilisticGibbs
31. def graphHeuristicFunction[T](var1: Variable[T]): Double

Compute the score of a given variable.

Compute the score of a given variable.

Definition Classes
HeuristicCollapseStrategyCollapsedProbabilisticGibbs
32. def graphTerm[T](var1: Variable[T]): Double

Returns how many edges would be added to the primal graph by removing var1.

Returns how many edges would be added to the primal graph by removing var1. Note: this is number of edges added, NOT net edges added and removed. Source paper is somewhat ambiguous on whether this should be added or net.

Definition Classes
CollapsedProbabilisticGibbs
33. def hashCode(): Int
Definition Classes
AnyRef → Any
34. val hellingerDistances: Map[(Int, Int), Double]
Definition Classes
HeuristicCollapseStrategy
Attributes
protected
Definition Classes
BaseUnweightedSampler
36. def initialize(): Unit

Called when the algorithm is started before running any steps.

Called when the algorithm is started before running any steps. By default, does nothing. Can be overridden.

Definition Classes
HeuristicCollapseStrategyAlgorithm
37. def isActive: Boolean
Definition Classes
Algorithm
38. final def isInstanceOf[T0]: Boolean
Definition Classes
Any
39. def kill(): Unit

Kill the algorithm so that it is inactive.

Kill the algorithm so that it is inactive. It will no longer be able to provide answers.Throws AlgorithmInactiveException if the algorithm is not active.

Definition Classes
Algorithm
40. def makeResultFactor(factorsAfterElimination: MultiSet[Factor[Double]]): Factor[Double]

Combine all the remaining factors into one 'result factor', as in VE.

Combine all the remaining factors into one 'result factor', as in VE.

Definition Classes
CollapsedProbabilisticGibbs
41. def marginalize(resultFactor: Factor[Double]): List[Factor[Double]]

Marginalize all factors to their component variables.

Marginalize all factors to their component variables.

Definition Classes
CollapsedProbabilisticGibbs
42. def marginalizeToTarget(factor: Factor[Double], target: Variable[_]): Factor[Double]

Marginalize a factor to a particular variable.

Marginalize a factor to a particular variable.

Definition Classes
CollapsedProbabilisticGibbs
43. val marginals: Map[Int, Map[Int, Double]]
Definition Classes
HeuristicCollapseStrategy
44. final def ne(arg0: AnyRef): Boolean
Definition Classes
AnyRef
45. def newLastUpdate[T](target: Element[T]): LastUpdate[T]
Attributes
protected
Definition Classes
BaseUnweightedSampler
46. def newTimesSeen[T](target: Element[T]): TimesSeen[T]
Attributes
protected
Definition Classes
BaseUnweightedSampler
47. final def notify(): Unit
Definition Classes
AnyRef
48. final def notifyAll(): Unit
Definition Classes
AnyRef
49. val numSamplesSeenSoFar: Int
Definition Classes
HeuristicCollapseStrategy
50. val originalBlocks: List[Block]
Definition Classes
CollapsedProbabilisticGibbs
51. val pairwiseMarignals: Map[(Int, Int), Map[(Int, Int), Double]]
Definition Classes
HeuristicCollapseStrategy
52. lazy val queryTargets: List[Element[_]]
Definition Classes
BaseUnweightedSampler
53. def removeFactor[T](factor: Factor[T], map: Map[Variable[_], MultiSet[Factor[T]]]): Unit

remove a factor from the list

remove a factor from the list

Definition Classes
CollapsedProbabilisticGibbs
54. def resetCounts(): Unit
Attributes
protected
Definition Classes
BaseUnweightedSamplerSampler
55. def resetMarginals(): Unit

We override resetMarginals() to do nothing so that we don't get rid of our saved marginal data every time we re-initialize.

We override resetMarginals() to do nothing so that we don't get rid of our saved marginal data every time we re-initialize. If we haven't built the marginal maps yes, build them, else do nothing.

Definition Classes
RecurringCollapseStrategyHeuristicCollapseStrategy
56. def resume(): Unit

Resume the computation of the algorithm, if it has been stopped.

Resume the computation of the algorithm, if it has been stopped. Throws AlgorithmInactiveException if the algorithm is not active.

Definition Classes
Algorithm
57. def sample(): (Boolean, Sample)

Produce a single sample.

Produce a single sample.

Definition Classes
ProbabilisticGibbsBaseUnweightedSampler
58. def sampleAllBlocks(): Unit

Every sampleRecurrence many samples, we alter the marginals and PairwiseMarginal Maps to record the current sample.

Every sampleRecurrence many samples, we alter the marginals and PairwiseMarginal Maps to record the current sample. Every sampleReset many samples, we re-initialize.

Definition Classes
RecurringCollapseStrategyProbabilisticGibbs
59. def sampleAllBlocksWithTracking(): Unit

Sample all blocks, then store that sample in the marginal and p.m.

Sample all blocks, then store that sample in the marginal and p.m. maps.

Definition Classes
HeuristicCollapseStrategy
60. var sampleCount: Int
Attributes
protected
Definition Classes
BaseUnweightedSampler
61. val sampleRecurrence: Int

How often we want to save one of our samples for marginal estimation.

62. val sampleReset: Int

How often we want to re-collapse.

63. val semiring

Semiring for use in factors.

Semiring for use in factors.

Definition Classes
ProbabilisticGibbsGibbsFactoredAlgorithm
64. def sortByHeuristic(varList: List[Variable[_]], HeuristicMap: Map[Variable[_], Double]): List[Variable[_]]

Sort variables by the target heuristic, if they have fewer than alpha neighbors and are not targets.

Sort variables by the target heuristic, if they have fewer than alpha neighbors and are not targets.

Definition Classes
CollapsedProbabilisticGibbs
65. def start(): Unit

Start the algorithm and make it active.

Start the algorithm and make it active. After it returns, the algorithm must be ready to provide answers. Throws AlgorithmActiveException if the algorithm is already active.

Definition Classes
Algorithm
66. def stop(): Unit

Stop the algorithm from computing.

Stop the algorithm from computing. The algorithm is still ready to provide answers after it returns. Throws AlgorithmInactiveException if the algorithm is not active.

Definition Classes
Algorithm
67. final def synchronized[T0](arg0: ⇒ T0): T0
Definition Classes
AnyRef
68. val targetVariables: List[Variable[_]]

List of variables corresponding to target elements.

List of variables corresponding to target elements. Creating these is memoized, so we don't need to worry about duplicates.

Definition Classes
CollapsedProbabilisticGibbs
69. val targs: Seq[Element[_]]

Store which elements are our target variables so that subclasses can make use of them.

Store which elements are our target variables so that subclasses can make use of them.

Definition Classes
CollapsedProbabilisticGibbs
70. def toString(): String
Definition Classes
AnyRef → Any
71. val totalSamples: Int
Definition Classes
HeuristicCollapseStrategy
72. val trackingSamples: Int
Definition Classes
HeuristicCollapseStrategy
73. val universe
Definition Classes
BaseUnweightedSampler
74. def update(): Unit
Attributes
protected
Definition Classes
BaseUnweightedSamplerSampler
75. def updateDistances(): Unit

Use the marginal maps to compute Hellinger maps.

Use the marginal maps to compute Hellinger maps.

Definition Classes
HeuristicCollapseStrategy
76. def updateTimesSeenForTarget[T](elem: Element[T], newValue: T): Unit
Attributes
protected
Definition Classes
BaseUnweightedSampler
77. def updateTimesSeenWithValue[T](value: T, timesSeen: TimesSeen[T], seen: Int): Unit
Attributes
protected
Definition Classes
BaseUnweightedSampler
78. val upperB: Boolean

Store which elements are our target variables so that subclasses can make use of them.

Store which elements are our target variables so that subclasses can make use of them.

Definition Classes
CollapsedProbabilisticGibbs
79. val variables: Set[Variable[_]]

Variables to sample at each time step.

Variables to sample at each time step.

Definition Classes
Gibbs
80. val varsInOrder: List[Variable[_]]

We need a list of variables in order so we can access them by index.

We need a list of variables in order so we can access them by index.

Definition Classes
CollapsedProbabilisticGibbs
81. final def wait(): Unit
Definition Classes
AnyRef
Annotations
@throws( ... )
82. final def wait(arg0: Long, arg1: Int): Unit
Definition Classes
AnyRef
Annotations
@throws( ... )
83. final def wait(arg0: Long): Unit
Definition Classes
AnyRef
Annotations
@throws( ... )