PythonApproximationListener.setWhenStop

PythonApproximationListener.setWhenStop(pyfunc)

Set the function called when the algorithm stops (it replaces the function previously set for this event on this listener).

Parameters:

pyfunc (callable) – a function (message: str) called when the algorithm stops, with the reason of the stop

Raises:

pyagrum.InvalidArgument – if pyfunc is not callable

Return type:

None

Example

import pyagrum as gum

ie = gum.GibbsSampling(gum.fastBN("A->B->C;A->C"))
ie.disableEpsilon()
ie.disableMinEpsilonRate()
ie.setMaxIter(2000)
listener = gum.PythonApproximationListener(ie)
messages = []
listener.setWhenStop(lambda message: messages.append(message))
ie.makeInference()
messages
# ['stopped with max iteration=2000']

Class

PythonApproximationListener