ShaferShenoyInference.setMaxMemory

ShaferShenoyInference.setMaxMemory(megabytes)

Sets an upper bound on the memory used by the inference.

The bound applies to the tables computed during the inference (a rough estimate based on their sizes). If the inference needs more, it raises MemoryError.

The bound is checked only for large models: when the cliques of the junction tree contain more than 10^6 values in all. A smaller inference needs less than about 8 megabytes for its cliques and is performed without checking it.

Parameters:

megabytes (float) – the upper bound in megabytes (1 megabyte = 1024*1024 bytes). 0 (the default) means no limit.

Return type:

None

Example

import pyagrum as gum

bn = gum.fastBN("A->B->C")
bn.cpt("A").fillWith([0.2, 0.8])
bn.cpt("B").fillWith([0.9, 0.1, 0.3, 0.7])
bn.cpt("C").fillWith([0.6, 0.4, 0.1, 0.9])
ie = gum.ShaferShenoyInference(bn)
ie.setMaxMemory(512)  # at most 512 megabytes for the tables of the inference
ie.makeInference()
print(ie.posterior("C"))
#
#   C                │
# 0        │1        │
# ─────────│─────────│
#  0.3100  │ 0.6900  │

Class

ShaferShenoyInference