### Install development requirements Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html Install necessary dependencies for development, including style checking tools. ```bash $ pip3 install -r dev-requirements.txt ``` -------------------------------- ### Initialize a Reservoir Model Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/quickstart.ipynb.txt Basic setup for creating a reservoir computing model. ```python from reservoirpy.nodes import Reservoir, Ridge reservoir = Reservoir(units=100, lr=0.5, sr=0.9) readout = Ridge(output_dim=1) model = reservoir >> readout ``` -------------------------------- ### Install Sphinx for Documentation Building Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html Use this command to install Sphinx, a tool required for building the project's documentation. Ensure you are using pip3. ```bash pip3 install sphinx ``` -------------------------------- ### Specific Node Example: reservoirpy.mat_gen.line Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.mat_gen.line.html Example usage of the `line` function for weight initialization. ```APIDOC ## Weights initialization (`reservoirpy.mat_gen`) ### `reservoirpy.mat_gen.line` Creates a weight matrix with a line topology. #### Parameters: - **N** (int) - The number of neurons in the reservoir. - **radius** (float, optional) - The spectral radius of the weight matrix. Defaults to 0.9. - **noise** (float, optional) - The amount of noise to add. Defaults to 0.0. - **seed** (int, optional) - Seed for the random number generator. #### Returns: - numpy.ndarray: The generated weight matrix. ``` -------------------------------- ### Initialize ReservoirPy Model Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/quickstart.ipynb.txt Basic setup for initializing a reservoir computing model. ```python from reservoirpy.nodes import Reservoir, Ridge reservoir = Reservoir(units=100, lr=0.5, sr=0.9) readout = Ridge(ridge=1e-6) model = reservoir >> readout ``` -------------------------------- ### Install ReservoirPy with Hyperoptimization Tools Source: https://reservoirpy.readthedocs.io/en/latest/_sources/developer_guide/advanced_install.rst.txt Install ReservoirPy along with extra dependencies required for hyperoptimization and visualization tools, such as hyperopt, matplotlib, and seaborn. ```bash pip install reservoirpy[hyper] ``` -------------------------------- ### Build ReservoirPy Documentation Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html Navigate to the main reservoirPy folder and execute this command to build the HTML documentation. This command requires Sphinx to be installed. ```bash sphinx-build docs/ docs/html ``` -------------------------------- ### Install Development Tools Source: https://reservoirpy.readthedocs.io/en/latest/_sources/developer_guide/advanced_install.rst.txt Install additional dependencies for contributing to ReservoirPy, including pytest for testing and flake8 for linting. ```bash pip install pytest pytest-cov flake8 ``` -------------------------------- ### Install ReservoirPy from Source Source: https://reservoirpy.readthedocs.io/en/latest/_sources/developer_guide/advanced_install.rst.txt Install ReservoirPy in editable mode from its source code location. This is useful for development or when using a specific branch. ```bash pip install -e /path/to/reservoirpy ``` -------------------------------- ### Check ReservoirPy Installation Source: https://reservoirpy.readthedocs.io/en/latest/_sources/developer_guide/advanced_install.rst.txt Verify that ReservoirPy has been installed correctly by checking its details or printing its version number. ```bash pip show reservoirpy ``` ```python python -c "from reservoirpy import __version__; print(__version__)" ``` -------------------------------- ### Initialize ESN Model Source: https://reservoirpy.readthedocs.io/en/latest/api/reservoirpy.ESN.html Instantiate an ESN model, specifying reservoir and readout parameters directly or by passing Node instances. This example shows how to set parameters like units, spectral radius (sr), and ridge regularization. ```python >>> from reservoirpy import ESN >>> >>> model = ESN(units=100, sr=0.9, ridge=1e-6) # reservoir and readout parameters at once >>> model.fit(x_train, y_train) >>> >>> model = ESN(reservoir=Reservoir(100, sr=0.9), readout=Ridge(1e-5)) # passing nodes as parameters >>> >>> model = ESN(units=100, input_to_readout=True, feedback=True) # more complex model ``` -------------------------------- ### Feedback Buffer Content Example Source: https://reservoirpy.readthedocs.io/en/latest/user_guide/advanced_demo.html This output shows an example of the content of the feedback buffers after fitting and running the ESN model. It indicates the stored feedback from the Ridge node to the Reservoir node. ```text Stored feedback: {(Ridge, 1, Reservoir): array([[-1.00263582]])} ``` -------------------------------- ### Initialize ESN Model for Offline Training Source: https://reservoirpy.readthedocs.io/en/latest/user_guide/learning_rules.html Sets up an Echo State Network (ESN) by combining a Reservoir node with a Ridge readout node. The Ridge node is configured for linear regression with a specified ridge parameter. This setup is for offline training. ```python In [8]: from reservoirpy.nodes import Reservoir, Ridge In [9]: reservoir, readout = Reservoir(100, lr=0.2, sr=1.0), Ridge(ridge=1e-3) In [10]: esn = reservoir >> readout ``` -------------------------------- ### Get ReservoirPy and System Versions Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html Run this code snippet to retrieve the installed versions of reservoirpy and numpy, which is useful for bug reports. ```python >>> import reservoirpy >>> print('reservoirpy', reservoirpy.__version___>) ``` -------------------------------- ### Install ReservoirPy Stable Release Source: https://reservoirpy.readthedocs.io/en/latest/_sources/getting_started.rst.txt Use this command to install the latest stable version of ReservoirPy from PyPI. Ensure you have pip installed. ```bash pip install reservoirpy ``` -------------------------------- ### Configure Reservoir Parameters Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Demonstrates how to configure various parameters when initializing a Reservoir node, such as spectral radius, sparsity, and noise. ```python from reservoirpy.nodes import Reservoir # Initialize reservoir with specific parameters res_custom = Reservoir( 100, # Number of neurons sr=0.9, # Spectral radius sf=0.3, # Sparsity factor noise=0.05, # Input noise connectivity=0.1, # Connectivity of the reservoir leak_rate=0.5 # Leak rate of the neurons ) ``` -------------------------------- ### Initialize matrices with random_sparse Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.mat_gen.Initializer.html Demonstrates creating a matrix initialization function with specific parameters and generating a matrix of a defined shape. ```python >>> from reservoirpy.mat_gen import random_sparse >>> init_func = random_sparse(dist="uniform") >>> init_func = init_func(connectivity=0.1) >>> matrix = init_func(5, 5) # actually creates the matrix >>> matrix = random_sparse(5, 5, dist="uniform", connectivity=0.1) # also creates the matrix ``` -------------------------------- ### Example Usage: Lorenz Dataset Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.lorenz.html An example demonstrating how to use the `lorenz` dataset generator. ```APIDOC ## Example: Lorenz Dataset (`reservoirpy.datasets.lorenz`) This example shows how to generate data using the Lorenz system. ### Usage ```python import reservoirpy.datasets as rpd # Generate Lorenz time series data # Parameters can be adjusted for different system behaviors time_series = rpd.lorenz(n_samples=1000, noise_level=0.1) # The 'time_series' variable now holds the generated data. # You can then use this data for training or testing your reservoir models. print(f"Generated time series with {len(time_series)} data points.") ``` ``` -------------------------------- ### Initialize random sparse matrices Source: https://reservoirpy.readthedocs.io/en/latest/api/reservoirpy.mat_gen.html Demonstrates creating a sparse matrix initializer and applying it to generate a matrix, or generating the matrix directly. ```python In [1]: from reservoirpy.mat_gen import random_sparse In [2]: initializer = random_sparse(dist="uniform", sr=0.9, connectivity=0.1) In [3]: matrix = initializer(100, 100) In [4]: print(type(matrix), "\n", matrix[:5, :5]) ``` ```python In [5]: matrix = random_sparse(100, 100, dist="uniform", sr=0.9, connectivity=0.1) In [6]: print(type(matrix), "\n", matrix[:5, :5]) ``` -------------------------------- ### Install ReservoirPy with Scikit-learn Integration Source: https://reservoirpy.readthedocs.io/en/latest/_sources/developer_guide/advanced_install.rst.txt Install ReservoirPy with the necessary dependencies to use scikit-learn models through the ScikitLearnNode. ```bash pip install reservoirpy[sklearn] ``` -------------------------------- ### Initialize Nodes for Feedback Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Sets up reservoir and readout nodes in preparation for establishing feedback connections. ```python from reservoirpy.nodes import Reservoir, Ridge reservoir = Reservoir(100, lr=0.5, sr=0.9) readout = Ridge(ridge=1e-7) ``` -------------------------------- ### Method: initialize Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.Input.html Defines input/output dimensions and instantiates variables. ```APIDOC ## initialize(x) ### Description Only called once, before fitting or running the node. ### Parameters #### Request Body - **x** (array) - Required - Input data to the node. - **y** (None) - Required - Training data (expected to be None). ``` -------------------------------- ### Initialize and connect a ScikitLearnNode Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.ScikitLearnNode.html Demonstrates how to import the node, wrap a scikit-learn Lasso model with specific hyperparameters, and connect it to a Reservoir node. ```python >>> from reservoirpy.nodes import Reservoir, ScikitLearnNode >>> from sklearn.linear_model import Lasso >>> reservoir = Reservoir(units=100) >>> readout = ScikitLearnNode(model=Lasso, model_hypers={"alpha":1e-5}) >>> model = reservoir >> readout ``` -------------------------------- ### Scikit-Learn Style Docstring Example Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html An example of a Python docstring following Scikit-Learn conventions, demonstrating parameters, returns, and method implementation. ```python def fit_predict(self, X, y=None, sample_weight=None): """Compute cluster centers and predict cluster index for each sample. Convenience method; equivalent to calling fit(X) followed by predict(X). Parameters ---------- X : {array-like, sparse_matrix} of shape=[..., n_features] New data to transform. y : Ignored Not used, present here for API consistency by convention. sample_weight : array-like, shape [...,], optional The weights for each observation in X. If None, all observations are assigned equal weight (default: None). Returns ------- labels : array, shape=[...,] Index of the cluster each sample belongs to. """ return self.fit(X, sample_weight=sample_weight).labels_ ``` -------------------------------- ### initialize Method Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.ScikitLearnNode.html Defines input and output dimensions and instantiates internal variables. ```APIDOC ## ScikitLearnNode.initialize ### Description Defines input and output dimensions, and instantiate variables. Only called once, before fitting or running the node. ### Parameters - **x** (array) - Required - Input data to the node. - **y** (None) - Optional - Training data (expected to be None for this node). ``` -------------------------------- ### Initialize Input and Target Data Source: https://reservoirpy.readthedocs.io/en/latest/user_guide/learning_rules.html Create sample input and target data arrays for model training. ```python In [1]: X = np.arange(100)[:, np.newaxis] In [2]: Y = np.arange(100)[:, np.newaxis] ``` -------------------------------- ### Print NumPy Docstring Example Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html This Python snippet demonstrates how to access and print the docstring of a function, using `numpy.mean` as an example. This is useful for understanding docstring formatting. ```python >>> import numpy as np >>> print(np.mean.__doc__) ``` -------------------------------- ### Configure Logging Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Sets up logging for ReservoirPy to monitor training progress and potential issues. Adjust the level for verbosity. ```python import reservoirpy as rpy # Configure logging to show INFO messages rpy.set_log_level('INFO') ``` -------------------------------- ### Run Reservoir with Different Input Scalings Source: https://reservoirpy.readthedocs.io/en/latest/user_guide/hyper.html Initializes and runs a Reservoir node with varying input scaling factors to observe their effect on state dynamics. Requires pre-defined hyperparameters and input data. ```python states = [] input_scalings = [0.1, 1.0, 10.] for input_scaling in input_scalings: reservoir = Reservoir( units=UNITS, sr=SPECTRAL_RADIUS, input_scaling=input_scaling, lr=LEAK_RATE, rc_connectivity=RC_CONNECTIVITY, input_connectivity=INPUT_CONNECTIVITY, seed=SEED, ) s = reservoir.run(X[:500]) states.append(s) ``` -------------------------------- ### Initialize Reservoir with Custom Parameters Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Initialize a Reservoir object with custom parameters for spectral radius, connectivity, and input scaling. Adjust these parameters to fine-tune reservoir behavior. ```python import reservoirpy as rpy # Initialize a reservoir with custom parameters res = rpy.Reservoir(sr=0.9, rc=0.1, ic=0.5) ``` -------------------------------- ### GET /datasets/kuramoto_sivashinsky Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.kuramoto_sivashinsky.html Generates a multivariate timeseries using the Kuramoto-Sivashinsky oscillators model. ```APIDOC ## GET /datasets/kuramoto_sivashinsky ### Description Generates a 1D partial differential equation solution for Kuramoto-Sivashinsky oscillators using the ETDRK4 method. ### Parameters #### Query Parameters - **n_timesteps** (int) - Required - Number of timesteps to generate. - **warmup** (int) - Optional - Number of timesteps to discard at the beginning of the signal to remove transient states. Default: 0. - **N** (int) - Optional - Dimension of the system. Default: 128. - **M** (float) - Optional - Number of points for complex means. Default: 16. - **x0** (array-like) - Optional - Initial conditions of the system. Default: None. - **h** (float) - Optional - Time delta between two discrete timesteps. Default: 0.25. ### Response #### Success Response (200) - **ndarray** (array) - Kuramoto-Sivashinsky equation solution with shape (n_timesteps - warmup, N). ### Request Example >>> from reservoirpy.datasets import kuramoto_sivashinsky >>> timeseries = kuramoto_sivashinsky(1000) ``` -------------------------------- ### GET reservoirpy.datasets.rabinovich_fabrikant Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.rabinovich_fabrikant.html Generates a Rabinovitch-Fabrikant system timeseries based on specified parameters. ```APIDOC ## GET reservoirpy.datasets.rabinovich_fabrikant ### Description Generates a Rabinovitch-Fabrikant system timeseries of a specified length using numerical integration. ### Parameters #### Query Parameters - **n_timesteps** (int) - Required - Number of timesteps to generate. - **alpha** (float) - Optional - α parameter of the system (default: 1.1). - **gamma** (float) - Optional - γ parameter of the system (default: 0.89). - **x0** (list | ndarray) - Optional - Initial conditions of the system (default: [-1, 0, 0.5]). - **h** (float) - Optional - Time delta between two discrete timesteps (default: 0.05). - **kwargs** (dict) - Optional - Other parameters to pass to the scipy.integrate.solve_ivp solver. ### Response #### Success Response (200) - **timeseries** (ndarray) - Array of shape (n_timesteps, 3) representing the Rabinovitch-Fabrikant system timeseries. ### Response Example { "timeseries": [[-1.0, 0.0, 0.5], [-0.98, 0.02, 0.49], ...] } ``` -------------------------------- ### GET reservoirpy.datasets.lorenz96 Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.lorenz96.html Generates a Lorenz96 attractor timeseries based on specified system parameters. ```APIDOC ## GET reservoirpy.datasets.lorenz96 ### Description Generates a Lorenz96 attractor timeseries as defined by Lorenz in 1996. ### Parameters - **n_timesteps** (int) - Required - Number of timesteps to generate. - **warmup** (int) - Optional - Number of timesteps to discard at the beginning of the signal to remove transient states. Default is 0. - **N** (int) - Optional - Dimension of the system. Default is 36. - **F** (float) - Optional - F parameter of the system. Default is 8.0. - **dF** (float) - Optional - Perturbation applied to initial condition if x0 is None. Default is 0.01. - **h** (float) - Optional - Time delta between two discrete timesteps. Default is 0.01. - **x0** (array-like) - Optional - Initial conditions of the system of shape (N,). Default is None. - **kwargs** (dict) - Optional - Other parameters to pass to the scipy.integrate.solve_ivp solver. ### Response - **Return Type** (ndarray) - Lorenz96 timeseries array of shape (n_timesteps - warmup, N). ### Request Example ```python from reservoirpy.datasets import lorenz96 timeseries = lorenz96(1000, h=0.1, N=5) ``` ``` -------------------------------- ### POST /initialize Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.Reservoir.html Defines input and output dimensions and instantiates variables for the node. This must be called once before fitting or running the node. ```APIDOC ## POST /initialize ### Description Define input and output dimensions, and instantiate variables. Only called once, before fitting or running the node. ### Method POST ### Endpoint /initialize ### Parameters #### Request Body - **x** (Array2D | Array3D | Sequence[Timeseries] | Array1D | None) - Required - Input data to the node. - **y** (None) - Required - Training data to the node. As it is not a trainable node, y is expected to be None. ``` -------------------------------- ### Softmax.initialize Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.Softmax.html Defines input and output dimensions and instantiates variables for the node. ```APIDOC ## Softmax.initialize ### Description Defines input and output dimensions, and instantiate variables. Only called once, before fitting or running the node. ### Parameters #### Request Body - **x** (Array2D | Array3D | Sequence[Timeseries] | Array1D) - Required - Input data to the node. - **y** (None) - Required - Training data, expected to be None. ``` -------------------------------- ### GET /reservoirpy/mat_gen/bernoulli Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.mat_gen.bernoulli.html Generates a Bernoulli matrix or a partially initialized function based on provided parameters. ```APIDOC ## GET /reservoirpy/mat_gen/bernoulli ### Description Creates an array with values equal to either 1 or -1. If a shape is provided, it returns a matrix; otherwise, it returns a partially initialized function. ### Parameters #### Query Parameters - **shape** (int, int, ...) - Optional - Shape (row, columns, ...) of the array. - **p** (float) - Optional - Probability of success (to obtain 1). Default: 0.5. - **connectivity** (float) - Optional - Density of the sparse array. Default: 1.0. - **sr** (float) - Optional - Spectral radius to rescale the matrix. - **input_scaling** (float or array) - Optional - Coefficient(s) to rescale the matrix. - **dtype** (numpy.dtype) - Optional - Numpy numerical type. Default: numpy.float64. - **sparsity_type** (string) - Optional - Format: "csr", "csc", or "dense". Default: "csr". - **seed** (optional) - Optional - Random generator seed. - **degree** (int) - Optional - Number of non-zero values along the specified axis. - **direction** (string) - Optional - Axis for degree distribution: "in" or "out". Default: "out". ### Response #### Success Response (200) - **result** (Numpy array or callable) - Returns a matrix if shape is provided, otherwise returns a callable function. ``` -------------------------------- ### Method: initialize Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.NVAR.html Defines input and output dimensions and instantiates variables for the NVAR node. ```APIDOC ## Method: initialize ### Description Defines input and output dimensions, and instantiates variables. Only called once, before fitting or running the node. ### Parameters - **x** (Array2D | Array3D | Sequence[Timeseries] | Array1D) - Required - Input data to the node. - **y** (None) - Optional - Training data, expected to be None. ``` -------------------------------- ### GET /datasets/mackey_glass Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.mackey_glass.html Generates a Mackey-Glass timeseries using the specified parameters for the delayed differential equation. ```APIDOC ## GET /datasets/mackey_glass ### Description Computes a Mackey-Glass timeseries from the delayed differential equation: dx/dt = a*x(t-tau) / (1 + x(t-tau)^n) - b*x(t). ### Parameters #### Query Parameters - **n_timesteps** (int) - Required - Number of timesteps to compute. - **tau** (int) - Optional - Time delay of the equation (default: 17). - **a** (float) - Optional - Parameter 'a' of the equation (default: 0.2). - **b** (float) - Optional - Parameter 'b' of the equation (default: 0.1). - **n** (int) - Optional - Parameter 'n' of the equation (default: 10). - **x0** (float) - Optional - Initial condition of the timeseries (default: 1.2). - **h** (float) - Optional - Time delta between two discrete timesteps (default: 1.0). - **seed** (int/Generator) - Optional - Random state seed for reproducibility. - **history** (ndarray) - Optional - Past timesteps used to warmup the process. ### Response #### Success Response (200) - **timeseries** (ndarray) - An array of shape (n_timesteps, 1) containing the generated Mackey-Glass timeseries. ``` -------------------------------- ### Softplus.initialize Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.Softplus.html Defines input and output dimensions and instantiates variables for the Softplus node. This must be called once before fitting or running. ```APIDOC ## initialize(x, y=None) ### Description Define input and output dimensions, and instantiate variables. Only called once, before fitting or running the node. ### Parameters #### Request Body - **x** (array) - Required - Input data to the node of shape (input_dim,) or (timestep, input_dim). - **y** (None) - Optional - Training data to the node. Expected to be None. ``` -------------------------------- ### GET reservoirpy.datasets.logistic_map Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.logistic_map.html Generates a logistic map discrete time series based on the provided parameters. ```APIDOC ## GET reservoirpy.datasets.logistic_map ### Description Generates a logistic map discrete time series using the formula x(n+1)=rx(n)(1-x(n)). ### Parameters #### Query Parameters - **n_timesteps** (int) - Required - Number of timesteps to generate. - **r** (float) - Optional - r parameter of the system (default: 3.9). - **x0** (float) - Optional - Initial condition of the system (default: 0.5). ### Response #### Success Response (200) - **ndarray** (array) - Logistic map discrete timeseries with shape (n_timesteps, 1). ### Request Example ```python from reservoirpy.datasets import logistic_map timeseries = logistic_map(n_timesteps=100) ``` ``` -------------------------------- ### Split timeseries for forecasting Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.to_forecasting.html Demonstrates how to import and use to_forecasting to generate training and testing sets from a sine wave timeseries. ```python >>> from reservoirpy.datasets import to_forecasting >>> from numpy import linspace, sin >>> t = linspace(0, 500, 1000) >>> timeseries = sin(0.2*t) + sin(0.311*t) >>> X_train, X_test, y_train, y_test = to_forecasting(timeseries, forecast=10, test_size=200) ``` -------------------------------- ### GET reservoirpy.activationsfunc.identity Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.activationsfunc.identity.html The identity function returns the input array unchanged, f(x) = x. ```APIDOC ## GET reservoirpy.activationsfunc.identity ### Description Identity function that returns the input array as is. Provided for convenience. ### Parameters #### Request Body - **x** (ndarray) - Required - Input array. ### Response #### Success Response (200) - **output** (ndarray) - Activated vector. ``` -------------------------------- ### Fit and Run a Reservoir Node Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.IPReservoir.html Demonstrates the basic workflow of fitting a Node to input data and then running it to obtain states. The `fit` method trains the node, and `run` processes data through the trained node. ```python _ = reservoir.fit(x, warmup=100) states = reservoir.run(x) ``` -------------------------------- ### Generate Hénon map timeseries Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.henon_map.html Example usage of the henon_map function to generate a timeseries of 2,000 steps. ```python >>> from reservoirpy.datasets import henon_map >>> timeseries = henon_map(2_000, a=1.4, b=0.3) >>> timeseries.shape (2000, 2) ``` -------------------------------- ### Get Reservoir Parameters Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Retrieve the current parameters of a Reservoir object. This is useful for inspecting the configuration of a reservoir. ```python import reservoirpy as rpy # Initialize a reservoir res = rpy.Reservoir(sr=0.9, rc=0.1, ic=0.5) # Get reservoir parameters params = res.params print(params) ``` -------------------------------- ### Initialize a Reservoir Network Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Initializes a reservoir network with specified parameters. Ensure all parameters are correctly set before initialization. ```python from reservoirpy.nodes import Reservoir, Input from reservoirpy.green.reservoir import Reservoir as GreenReservoir # Initialize a standard reservoir res = Reservoir(100, sr=0.1, sf=0.1, noise=0.01) # Initialize a green reservoir (for GPU acceleration) # green_res = GreenReservoir(100, sr=0.1, sf=0.1, noise=0.01) ``` -------------------------------- ### Node Initialization and Configuration Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.IPReservoir.html Details on initializing and configuring a ReservoirPy Node, including input/output dimensions and internal parameters. ```APIDOC ## Node Initialization and Configuration ### Description This section covers the initialization of the ReservoirPy Node, defining its input and output dimensions, and setting up internal variables. It also lists the configurable attributes that can be set during or after initialization. ### Methods #### `__init__` Initializes a new instance of the Node. Parameters: - `units` (int): Number of neuronal units in the reservoir. - `sr` (float): Spectral radius of the recurrent weight matrix W. - `lr` (float): Leaking rate of the reservoir units (default: 1.0). - `mu` (float): Mean of the target distribution for activation (default: 0.0). - `sigma` (float): Variance of the target distribution for activation (default: 1.0). - `learning_rate` (float): Learning rate for training (default: 5e-4). - `epochs` (int): Number of epochs for training (default: 1). - `input_scaling` (float or array): Scaling factor for the input data (default: 1.0). - `rc_connectivity` (float): Connectivity (density) of the recurrent weight matrix W (default: 0.1). - `input_connectivity` (float): Connectivity (density) of the input weight matrix Win (default: 0.1). - `activation` (str): Activation function for reservoir units ('tanh' or 'sigmoid', default: 'tanh'). - `rng` (object): Random state generator. #### `initialize(x, y=None)` Defines input and output dimensions, and instantiates variables. This method is called once before fitting or running the node. Parameters: - **x** (array of shape (input_dim,) or (timestep, input_dim)): Input data to the node. - **y** (None): Training data to the node. As it is not a trainable node, `y` is expected to be `None`. ### Attributes - `initialized` (bool): True if the Node has been initialized. - `input_dim` (int): Expected dimension of the Node input. Can be None before initialization. - `name` (str or None): Optional name of the Node. - `output_dim` (int): Expected dimension of the Node output. Can be None before initialization. - `W` (ndarray or sparray): Recurrent weights matrix. - `Win` (ndarray or sparray): Input weights matrix. - `bias` (ndarray or sparray): Bias vector. - `a` (float): Gain of reservoir activation. - `b` (float): Bias of reservoir activation. - `lr` (float or ndarray): Leaking rate (1.0 by default). - `sr` (float): Spectral radius of W. - `mu` (float): Mean of the target distribution (0.0 by default). - `sigma` (float): Variance of the target distribution (1.0 by default). - `learning_rate` (float): Learning rate (5e-4 by default). - `epochs` (int): Number of epochs for training (1 by default). - `input_scaling` (float or Sequence): Input scaling (1.0 by default). - `rc_connectivity` (float): Connectivity (density) of W (0.1 by default). - `input_connectivity` (float): Connectivity (density) of Win (0.1 by default). - `activation` (Literal['tanh', 'sigmoid']): Activation of the reservoir units ('tanh' by default). - `units` (int): Number of neuronal units in the reservoir. - `rng` (object): A random state generator. - `state` (ndarray): Current state of the Node. ``` -------------------------------- ### GET reservoirpy.datasets.rossler Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.rossler.html Generates a Rössler attractor timeseries of a specified length using defined system parameters. ```APIDOC ## GET reservoirpy.datasets.rossler ### Description Generates a Rössler attractor timeseries based on the differential equations: dxdt = -y - z, dydt = x + ay, dzdt = b + z(x - c). ### Parameters #### Query Parameters - **n_timesteps** (int) - Required - Number of timesteps to generate. - **a** (float) - Optional - a parameter of the system (default: 0.2). - **b** (float) - Optional - b parameter of the system (default: 0.2). - **c** (float) - Optional - c parameter of the system (default: 5.7). - **x0** (list | ndarray) - Optional - Initial conditions of the system (default: [-0.1, 0.0, 0.02]). - **h** (float) - Optional - Time delta between two discrete timesteps (default: 0.1). ### Response #### Success Response (200) - **timeseries** (ndarray) - Rössler attractor timeseries of shape (n_timesteps, 3). ### Response Example { "timeseries": [[-0.1, 0.0, 0.02], ...] } ``` -------------------------------- ### Visualize Network States Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Generates a visualization of the network's internal states over time. This requires matplotlib to be installed. ```python import reservoirpy as rpy import numpy as np import matplotlib.pyplot as plt # Generate dummy data inputs = np.random.rand(100, 5) # Get network states states = network.run(inputs) # Plot the states rpy.visuals.plot_states(states) plt.show() ``` -------------------------------- ### Get the Bias Vector Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Retrieve the bias vector of the reservoir. This vector adds a constant offset to the activation of each reservoir node. ```python import reservoirpy as rpy # Initialize a reservoir res = rpy.Reservoir() # Get the bias vector bias_vector = res.bias ``` -------------------------------- ### initialize Method Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.node.TrainableNode.html Details on initializing the input and output dimensions of a TrainableNode. ```APIDOC ## Method: initialize ### Description Define input and output dimensions, and instantiate variables. Only called once, before fitting or running the node. ### Method `initialize` ### Parameters - **x** (array-like) - Required - Input data to the node. Shape: (input_dim,) or (timestep, input_dim). - **y** (None) - Required - Training data to the node. As it is not a trainable node, `y` is expected to be `None`. ### Returns None ``` -------------------------------- ### GET reservoirpy.datasets.japanese_vowels Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.japanese_vowels.html Loads the Japanese Vowels dataset, which consists of 12-dimensional LPC cepstrum coefficients for speaker identity inference. ```APIDOC ## GET reservoirpy.datasets.japanese_vowels ### Description Loads the Japanese Vowels dataset for audio discrimination tasks. The dataset contains 640 samples total, with 9 classes representing different speakers. ### Parameters #### Query Parameters - **one_hot_encode** (bool) - Optional - If True, returns class label as a one-hot encoded vector. Defaults to True. - **repeat_targets** (bool) - Optional - If True, repeat the target label or vector along the time axis. Defaults to False. - **data_folder** (str or Path-like) - Optional - Local destination of the downloaded data. - **reload** (bool) - Optional - If True, re-downloads data from the remote repository. Defaults to False. ### Response #### Success Response (200) - **X_train, X_test, Y_train, Y_test** (List of arrays) - Returns lists of arrays of shape (timesteps, features) or (timesteps, target) or (target,). ``` -------------------------------- ### Generate Lorenz96 timeseries Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.lorenz96.html Example usage of the lorenz96 function to generate a timeseries with specified timesteps, time delta, and system dimension. ```python >>> from reservoirpy.datasets import lorenz96 >>> timeseries = lorenz96(1000, h=0.1, N=5) >>> timeseries.shape (1000, 5) ``` -------------------------------- ### Use a Custom Input Matrix Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Provide a custom input weight matrix when initializing the reservoir. This allows for more control over how input signals are processed. ```python import reservoirpy as rpy import numpy as np # Define a custom input matrix input_matrix = np.random.rand(10, 5) # 10 input features, 5 reservoir nodes # Initialize a reservoir with the custom input matrix res = rpy.Reservoir(input_matrix=input_matrix) ``` -------------------------------- ### Get the Reservoir Weights Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Retrieve the recurrent weight matrix of the reservoir. This matrix defines the connections between reservoir nodes and their internal dynamics. ```python import reservoirpy as rpy # Initialize a reservoir res = rpy.Reservoir() # Get the reservoir weights reservoir_weights = res.reservoir_weights ``` -------------------------------- ### Configure Multi-input Reservoir Model Source: https://reservoirpy.readthedocs.io/en/latest/user_guide/advanced_demo.html Constructs a model with multiple reservoirs and readouts, demonstrating how to map inputs to specific nodes and fit the model using a dictionary of input and target data. ```python import numpy as np from reservoirpy.nodes import Reservoir, Ridge reservoir1 = Reservoir(100, name="res1-3") reservoir2 = Reservoir(100, name="res2-3") reservoir3 = Reservoir(100, name="res3-3") readout1 = Ridge(name="readout1") readout2 = Ridge(name="readout2") model = [reservoir1, reservoir2] >> readout1 & [reservoir2, reservoir3] >> readout2 model.fit( {"res1-3": X1, "res2-3": X2, "res3-3": X3}, {"readout1": Y1, "readout2": Y2}, ) out = model.run({"res1-3": X1, "res2-3": X2, "res3-3": X3}) # out = {"readout1": out1, "readout2": out2} out1 = out["readout1"] out2 = out["readout2"] print(out1.shape, out2.shape) ``` -------------------------------- ### Node Initialization Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.node.Node.html Details the `initialize` method used to define input and output dimensions and instantiate variables for a Node. ```APIDOC ## `Node.initialize()` ### Description Define input and output dimensions, and instantiate variables. Only called once, before fitting or running the node. ### Parameters - **x** (_array_ _of_ _shape_ _(__input_dim_ _,__) or_ _(__timestep_ _,__input_dim_ _)_) – Input data to the node. - **y** (_None_) – Training data to the node. As it is not a trainable node, `y` is expected to be `None`. ``` -------------------------------- ### Get the Input Weights Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Retrieve the input weight matrix of the reservoir. This matrix determines how input signals are transformed before entering the reservoir. ```python import reservoirpy as rpy # Initialize a reservoir res = rpy.Reservoir() # Get the input weights input_weights = res.input_weights ``` -------------------------------- ### Train and run an ESN model Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.observables.mse.html This snippet demonstrates how to initialize, train, and run an Echo State Network (ESN) model using sample data. It requires importing `ESN` from `reservoirpy.nodes` and data generation functions from `reservoirpy.datasets`. ```python from reservoirpy.nodes import ESN from reservoirpy.datasets import mackey_glass, to_forecasting x_train, x_test, y_train, y_test = to_forecasting(mackey_glass(1000), test_size=0.2) y_pred = ESN(units=100, sr=1).fit(x_train, y_train).run(x_test) ``` -------------------------------- ### GET reservoirpy.datasets.santafe_laser Source: https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.datasets.santafe_laser.html Loads the Santa-Fe laser dataset, a recording of far-infrared laser activity in a chaotic state consisting of 10,093 timesteps. ```APIDOC ## GET reservoirpy.datasets.santafe_laser ### Description Loads the Santa-Fe laser dataset, which is a static dataset of 10,093 timesteps commonly used as a forecasting task in reservoir computing benchmarks. ### Method GET ### Endpoint reservoirpy.datasets.santafe_laser() ### Response #### Success Response (200) - **X** (Array) - An array of shape (10,093, 1) representing the laser activity data. ``` -------------------------------- ### Get the Readout Weights Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Retrieve the learned readout weights from a trained reservoir. These weights are used to map reservoir states to the desired output. ```python import reservoirpy as rpy # Initialize and train a reservoir res = rpy.Reservoir() X_train = rpy.datasets.narma_dataset(N=1000, d=10) y_train = X_train[10:] res.fit(X_train, y_train) # Get the readout weights readout_weights = res.readout_weights ``` -------------------------------- ### Naming Nodes at Instantiation Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/node.rst.txt Shows how to assign a name to a node during its creation. It is recommended to give unique names to all nodes for better management in complex models. ```python node = Node(..., name="my-node") ``` -------------------------------- ### Model Initialization Source: https://reservoirpy.readthedocs.io/en/latest/api/reservoirpy.ESN.html Initializes a Model instance at runtime, inferring Node dimensions and instantiating feedback buffers. ```APIDOC ## initialize(x, y=None) ### Description Initializes a `Model` instance at runtime, using samples of data to infer all `Node` dimensions and instantiate the feedback buffers. ### Method POST (or equivalent for initialization) ### Endpoint `/model/initialize` (Conceptual endpoint for initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **x** (numpy.ndarray or dict of numpy.ndarray) - Required - A vector of shape (1, ndim) corresponding to a timestep of data, or a dictionary mapping node names to vector of shapes (1, ndim of corresponding node). - **y** (numpy.ndarray or dict of numpy.ndarray, optional) - Optional - A vector of shape (1, ndim) corresponding to a timestep of target data, or a dictionary mapping node names to vector of shapes (1, ndim of corresponding node). ### Request Example ```json { "x": [1.0, 2.0, 3.0], "y": [0.5, 1.5, 2.5] } ``` ### Response #### Success Response (200) - **initialized** (bool) - If True, the model and its Nodes has been initialized. - **input_node** (Input | None) - Input node, if `input_to_readout` is set to True - **input_to_readout** (bool) - Is the readout directly receiving the input (False by default). - **inputs** (list[Node]) - List of Nodes that expects an input - **is_multi_input** (bool) - If True, the model has multiple Node inputs - **is_multi_output** (bool) - If True, the model has multiple outputs and returns a dictionary that associates a node name to a node output. - **is_online** (bool) - If True, the model can be trained online (with `partial_fit()`) - **is_parallel** (bool) - If True, the model can be trained in parallel (offline). - **is_trainable** (bool) - If True, the model can be trained (with `fit()`) - **named_nodes** (dict[str, Node]) - Dictionary that associates a name to a Node with that name in the model. - **nodes** (list[Node]) - List of Nodes contained in the model, in insertion order. - **output_node** (Output | None) - Output node for the reservoir, if `return_reservoir_activity` is set to True - **outputs** (list[Node]) - List of Nodes expected to output their values - **parents** (dict[Node, list[Node]]) - Dictionary that associates a list of all Nodes connected to the key Node. #### Response Example ```json { "initialized": true, "input_node": null, "input_to_readout": false, "inputs": [], "is_multi_input": false, "is_multi_output": false, "is_online": true, "is_parallel": true, "is_trainable": true, "named_nodes": {}, "nodes": [], "output_node": null, "outputs": [], "parents": {} } ``` ``` -------------------------------- ### Resetting the Network State Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/advanced_demo.ipynb.txt Resets the internal state of the reservoir network. This is typically done before processing a new sequence or starting a new experiment. ```python from reservoirpy.nodes import Reservoir, Input # Assume network is already defined input_node = Input(10) reservoir_node = Reservoir(100, sr=0.1, sf=0.1, noise=0.01) output_node = Input(100) network = input_node >> reservoir_node >> output_node # Process some data (which updates the state) # ... network.run(...) ... # Reset the network state network.reset() ``` -------------------------------- ### Generic Python Docstring Template Source: https://reservoirpy.readthedocs.io/en/latest/developer_guide/index.html A template for writing Python docstrings, including sections for summary, description, parameters, returns, notes, examples, and references. ```python def my_method(self, my_param_1, my_param_2="vector"): """Write a one-line summary for the method. Write a description of the method, including "big o" (:math:`O\left(g\left(n\right)\right)`) complexities. Parameters ---------- my_param_1 : array-like, shape=[..., dim] Write a short description of parameter my_param_1. my_param_2 : str, {"vector", "matrix"} Write a short description of parameter my_param_2. Optional, default: "vector". Returns ------- my_result : array-like, shape=[..., dim, dim] Write a short description of the result returned by the method. Notes ----- If relevant, provide equations with (:math:) describing computations performed in the method. Example ------- Provide code snippets showing how the method is used. You can link to scripts of the examples/ directory. Reference --------- If relevant, provide a reference with associated pdf or wikipedia page. """ ``` -------------------------------- ### Run Reservoir on Univariate Timeseries Source: https://reservoirpy.readthedocs.io/en/latest/_sources/user_guide/quickstart.ipynb.txt Initialize and run the reservoir on a univariate timeseries of 100 timesteps sampled from a sine wave. This process helps visualize reservoir activation and infers parameters based on input data. ```python import numpy as np import matplotlib.pyplot as plt from reservoirpy.nodes import Reservoir # Create a reservoir reservoir = Reservoir(100, lr=0.5, sr=0.9) # Create a univariate timeseries input_data = np.sin(np.linspace(0, 100, 100)).reshape(-1, 1) # Run the reservoir on the input data output_data = reservoir.run(input_data) # Visualize the reservoir activation plt.figure(figsize=(10, 5)) plt.plot(output_data) plt.title("Reservoir Activation") plt.xlabel("Timestep") plt.ylabel("Activation") plt.show() ```