Customisation¶
Hooks for changing how a fit is initialised, when it stops, and how its loop is scheduled.
Pass them to Robusta as override_initialiser, override_conv_tester and
override_frame.
Initialiser¶
robusta_hmf.Initialiser
dataclass
¶
Seeds (A, G) before the optimisation loop starts.
Pass one to Robusta as override_initialiser.
N, M and K may be left unset, in which case
Robusta.fit() fills them in from the data,
so an initialiser can be built without knowing the shapes up front.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int | None
|
Rows and columns of |
None
|
M
|
int | None
|
Rows and columns of |
None
|
K
|
int | None
|
Rows and columns of |
None
|
strategy
|
(svd, random, custom)
|
|
"svd"
|
with_dims(N, M, K)
¶
Fill in whichever of N, M, K are unset. Explicit values win.
execute(seed=None, A=None, G=None, Y=None, opt=None)
¶
Build the initial state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Random seed, required for |
None
|
A
|
Array | None
|
Initial factors, shapes |
None
|
G
|
Array | None
|
Initial factors, shapes |
None
|
Y
|
Array | None
|
The |
None
|
opt
|
GradientTransformation | None
|
If given, its state is initialised on |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
state |
RHMFState
|
The initial factors, with |
ConvergenceTester¶
robusta_hmf.ConvergenceTester
dataclass
¶
Decides when a fit has converged, from consecutive checked states.
Robusta builds one from conv_strategy and
conv_tol; pass one as override_conv_tester to set it directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
(max_frac_G, max_frac_A, rel_frac_loss, none)
|
|
"max_frac_G"
|
tol
|
float
|
Tolerance. Note that |
1e-6
|
is_converged(old_state, new_state, old_loss, new_loss)
¶
Whether the fit has converged between two checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_state
|
RHMFState
|
The states at the previous and the current convergence check. |
required |
new_state
|
RHMFState
|
The states at the previous and the current convergence check. |
required |
old_loss
|
float
|
The losses at those checks. |
required |
new_loss
|
float
|
The losses at those checks. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
converged |
bool
|
|
OptFrame¶
robusta_hmf.OptFrame
dataclass
¶
Owns the optimisation loop: data placement, initialisation, iteration.
Robusta configures the model (an HMF) and
delegates execution to a frame. A subclass can change how the loop is
scheduled -- see ShardedFrame, which chunks
and shards the row axis -- without re-declaring the model's parameter list.
compute_dtype is the dtype of the arithmetic and of A/G.
Robusta sets it through bind(); None leaves arrays in
whatever dtype they arrive in.