API Reference
This section documents the Python API for rclib. The C++ core is wrapped efficiently to provide a seamless experience.
Reservoirs
rclib.reservoirs
Reservoir configurations.
RandomSparse
Random Sparse Reservoir configuration.
Source code in python/rclib/reservoirs.py
__init__(n_neurons, spectral_radius, sparsity=0.1, leak_rate=1.0, input_scaling=1.0, *, include_bias=False, seed=42)
Initialize the Random Sparse Reservoir.
Args: n_neurons: Number of neurons in the reservoir. spectral_radius: Spectral radius of the reservoir weight matrix. sparsity: Sparsity of the reservoir weight matrix (0.0 to 1.0). leak_rate: Leaking rate of the neurons. input_scaling: Scaling factor for the input weights. include_bias: Whether to include a bias term. seed: Random seed for weights initialization.
Source code in python/rclib/reservoirs.py
Nvar
NVAR Reservoir configuration.
Source code in python/rclib/reservoirs.py
__init__(num_lags)
Readouts
rclib.readouts
Readout configurations.
Ridge
Ridge Regression Readout configuration.
Source code in python/rclib/readouts.py
__init__(alpha, *, include_bias, solver='auto', tolerance=1e-10)
Initialize the Ridge Readout.
Args: alpha: Regularization parameter. include_bias: Whether to include a bias term. solver: Solver to use ("auto", "cholesky", "dual_cholesky", "conjugate_gradient", "conjugate_gradient_implicit"). tolerance: Convergence tolerance for iterative solvers (CG).
Source code in python/rclib/readouts.py
Rls
Recursive Least Squares (RLS) Readout configuration.
Source code in python/rclib/readouts.py
__init__(lambda_, delta, *, include_bias, solver='rank1_update')
Initialize the RLS Readout.
Args: lambda_: Forgetting factor (0.0 to 1.0). delta: Initial value for the covariance matrix diagonal. include_bias: Whether to include a bias term. solver: Solver type ("rank1_update" or "rank_k_update"). "rank1_update" is traditional sequential RLS. "rank_k_update" is optimized for mini-batches using Woodbury identity.
Source code in python/rclib/readouts.py
Lms
Least Mean Squares (LMS) Readout configuration.
Source code in python/rclib/readouts.py
__init__(learning_rate, *, include_bias)
Initialize the LMS Readout.
Args: learning_rate: Learning rate for the LMS algorithm. include_bias: Whether to include a bias term.
Source code in python/rclib/readouts.py
Model
rclib.model
Model module for Reservoir Computing.
ESN
Echo State Network (ESN) model.
Source code in python/rclib/model.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 64 65 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
__init__(connection_type='serial')
Initialize the ESN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_type
|
str
|
The type of connection between reservoirs ("serial" or "parallel"). Default is "serial". |
'serial'
|
Source code in python/rclib/model.py
add_reservoir(reservoir)
Add a reservoir to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reservoir
|
Any
|
The reservoir object to add. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the reservoir type is unsupported. |
Source code in python/rclib/model.py
fit(x, y, washout_len=0)
Fit the model to the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Input data. |
required |
y
|
ArrayLike
|
Target data. |
required |
washout_len
|
int
|
Number of initial samples to discard. Default is 0. |
0
|
Source code in python/rclib/model.py
get_reservoir(index)
Get the reservoir object at the specified index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index of the reservoir. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The C++ reservoir object. |
Source code in python/rclib/model.py
partial_fit(x, y)
Update the model with a single sample (online learning).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Input data sample. If None, the reservoir state is not advanced (useful if predict_online was already called). |
required |
y
|
ArrayLike
|
Target data sample. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no reservoir or readout is set. |
Source code in python/rclib/model.py
predict(x, *, reset_state_before_predict=True)
Predict using the trained model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Input data. |
required |
reset_state_before_predict
|
bool
|
Whether to reset the reservoir state before prediction. Default is True. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The predicted values. |
Source code in python/rclib/model.py
predict_generative(prime_data, n_steps)
Generative prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prime_data
|
ArrayLike
|
Initial data to prime the reservoir. |
required |
n_steps
|
int
|
Number of steps to generate. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The generated data. |
Source code in python/rclib/model.py
predict_online(x)
Predict in online mode (updating state).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Input data. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The predicted values. |
Source code in python/rclib/model.py
reset_reservoirs()
set_readout(readout)
Set the readout for the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
readout
|
Any
|
The readout object to set. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the readout type is unsupported. |