Reservoir computing benchmark toolkit
Project description
RCbench - Reservoir Computing Benchmark Toolkit
RCbench (Reservoir Computing Benchmark Toolkit) is a comprehensive Python package for evaluating and benchmarking reservoir computing systems. It provides standardized tasks, flexible visualization tools, and efficient evaluation methods for both physical and simulated reservoirs.
Features
RCbench provides a complete suite of benchmark tasks and evaluation tools:
Benchmark Tasks
- NLT (Nonlinear Transformation): Evaluate reservoir performance on standard nonlinear transformations (square wave, phase shift, double frequency, triangular wave)
- NARMA (Nonlinear Auto-Regressive Moving Average): Test with NARMA models of different orders (NARMA-2, NARMA-10, etc.)
- Memory Capacity: Measure short and long-term memory capabilities with linear memory capacity evaluation
- Nonlinear Memory: Map the memory-nonlinearity trade-off using
y(t) = sin(ฮฝ * s(t-ฯ))benchmark - Sin(x) Approximation: Assess reservoir ability to transform a random signal into sin(x)
- Kernel Rank: Evaluate the nonlinearity and kernel quality of the reservoir
- Generalization Rank: Assess the generalization capabilities across different datasets
Advanced Visualization
- Task-specific plotters with customizable configurations
- General reservoir property visualization (input signals, output responses, nonlinearity)
- Frequency domain analysis of reservoir behavior
- Target vs. prediction comparison with proper time alignment
- Heatmaps for capacity matrices and parameter sweeps
Efficient Data Handling
- Automatic measurement loading and parsing with
ElecResDatasetandReservoirDataset - Support for various experimental data formats (CSV, whitespace-separated)
- Automatic node classification (input, ground, computation nodes)
- Feature selection and dimensionality reduction tools (PCA, k-best)
Flexible Evaluation Framework
- Base evaluator class with common functionality
- Support for Ridge and Linear regression models
- Multiple metrics (NMSE, RNMSE, MSE, Capacity)
- Configurable train/test splits
- Reproducible results with random state control
๐ Project Structure
RCbench/
โโโ rcbench/
โ โโโ __init__.py
โ โโโ examples/ # Example scripts
โ โ โโโ example_nlt.py # NLT with real data
โ โ โโโ example_nlt_matrix.py # NLT with synthetic data
โ โ โโโ example_NARMA.py # NARMA with real data
โ โ โโโ example_NARMA_matrix.py # NARMA with synthetic data
โ โ โโโ example_sinx.py # Sin(x) with real data
โ โ โโโ example_sinx_matrix.py # Sin(x) with synthetic data
โ โ โโโ example_MC.py # Memory Capacity with real data
โ โ โโโ example_MC_matrix.py # Memory Capacity with synthetic data
โ โ โโโ example_nonlinearmemory.py # Nonlinear Memory with real data
โ โ โโโ example_nonlinearmemory_matrix.py # Nonlinear Memory with synthetic data
โ โ โโโ example_KR.py # Kernel Rank
โ โ โโโ example_KR_matrix.py # Kernel Rank with synthetic data
โ โ โโโ examplePCA.py # Feature selection example
โ โโโ measurements/ # Data handling
โ โ โโโ __init__.py
โ โ โโโ dataset.py # ReservoirDataset and ElecResDataset classes
โ โ โโโ loader.py # MeasurementLoader for data loading
โ โ โโโ parser.py # MeasurementParser for node identification
โ โโโ tasks/ # Benchmark tasks
โ โ โโโ __init__.py
โ โ โโโ baseevaluator.py # Base evaluation methods
โ โ โโโ featureselector.py # Feature selection utilities
โ โ โโโ nlt.py # Nonlinear Transformation task
โ โ โโโ narma.py # NARMA task
โ โ โโโ memorycapacity.py # Memory Capacity task
โ โ โโโ nonlinearmemory.py # Nonlinear Memory benchmark
โ โ โโโ sinx.py # Sin(x) approximation task
โ โ โโโ kernelrank.py # Kernel Rank evaluation
โ โ โโโ generalizationrank.py # Generalization Rank evaluation
โ โโโ visualization/ # Plotting utilities
โ โ โโโ __init__.py
โ โ โโโ base_plotter.py # Base plotting functionality
โ โ โโโ plot_config.py # Configuration classes for all plotters
โ โ โโโ nlt_plotter.py # NLT visualization
โ โ โโโ narma_plotter.py # NARMA visualization
โ โ โโโ sinx_plotter.py # Sin(x) visualization
โ โ โโโ mc_plotter.py # Memory Capacity visualization
โ โโโ classes/ # Core classes
โ โ โโโ __init__.py
โ โ โโโ Measurement.py # Measurement data structures
โ โ โโโ sample.py # Sample handling
โ โโโ utils/ # Utility functions
โ โ โโโ __init__.py
โ โ โโโ utils.py
โ โโโ logger.py # Logging utilities
โโโ tests/ # Test suite
โ โโโ test_nlt_dataset.py # NLT evaluation tests
โ โโโ test_reservoir_dataset_consistency.py
โ โโโ test_electrode_selection.py
โ โโโ test_files/ # Test data files
โโโ setup.py # Package setup
โโโ pytest.ini # Pytest configuration
โโโ README.md # This file
๐ง Installation
Install from PyPI:
pip install rcbench
Install directly from GitHub:
pip install git+https://github.com/nanotechdave/RCbench.git
Install locally (development mode):
git clone https://github.com/nanotechdave/RCbench.git
cd RCbench
pip install -e .
Dependencies
RCbench requires:
- Python >= 3.9
- numpy
- scipy
- matplotlib
- scikit-learn
- pandas
๐ฆ Quick Start
Example 1: NLT Evaluation with Real Data
from rcbench import ElecResDataset, NltEvaluator
# Load measurement data
dataset = ElecResDataset("your_measurement_file.txt")
# Get input signal and node outputs
input_signal = dataset.get_input_voltages()[dataset.input_nodes[0]]
nodes_output = dataset.get_node_voltages()
# Create evaluator
evaluator = NltEvaluator(
input_signal=input_signal,
nodes_output=nodes_output,
time_array=dataset.time
)
# Run evaluation
result = evaluator.run_evaluation(target_name='square_wave')
print(f"NMSE: {result['accuracy']:.6f}")
Example 2: Memory Capacity Evaluation
from rcbench import ElecResDataset, MemoryCapacityEvaluator
from rcbench.visualization.plot_config import MCPlotConfig
# Load data
dataset = ElecResDataset("your_measurement_file.txt")
input_voltages = dataset.get_input_voltages()
nodes_output = dataset.get_node_voltages()
input_signal = input_voltages[dataset.input_nodes[0]]
node_names = dataset.nodes
# Create evaluator
plot_config = MCPlotConfig(
plot_mc_curve=True,
plot_predictions=True,
plot_total_mc=True
)
evaluator = MemoryCapacityEvaluator(
input_signal=input_signal,
nodes_output=nodes_output,
max_delay=30,
node_names=node_names,
plot_config=plot_config
)
# Calculate total memory capacity
results = evaluator.calculate_total_memory_capacity(
feature_selection_method='pca',
num_features='all',
modeltype='Ridge',
regression_alpha=0.1,
train_ratio=0.8
)
logger.output(f"Total Memory Capacity: {results['total_memory_capacity']:.4f}")
# Generate plots
evaluator.plot_results()
Example 3: Nonlinear Memory Benchmark
from rcbench import ElecResDataset, NonlinearMemoryEvaluator
from rcbench.visualization.plot_config import NonlinearMemoryPlotConfig
# Load data
dataset = ElecResDataset("your_measurement_file.txt")
input_signal = dataset.get_input_voltages()[dataset.input_nodes[0]]
nodes_output = dataset.get_node_voltages()
# Create plot configuration
plot_config = NonlinearMemoryPlotConfig(
save_dir="./results",
plot_capacity_heatmap=True,
plot_tradeoff_analysis=True
)
# Create evaluator with parameter ranges
evaluator = NonlinearMemoryEvaluator(
input_signal=input_signal,
nodes_output=nodes_output,
tau_values=[1, 2, 3, 4, 5, 6, 7, 8], # Delay values
nu_values=[0.1, 0.3, 1.0, 3.0, 10.0], # Nonlinearity strengths
random_state=42,
node_names=dataset.nodes,
plot_config=plot_config
)
# Run parameter sweep
results = evaluator.run_parameter_sweep(
feature_selection_method='kbest',
num_features='all',
modeltype='Ridge',
regression_alpha=0.1,
train_ratio=0.8,
metric='NMSE'
)
# Get summary
summary = evaluator.summary()
print(f"Average capacity: {summary['average_capacity']:.4f}")
print(f"Best (ฯ, ฮฝ): ({summary['best_tau']}, {summary['best_nu']})")
# Generate plots
evaluator.plot_results()
Example 4: Using Synthetic Data
import numpy as np
from rcbench import NarmaEvaluator
# Generate synthetic data
n_samples = 2000
n_nodes = 15
np.random.seed(42)
input_signal = np.random.uniform(-1, 1, n_samples)
# Create synthetic reservoir responses
nodes_output = np.zeros((n_samples, n_nodes))
for i in range(n_nodes):
delay = np.random.randint(1, 5)
nonlinearity = 0.5 + np.random.rand() * 2
nodes_output[:, i] = np.tanh(nonlinearity * np.roll(input_signal, delay))
nodes_output[:, i] += np.random.randn(n_samples) * 0.05
node_names = [f'Node_{i}' for i in range(n_nodes)]
# Evaluate
evaluator = NarmaEvaluator(
input_signal=input_signal,
nodes_output=nodes_output,
node_names=node_names,
order=2
)
result = evaluator.run_evaluation(
metric='NMSE',
feature_selection_method='kbest',
num_features='all',
modeltype="Ridge",
regression_alpha=1.0,
train_ratio=0.8
)
logger.output(f"NARMA-{evaluator.order} Accuracy: {result['accuracy']:.6f}")
๐ Available Benchmark Tasks
1. Nonlinear Transformation (NLT)
Evaluates the reservoir's ability to perform various nonlinear transformations:
- Square wave generation
- Phase-shifted signals (ฯ/2)
- Frequency doubling
- Triangular wave generation
Key Parameters:
waveform_type: 'sine' or 'triangular'metric: 'NMSE', 'RNMSE', or 'MSE'
2. NARMA (Nonlinear Auto-Regressive Moving Average)
Tests temporal and nonlinear processing with NARMA time series:
NARMA-N: y[t+1] = ฮฑยทy[t] + ฮฒยทy[t]ยทฮฃy[t-i] + ฮณยทu[t-N]ยทu[t] + ฮด
NARMA-2: y[t] = ฮฑยทy[t-1] + ฮฒยทy[t-1]ยทy[t-2] + ฮณยท(u[t-1])ยณ + ฮด
Key Parameters:
order: Order of the NARMA system (2, 10, etc.)alpha, beta, gamma, delta: NARMA coefficients
3. Memory Capacity
Measures the reservoir's ability to recall past inputs:
Task: Predict y(t) = s(t - ฯ) for various delays ฯ
Output: Total memory capacity (sum of squared correlations across delays)
Key Parameters:
max_delay: Maximum delay to test
4. Nonlinear Memory Benchmark
Maps the memory-nonlinearity trade-off surface:
Task: y(t) = sin(ฮฝ ยท s(t - ฯ))
Parameters:
ฯ (tau): Delay (tests memory depth)ฮฝ (nu): Nonlinearity strength
Output: Capacity matrix C(ฯ, ฮฝ) revealing trade-offs
5. Sin(x) Approximation
Tests ability to compute nonlinear functions:
Task: Transform input signal x to sin(x)
6. Kernel Rank
Evaluates the effective dimensionality and nonlinearity of the reservoir's kernel matrix.
7. Generalization Rank
Assesses how well the reservoir generalizes across similar datasets.
๐จ Visualization System
RCbench features a unified visualization system with task-specific plotters:
Configuration Classes
Each task has a configuration class to control plotting:
from rcbench.visualization.plot_config import (
NLTPlotConfig,
MCPlotConfig,
NarmaPlotConfig,
SinxPlotConfig,
NonlinearMemoryPlotConfig
)
# Example: NLT configuration
plot_config = NLTPlotConfig(
figsize=(10, 6),
dpi=100,
save_dir="./plots",
show_plot=True,
# General plots
plot_input_signal=True,
plot_output_responses=True,
plot_nonlinearity=True,
plot_frequency_analysis=True,
# Task-specific plots
plot_target_prediction=True,
# Styling
nonlinearity_plot_style='scatter',
frequency_range=(0, 50),
prediction_sample_count=200
)
Generated Plots
For each task, RCbench can generate:
-
General Reservoir Properties:
- Input signal time series
- Node output responses
- Input-output nonlinearity scatter plots
- Frequency spectrum analysis
-
Task-Specific Visualizations:
- NLT: Target transformations and predictions
- Memory Capacity: MC vs delay curves, cumulative MC
- Nonlinear Memory: Capacity heatmaps, trade-off curves
- NARMA: Time series predictions with error analysis
๐ฌ Dataset Classes
ElecResDataset
For electrical reservoir computing measurements:
from rcbench import ElecResDataset
dataset = ElecResDataset(
source="measurement_file.txt", # or pandas DataFrame
time_column='Time[s]',
ground_threshold=1e-2,
input_nodes=None, # Auto-detect or force specific nodes
ground_nodes=None,
nodes=None
)
# Access data
input_voltages = dataset.get_input_voltages() # Dict[str, np.ndarray]
ground_voltages = dataset.get_ground_voltages()
node_voltages = dataset.get_node_voltages() # np.ndarray
# Node information
print(dataset.input_nodes) # List of input node names
print(dataset.ground_nodes) # List of ground node names
print(dataset.nodes) # List of computation node names
# Summary
summary = dataset.summary()
ReservoirDataset
General parent class for any reservoir data:
from rcbench import ReservoirDataset
dataset = ReservoirDataset(
source="data_file.csv",
time_column='Time[s]'
)
time = dataset.time
dataframe = dataset.dataframe
๐งช Feature Selection
RCbench includes flexible feature selection:
# In any evaluator
result = evaluator.run_evaluation(
feature_selection_method='kbest', # or 'pca', 'none'
num_features=10, # or 'all'
# ... other parameters
)
# Access selected features
selected_features = result['selected_features'] # Indices
selected_names = evaluator.selected_feature_names # Names
Available Methods:
'kbest': Select k best features using f_regression'pca': Principal Component Analysis'none': Use all features
๐ Logging
RCbench uses a custom logger with different levels:
from rcbench.logger import get_logger
import logging
logger = get_logger(__name__)
logger.setLevel(logging.INFO) # INFO, DEBUG, WARNING, ERROR
logger.info("Information message")
logger.output("Output result (level 25)")
logger.warning("Warning message")
logger.error("Error message")
Log Levels:
OUTPUT(25): For displaying resultsINFO(20): For process informationDEBUG(10): For detailed debuggingWARNING(30): For warningsERROR(40): For errors
๐งโ๐ป Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add YourFeature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
Development Setup
git clone https://github.com/nanotechdave/RCbench.git
cd RCbench
pip install -e ".[dev,test]"
Running Tests
pytest tests/
๐ Documentation
For detailed documentation on specific tasks:
- See
rcbench/tasks/NONLINEARMEMORY_README.mdfor the Nonlinear Memory benchmark - Check example scripts in
rcbench/examples/for usage patterns - Each task class includes comprehensive docstrings
๐ Issues & Support
- Issue Tracker: https://github.com/nanotechdave/RCbench/issues
- Pull Requests: https://github.com/nanotechdave/RCbench/pulls
- Discussions: https://github.com/nanotechdave/RCbench/discussions
๐ License
RCbench is licensed under the MIT License. See the LICENSE file for details.
๐ฅ Authors
- Davide Pilati - Initial work - nanotechdave
๐ Acknowledgments
This toolkit was developed at Politecnico di Torino and INRiM for benchmarking physical reservoir computing systems, particularly nanowire networks and other unconventional computing substrates.
๐ Citation
If you use RCbench in your research, please cite:
@software{rcbench2025,
author = {Pilati, Davide},
title = {RCbench: Reservoir Computing Benchmark Toolkit},
year = {2025},
url = {https://github.com/nanotechdave/RCbench},
version = {0.1.30}
}
Version: 0.1.30
Last Updated: November 2025
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rcbench-0.1.40.tar.gz.
File metadata
- Download URL: rcbench-0.1.40.tar.gz
- Upload date:
- Size: 58.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00060604b5e63ff7f5acf714a94f24dc200ccc41914d3c1576b49af6f8cacb2e
|
|
| MD5 |
a6fa28b6549429a3da86a974c7161c8b
|
|
| BLAKE2b-256 |
9c3c5fc3d85329003f144544bac36aa83a2e4c5013df2a3bcc7cb9379eb68721
|
File details
Details for the file rcbench-0.1.40-py3-none-any.whl.
File metadata
- Download URL: rcbench-0.1.40-py3-none-any.whl
- Upload date:
- Size: 61.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a24db06708d107226310049a33cfdd91fe9c07b7935ccbfe1ba4bf9a3ea6df0
|
|
| MD5 |
5873df724e38e659f7801de978bf5e6b
|
|
| BLAKE2b-256 |
5d827af3113c01c7c8165991dccfc135580d4a921218b0ccda9c61095a14b3be
|