Clear Filters
Clear Filters

Use of catsamples() to concatenate sequences for a neural network

2 views (last 30 days)
I have developed a MIMO NARX network where I have multiple sequences (trials). Originally, I concatenated the data with one trial after the other to create "continuous" input and target time series. Because the data is not really continuous, I get a discontinuation between each concatenation. After some digging, I found these 2 links that talks about problem ( https://www.mathworks.com/help/nnet/ug/understanding-neural-network-toolbox-data-structures.html ) and the solution ( https://www.mathworks.com/help/nnet/ug/multiple-sequences-with-dynamic-neural-networks.html ). However I am having troubles implementing the catsamples() command based on how my data is setup.
For the inputs, I have a cell array of 3x30 where each column is a sequence of different length of [2X1] (2 inputs) and each row will be a different input series. I have different experimental conditions saved in 1 cell array but each will be tested separately as a single input series.
EMG =3×30 cell array
Columns 1 through 5
{1×134 cell} {1×137 cell} {1×133 cell} {1×134 cell} {1×136 cell}
{1×134 cell} {1×137 cell} {1×133 cell} {1×134 cell} {1×136 cell}
{1×134 cell} {1×137 cell} {1×133 cell} {1×134 cell} {1×136 cell}
Columns 6 through 10 ...
EMG{1, 1}{1, 1} = 1×134 cell array
Columns 1 through 5
[2×1 double] [2×1 double] [2×1 double] [2×1 double] [2×1 double]
Columns 6 through 10 ...
The output is just a 1x30 where each column is a sequence/trial and each cell has 2 target outputs.
Angle_Moment=1×30 cell array
Columns 1 through 5
{1×134 cell} {1×137 cell} {1×133 cell} {1×134 cell} {1×136 cell}
Columns 6 through 10 ...
Angle_Moment{1, 1}{1, 1} = 1×134 cell array
Columns 1 through 5
[2×1 double] [2×1 double] [2×1 double] [2×1 double] [2×1 double]
Columns 6 through 10 ...
All the examples I found of catsamples() have each sequence in a separate variables. How can I implement
x_mul = catsamples(x1,x2,x3,'pad');
but with all the sequences in one single cell array with 2 inputs/outputs? Should I set up my data differently? How?
Also, I am planning on dividing my data using
net.divideFcn ='divideblock';
with 70-20-10%. Does that means it will take the first 21 values of the {1x30}?
Please respond if you have insight in either of the 2 questions (catsamples or divideFcn).
Thank you,

Accepted Answer

ErikaZ
ErikaZ on 20 Jul 2018
Edited: ErikaZ on 20 Jul 2018
catsamples( EMG_InputSeries{i,:},'pad'); % For EMG
catsamples( Angle_Moment_TargetSeries{:},'pad'); % For Ankle_Moment
This will create a 1x400s cell array with 2x30 cell inside each.
For default 'divideblock', it takes 70 percent of 400s time points for training. If needed to take 70% of the Q = 30, the mode must be changed to sample
net.divideMode = 'sample';
This will take 21 points from every of the 400s time points for training.
  1 Comment
Torsten K
Torsten K on 15 Oct 2020
Hello everybody,
i know the thread is old but i'm looking for a solution to a similar problem. I have 150 time series of different lengths (max 600 timesteps), 2 inputs and 1 target and I want to train a NARX network. I converted the time series into a cell array X for the inputs and a cell array T for the targets:
X = 1×600 cell array
Columns 1 through 2 [...] Columns 599 through 600
{2×150 double} {2×150 double} [...] {2×150 double} {2×150 double}
T = 1×600 cell array
Columns 1 through 2 [...] Columns 599 through 600
{1×150 double} {1×150 double} [...] {1×150 double} {1×150 double}
Now I would like to use 110 "complete" time series for training, 20 for validation and 20 for testing. The time series should not be torn apart, as each time series reflects a single dynamic process, so it makes no sense for me to train with the first 70% of the timeseries, validate with the next 15% and test with the last 15%.
Does anyone have any suggestion on how to implement this approach in Matlab code?
Best regards
Torsten

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!