spires_train_rls
Train the readout weight matrix using Recursive Least Squares (RLS) over a complete input/target time series. RLS is a streaming, second-order method that processes the series one timestep at a time and converges significantly faster than the online delta rule.
Signature
spires_status spires_train_rls(spires_reservoir *r,
const double *input_series,
const double *target_series,
size_t series_length,
double delta, double lambda);Parameters
| Parameter | Type | Description |
|---|---|---|
r | spires_reservoir * | Handle to the reservoir. Must not be NULL. The reservoir is reset before training begins; after training, the state reflects the final timestep of input_series. |
input_series | const double * | Flattened input matrix of shape [series_length x num_inputs], row-major. Must not be NULL. |
target_series | const double * | Flattened target matrix of shape [series_length x num_outputs], row-major. Element target_series[t * num_outputs + k] is the desired output channel k at timestep t. Must not be NULL. |
series_length | size_t | Number of timesteps in both the input and target series. Must be greater than zero. |
delta | double | Initial prior scaling factor. The inverse correlation matrix is initialized as . Must be positive. A value of 1.0 is a sensible default. Smaller values produce a wider prior and faster initial adaptation. |
lambda | double | Forgetting factor in . Controls how much older samples are discounted. Use 1.0 for stationary tasks (no forgetting). Values below 1.0 give exponentially decaying memory with effective horizon steps. |
Returns
spires_status — SPIRES_OK on success. On failure:
SPIRES_ERR_INVALID_ARG— a pointer isNULL,series_lengthis 0,deltais non-positive, orlambdais outside .SPIRES_ERR_ALLOC— memory allocation for the inverse correlation matrix or workspace arrays failed.
Example
double delta = 1.0; /* unit prior */
double lambda = 1.0; /* no forgetting */
spires_status s = spires_train_rls(r, input, target, T, delta, lambda);
if (s != SPIRES_OK) {
fprintf(stderr, "RLS training failed: %d\n", s);
return 1;
}
/* Run inference on new data */
spires_reservoir_reset(r);
for (size_t t = 0; t < test_len; t++) {
spires_step(r, &test_input[t * num_inputs]);
double y[NUM_OUTPUTS];
spires_compute_output(r, y);
}Notes
- Internal workflow. This function (1) resets the reservoir state and zeroes
W_out, (2) allocates initialized to , (3) processes each timestep sequentially: steps the reservoir, reads the statex, computes the Kalman gaink = Px / (lambda + x'Px), updatesW_out += e * k'wheree = target - W_out * x, and downdatesPvia a rank-1 update, (4) freesPand returns. The trainedW_outis stored inside the reservoir for use byspires_compute_output. - Memory. Allocates one matrix for ( bytes in double precision) plus two workspace vectors. For this is approximately 1.3 MB. Unlike ridge regression, the full state matrix is never stored.
- Single-call training. The matrix is local to this function and is freed on return. To continue updating weights incrementally after this call, use
spires_train_online. - State after training. The reservoir state after this call reflects the final timestep of
input_series. Callspires_reservoir_resetbefore processing new sequences. - Thread safety. Do not call this function on a reservoir that is concurrently in use by another thread.
See Also
- spires_train_ridge — batch ridge regression; global optimum in one pass when all data is available.
- spires_train_online — single-step delta rule update; memory, no auxiliary matrices.
- spires_compute_output — use the trained weights to compute outputs.
- Recursive Least Squares — user guide with parameter selection guidance.
- Training Theory — mathematical derivation of the RLS algorithm.
Last updated on