PythonApproximationListener.setWhenProgress

PythonApproximationListener.setWhenProgress(pyfunc)

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

Parameters:

pyfunc (callable) – a function (step: int, error: float, duration: float) called when the algorithm has done step iterations, with the current error and the elapsed time in seconds

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)
ie.setPeriodSize(500)
listener = gum.PythonApproximationListener(ie)
steps = []
listener.setWhenProgress(lambda step, error, duration: steps.append(step))
ie.makeInference()
steps  # a notification every 500 iterations (the burn-in is not counted)
# [500, 1000, 1500]

Class

PythonApproximationListener