spires_copy_weights
Return a heap-allocated copy of the reservoir’s recurrent weight matrix.
Signature
double *spires_copy_weights(const spires_reservoir *r);Parameters
| Parameter | Type | Description |
|---|---|---|
r | const spires_reservoir * | Handle to the reservoir. Must not be NULL. |
Returns
double * — Pointer to a newly malloc-allocated array of length num_neurons * num_neurons, stored in row-major order. Element result[i * num_neurons + j] is the synaptic weight from neuron j to neuron i.
Returns NULL if r is NULL or if memory allocation fails.
Example
size_t N = spires_num_neurons(r);
double *W = spires_copy_weights(r);
if (!W) {
fprintf(stderr, "failed to copy weights\n");
return 1;
}
/* Find the maximum positive weight */
double w_max = 0.0;
for (size_t k = 0; k < N * N; k++)
if (W[k] > w_max) w_max = W[k];
printf("max weight: %.6f\n", w_max);
free(W);Notes
- Ownership. The returned array is allocated with
mallocand owned by the caller. You must callfree()on the pointer when it is no longer needed. - Row-major layout.
W[i * N + j]is the weight of the connection from neuronjto neuroni. Zero entries indicate no connection. - Snapshot semantics. The returned array is a copy of the weight matrix at the time of the call. Weights are fixed after reservoir creation and do not change during stepping or training, so repeated calls return identical data.
- Allocation-free alternative. Use
spires_read_weightsto copy the weight matrix into a pre-allocated buffer. - Common use: threshold selection for coarse-graining. Sorting the positive entries of this matrix and selecting a high percentile (e.g., 99th) yields a stable threshold for
spires_coarse_grain.
See Also
- spires_read_weights — copy weights into a caller-provided buffer (no allocation).
- spires_coarse_grain — compress the reservoir by merging strongly-connected neuron pairs.
- spires_num_neurons — query the dimension of the weight matrix.
Last updated on