Skip to contentSkip to Content

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

ParameterTypeDescription
rconst 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 malloc and owned by the caller. You must call free() on the pointer when it is no longer needed.
  • Row-major layout. W[i * N + j] is the weight of the connection from neuron j to neuron i. 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_weights to 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

Last updated on