Types
posteriors.types.TransformState
𝞡
Bases: NamedTuple
A posteriors
transform state is a NamedTuple
containing the required
information for the posteriors iterative algorithm defined by the init
and
update
functions.
Inherit the NamedTuple
class when defining a new algorithm state, just make sure
to include the params
and aux
fields.
class AlgorithmState(NamedTuple):
params: TensorTree
algorithm_info: Any
aux: Any
Attributes:
Name | Type | Description |
---|---|---|
params |
TensorTree
|
PyTree containing the current value of parameters. |
aux |
Any
|
Auxiliary information from the model call. |
Source code in posteriors/types.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
posteriors.types.InitFn
𝞡
Bases: Protocol
Source code in posteriors/types.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
__call__(params)
staticmethod
𝞡
Initiate a posteriors state with unified API:
state = init(params)
where params is a PyTree of parameters. The produced state
is a
TransformState
(NamedTuple
) containing the required information for the
posteriors iterative algorithm defined by the init
and update
functions.
Note that this represents the init
function as stored in a Transform
returned by an algorithm's build
function, the internal init
function in
the algorithm module can and likely will have additional arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
TensorTree
|
PyTree containing initial value of parameters. |
required |
Returns:
Type | Description |
---|---|
TransformState
|
The initial state ( |
Source code in posteriors/types.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
posteriors.types.UpdateFn
𝞡
Bases: Protocol
Source code in posteriors/types.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
__call__(state, batch, inplace=False)
staticmethod
𝞡
Transform a posteriors state with unified API:
state = update(state, batch, inplace=False)
where state is a NamedTuple
containing the required information for the
posteriors iterative algorithm defined by the init
and update
functions.
Note that this represents the update
function as stored in a Transform
returned by an algorithm's build
function, the internal update
function in
the algorithm module can and likely will have additional arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
TransformState
|
The state of the iterative algorithm. |
required |
batch
|
Any
|
The data batch. |
required |
inplace
|
bool
|
Whether to modify state using inplace operations. Defaults to True. |
False
|
Returns:
Type | Description |
---|---|
TransformState
|
The transformed state ( |
Source code in posteriors/types.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
posteriors.types.Transform
𝞡
Bases: NamedTuple
A transform contains init
and update
functions defining an iterative
algorithm.
Within the Transform
all algorithm specific arguments are predefined, so that the
init
and update
functions have a unified API:
state = transform.init(params)
state = transform.update(state, batch, inplace=False)
Note that this represents the Transform
function is returned by an algorithm's
build
function, the internal init
and update
functions in the
algorithm module can and likely will have additional arguments.
Attributes:
Name | Type | Description |
---|---|---|
init |
InitFn
|
The init function. |
update |
UpdateFn
|
The update function. |
Source code in posteriors/types.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|