- MATLAB 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| geldevice.m | ||
| LICENSE | ||
| MackeyGlass.m | ||
| prediction_task.m | ||
| README.md | ||
| readme.txt | ||
| recognition_task.m | ||
| run.m | ||
| timeset.m | ||
Code-for-iontronic-reservoir
Code in "An iontronic reservoir for highly robust neuromorphic prosthesis"
-
Overview This MATLAB code is designed to realize iontronic reservoir computing on two main tasks: time series prediction using the Mackey - Glass time series and a recognition task using the Iris dataset. For the recognition task, the Iris dataset, a relatively small - scale dataset, is used as a demonstration for a quick run. You can download other standard datasets from official websites as referred in our manuscript and replace the Iris dataset to run the model on different data.The parameter settings for the different tasks can be found in Supplementary Table 1.
-
Requirements
- MATLAB: This code is run in MATLAB (R2022b). You need to have MATLAB installed on your system.
- Functions: The code depends on the following custom functions:
MackeyGlass.m: Used to generate the Mackey - Glass time series.timeset.m: Used to create a one - hot encoded vector.geldevice.m: Used to simulate the behavior of a memristor - like device.
- Code Structure
3.1 Time Series Prediction Task
- Initialization: Clears the command window, workspace, and closes all figures. Sets parameters such as
ML,N,Vmax,Vmin, andT. - Data Generation: Generates the Mackey - Glass time series using the
MackeyGlassfunction. - Training Phase:
- Prepares the training input and target data.
- Generates a random mask and expands the input based on the mask.
- Normalizes the expanded input.
- Calculates the output of the device.
- Extracts states and calculates the output weights using linear regression.
- Testing Phase:
- Prepares the testing input and target data.
- Expands and normalizes the testing input.
- Calculates the output of the device for testing.
- Calculates the system output and evaluation metrics such as NRMSE, MSE, and MSAE.
- Visualization: Plots the time series and the phase portrait, comparing the target and output values.
3.2 Recognition Task
- Initialization: Initializes all variables used in the recognition task.
- Data Loading: Loads the Iris dataset using the
load fisheririscommand. - Data Pre - processing: Maps the species names to numbers and stores the features and labels in a cell array.
- Parameter Setting: Sets parameters such as
ML,N,Vmax,Vmin, andT. - Mask Generation: Generates a random mask and processes it.
- Training and Testing Loop: Runs 10 iterations of training and testing.
- Training: Shuffles the dataset, pre - processes the data, applies the mask, calculates the device output, collects states, and performs linear regression to calculate the output weights.
- Testing: Pre - processes the testing data, applies the mask, calculates the device output, collects states, and calculates the system output.
- Accuracy Calculation: Calculates the classification accuracy for each iteration and the overall accuracy.
- Visualization: Plots the input and memristor output data as dotted - line graphs and displays the mean and standard deviation of the accuracy above the figure.
-
How to Run
-
Place all the necessary functions (
MackeyGlass.m,timeset.m,geldevice.m) in the same directory as the main script. -
Open MATLAB and navigate to the directory containing the script.
-
Run the script (
run.m). The code will automatically perform the time series prediction and recognition tasks, display the evaluation metrics in the command window, and show the visualizations in separate figures. -
Customization
- Prediction Task:
- You can change the parameters such as
ML,N,Vmax,Vmin,T,tau, andstepto adjust the prediction process. - You can modify the
MackeyGlassfunction if you want to change the time series generation method.
- You can change the parameters such as
- Recognition Task:
- You can change the parameters such as
ML,N,Vmax,Vmin,T,trainnum,testnum, andrecognumto adjust the recognition process. - To use a different dataset, you need to modify the data loading and pre - processing part of the code. Replace the
load fisheririscommand and adjust the code to handle the new dataset's format.
- You can change the parameters such as
- Notes
- Function Dependencies: Make sure that the
MackeyGlass.m,timeset.m, andgeldevice.mfunctions are implemented correctly. Any errors in these functions will affect the overall performance of the code. - Randomness: The code involves random number generation (e.g., in the mask generation and dataset shuffling). If you want reproducible results, you can set the random number seed using the
rngfunction in MATLAB.