evokit.accounting package
Submodules
evokit.accounting.accountant module
- class evokit.accounting.accountant.AccountantRecord[source]
Bases:
Generic[T]A record collected by an
Accountantfrom anAlgorithm. Also records the generation count and time of collection.- event: str
Event that triggered the handler.
- value: T
Data collected in
generationafterevent.
- __init__(event: str, generation: int, value: ~evokit.accounting.accountant.T, time: float = <factory>) None
- class evokit.accounting.accountant.Accountant[source]
Bases:
Generic[C,T],Sequence[AccountantRecord[T]]Monitor and collect data from a running
Algorithm.The
Accountantshould be registered to anAlgorithm. Then, when an event fires in the algorithm, if that event is inevents, thenhandlerwill be called with that algorithm as argument. Results are collected as a sequence ofAccountantRecord.Call
Algorithm.register()to register anAccountantto aAlgorithm. Callreport()to retrieve collected records.For type checking purposes, the
Accountanthas two type parameterCandT.Cis the type of the observedAlgorithm;Tis the type of .value in the reportedAccountantRecord.Tutorial: Collect Runtime Statistics with Accountant.
- __init__(events: Container[str], handler: Callable[[C], T], watch_automatic_events: bool = False)[source]
- Parameters:
events – Events that trigger the
handler.handler – Callable that takes the attached algorithm as input.
watch_automatic_events – If
True, also callhandleronAlgorithm.automatic_events.
- report(scope: str | int | None = None) list[AccountantRecord[T]][source]
Report collected records.
- Parameters:
scope –
Option to filter which records to report. Can be an
int, astr, orNone:If
scopeis anint: report record only ifrecord.generation==scope.If
scopeis anstr: report record only ifrecord.event==scope.Otherwise, of if (by default)
scope==None, report all records.
Each time an event fires in the attached
Algorithm, if that event is registered inhandlers, supply theAlgorithmto the handler as argument then collect the result in anAccountantRecord. This method returns a list of all collected records.
evokit.accounting.accountants module
- evokit.accounting.accountants.fitness_accountant(events: list[str], watch_automatic_events: bool = False) Accountant[HomogeneousAlgorithm[Individual[Any]], tuple[float, ...]][source]
Return an
Accountantthat collects theIndividual.fitnessof the best individual in the population in the algorithm.- Arg:
events: Events that trigger the accountant. See
Accountant.events.watch_automatic_events: If
True, then automatic events also trigger the accountant. SeeAlgorithm.step()
- evokit.accounting.accountants.size_accountant(events: list[str], watch_automatic_events: bool = False) Accountant[HomogeneousAlgorithm[Any], int][source]
Return an
Accountantthat collects the length of the population in the algorithm.- Arg:
events: Events that trigger the accountant. See
Accountant.events.watch_automatic_events: If
True, then automatic events also trigger the accountant. SeeAlgorithm.step()
evokit.accounting.visualisers module
- evokit.accounting.visualisers.plot(records: Sequence[AccountantRecord[tuple[float, ...]]], track_generation: bool = False, use_line: bool = False, *args: Any, **kwargs: Any)[source]
Plot a sequence of
AccountantRecord`s. Plot :attr:`AccountantRecord.valueagainstAccountantRecord.time. Also set the X axis label.- Parameters:
records – Sequence of records. Each
AccountantRecord.valuemust only hold eitherfloator a 1-tuple of type tuple[float].track_generation – If
True, then also plot values collected at"STEP_BEGIN"and"STEP_END"as bigger (s=50), special (marker="*") markers. Otherwise, plot them as any other values.use_line – If
True, then plot a line plot. Otherwise, plot a scatter graph.args – Passed to
matplotlib.plot().kwargs – Passed to
matplotlib.plot().
Note
The parameter
use_lineis provided for convenience. Since some values might benan, plotting and connecting only available data points could produce misleading plots.
Module contents
- class evokit.accounting.Accountant[source]
Bases:
Generic[C,T],Sequence[AccountantRecord[T]]Monitor and collect data from a running
Algorithm.The
Accountantshould be registered to anAlgorithm. Then, when an event fires in the algorithm, if that event is inevents, thenhandlerwill be called with that algorithm as argument. Results are collected as a sequence ofAccountantRecord.Call
Algorithm.register()to register anAccountantto aAlgorithm. Callreport()to retrieve collected records.For type checking purposes, the
Accountanthas two type parameterCandT.Cis the type of the observedAlgorithm;Tis the type of .value in the reportedAccountantRecord.Tutorial: Collect Runtime Statistics with Accountant.
- __init__(events: Container[str], handler: Callable[[C], T], watch_automatic_events: bool = False)[source]
- Parameters:
events – Events that trigger the
handler.handler – Callable that takes the attached algorithm as input.
watch_automatic_events – If
True, also callhandleronAlgorithm.automatic_events.
- report(scope: str | int | None = None) list[AccountantRecord[T]][source]
Report collected records.
- Parameters:
scope –
Option to filter which records to report. Can be an
int, astr, orNone:If
scopeis anint: report record only ifrecord.generation==scope.If
scopeis anstr: report record only ifrecord.event==scope.Otherwise, of if (by default)
scope==None, report all records.
Each time an event fires in the attached
Algorithm, if that event is registered inhandlers, supply theAlgorithmto the handler as argument then collect the result in anAccountantRecord. This method returns a list of all collected records.
- class evokit.accounting.AccountantRecord[source]
Bases:
Generic[T]A record collected by an
Accountantfrom anAlgorithm. Also records the generation count and time of collection.- event: str
Event that triggered the handler.
- value: T
Data collected in
generationafterevent.
- __init__(event: str, generation: int, value: ~evokit.accounting.accountant.T, time: float = <factory>) None