PythonDatabaseGeneratorListener.setWhenStop

PythonDatabaseGeneratorListener.setWhenStop(pyfunc)

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

Parameters:

pyfunc (callable) – a function (message: str) called when the database is generated, with a summary of the generation

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)
messages = []
listener.setWhenStop(lambda message: messages.append(message))
ll = generator.drawSamples(100)
messages[0].split(" generated")[0]  # followed by the duration and the log2-likelihood
# 'Database of size 100(100)'

Class

PythonDatabaseGeneratorListener