Utils API Reference¶
This subpackage contains utility functions and helpers.
Utils Subpackage¶
utils ¶
Common utility functions for numerics and visualization.
max_eig_arnoldi ¶
Compute the maximum eigenvalue of a matrix using the Arnoldi iteration method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Array
|
The input matrix (m x m) for which the maximum eigenvalue is computed. |
required |
max_iters
|
int
|
The maximum number of Arnoldi iterations to perform. Default is 200. If the number of iterations exceeds the size of the matrix, it will be capped at m. |
200
|
seed
|
int
|
Random seed for initializing the starting vector. Default is 0. |
0
|
Visualization¶
visualization ¶
Visualization utilities for plotting time series and spatiotemporal data.
plot_time_series ¶
plot_time_series(U_lst, t=None, time_series_labels=None, line_formats=None, state_var_names=None, t_lim=None, figsize=(20, 8), x_label='$t$', title=None, **plot_kwargs)
Plot time series data with separate panels for each state variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
U_lst
|
2D array or list of 2D arrays
|
If a 2D array, shape should be (Nt, Nu) where Nu is the number of state variables and Nt is the number of time points.If a list of 2D arrays, each array should have shape (Nt, Nu) and represent different time series. |
required |
t
|
1D array
|
1D array of time points. If None, the time points will be assumed to be evenly spaced from 0 to Nt-1. |
None
|
time_series_labels
|
list of strings
|
List of strings containing the labels for each time series to be shown in a legend. If None, no labels will be shown. |
None
|
line_formats
|
list of strings
|
List of strings containing the line formats for each time series. If None, default line format will be used. |
None
|
state_var_names
|
list of strings
|
List of strings containing the names of the state variables. If None, no y-axis labels will be shown. |
None
|
t_lim
|
tuple
|
Limit for the x-axis. If None, the x-axis will be set to the full range of time points. |
None
|
figsize
|
tuple
|
Size of the figure to be created. Default is (20, 8). |
(20, 8)
|
x_label
|
string
|
Label for the x-axis. Default is r'\(t\)'. |
'$t$'
|
title
|
string
|
Title of the plot. If None, no title is shown. |
None
|
plot_kwargs
|
dict
|
Additional arguments to pass to the plot function. |
{}
|
Source code in src/orc/utils/visualization.py
8 9 10 11 12 13 14 15 16 17 18 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 | |
imshow_1D_spatiotemp ¶
imshow_1D_spatiotemp(U, tN, domain=(0, 1), figsize=(20, 6), title=None, x_label='$t$', **imshow_kwargs)
Plot 1D spatiotemporal data using imshow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
U
|
Data to be plotted, shape should be (Nt, Nx) where Nt is the number of time points and Nx is the number of spatial points |
required | |
tN
|
Final time of the simulation |
required | |
domain
|
Bounds of the spatial domain, default is (0, 1) |
(0, 1)
|
|
figsize
|
Size of the figure to be created, default is (20, 6) |
(20, 6)
|
|
title
|
Title of the plot, if None no title is shown |
None
|
|
x_label
|
Label for the x-axis, default is r'\(t\)' |
'$t$'
|
|
**imshow_kwargs
|
|
{}
|
Source code in src/orc/utils/visualization.py
Regressions¶
regressions ¶
Implements common regressions used to train RC models.
ridge_regression ¶
Solve a single matrix ridge regression problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_seq
|
Array
|
Sequence of training reservoir states, (shape=(seq_len, res_dim)). |
required |
target_seq
|
Array
|
Sequence of training targe states, (shape=(seq_len, out_dim)). |
required |
beta
|
float
|
Tikhonov regularization parameter. |
1e-07
|
Returns:
| Type | Description |
|---|---|
Array
|
Solution to ridge regression s.t. cmat @ res_seq = target_seq. |
Source code in src/orc/utils/regressions.py
_solve_all_ridge_reg_batched ¶
_solve_all_ridge_reg_batched(res_seq_train: Array, target_seq: Array, beta: float, batch_size: int) -> Array
Solve ridge regression for all parallel reservoirs using batched vmap.
This function processes the parallel reservoirs in batches to reduce memory usage for large numbers of parallel reservoirs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_seq_train
|
Array
|
Training reservoir states, shape=(seq_len, chunks, res_dim). |
required |
target_seq
|
Array
|
Target sequence, shape=(seq_len, chunks, out_dim). |
required |
beta
|
float
|
Tikhonov regularization parameter. |
required |
batch_size
|
int
|
Number of parallel reservoirs to process in each batch. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Ridge regression solution for all chunks, shape=(chunks, out_dim, res_dim). |
Source code in src/orc/utils/regressions.py
Numerics¶
numerics ¶
Additional utility functions for ORC.
max_eig_arnoldi ¶
Compute the maximum eigenvalue of a matrix using the Arnoldi iteration method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Array
|
The input matrix (m x m) for which the maximum eigenvalue is computed. |
required |
max_iters
|
int
|
The maximum number of Arnoldi iterations to perform. Default is 200. If the number of iterations exceeds the size of the matrix, it will be capped at m. |
200
|
seed
|
int
|
Random seed for initializing the starting vector. Default is 0. |
0
|