PythonDatabaseGeneratorListener.setWhenProgress

PythonDatabaseGeneratorListener.setWhenProgress(pyfunc)

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

Parameters:

pyfunc (callable) – a function (step: int, duration: float) called when step percent of the database is generated (from 0 to 99), with the elapsed time in seconds

Raises:

pyagrum.InvalidArgument – if pyfunc is not callable

Return type:

None

Example

import pyagrum as gum

generator = gum.BNDatabaseGenerator(gum.fastBN("A->B"))
listener = gum.PythonDatabaseGeneratorListener(generator)
progress = []
listener.setWhenProgress(lambda step, duration: progress.append(step))
ll = generator.drawSamples(1000)
len(progress), progress[:3], progress[-1]  # in percent
# (100, [0, 1, 2], 99)

Class

PythonDatabaseGeneratorListener