Base
Define the root of every configurable class of the library.
BaseConfig
Bases: BaseEstimator, ABC
Root of every configurable class of the library: it stores its settings and speaks three verbs.
The constructor of a child stores every setting unmodified under its own name, as in scikit-learn, so
get_params, set_params, and clone work on every class. The three verbs call the abstract hooks _check,
_prepare, and _run, which every child implements, itself or through the base of its family, and every verb
returns the object, as in scikit-learn:
check()validates the settings through_check()and marks the object as checked.prepare(context)prepares the checked object against the one thing it serves through_prepare(context), and sets the attributes that end in_.run(inputs, final=False)performs the one action of the checked and prepared object on its one input through_run(inputs), and keeps what the action produces in attributes that end in_; a last call withfinal=Truealso releases what preparing acquired through_release(), an optional hook that releases nothing by default.
Examples:
>>> from skcomplex.base import BaseConfig
>>> class DoublingConfig(BaseConfig):
... def __init__(self, factor=2):
... self.factor = factor
...
... def _check(self):
... pass
...
... def _prepare(self, context):
... pass
...
... def _run(self, inputs):
... self.doubled_ = self.factor * inputs
>>> DoublingConfig().check().prepare().run(3).doubled_
6
check()
Validate the settings of the object and mark it as checked.
Returns:
| Name | Type | Description |
|---|---|---|
self |
Self
|
The object. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
A setting is invalid, named in the message. |
Source code in src/skcomplex/base.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
prepare(context=None)
Prepare the checked object against the one thing it serves, setting its attributes that end in _.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ContextT | None
|
What the object serves, such as the system of a compiler, the problem of a solver, or the source of an analysis. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
Self
|
The prepared object. |
Raises:
| Type | Description |
|---|---|
NotCheckedError
|
The object was not checked with |
Source code in src/skcomplex/base.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
run(inputs=None, final=False)
Perform the one action of the checked object on its one input, keeping its results in attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
InputT | None
|
The input of the action, such as the state a solver advances or the values a law reads. |
None
|
final
|
bool
|
Whether this is the last call, after which the object releases what preparing acquired. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
Self
|
The object, with the results of the action in its attributes that end in |
Raises:
| Type | Description |
|---|---|
NotCheckedError
|
The object was not checked with |
NotPreparedError
|
The object was not prepared with |
Source code in src/skcomplex/base.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |