- Add assertions or logging to check for NaN or Inf values in the network outputs and states.
- Test the network with a smaller dataset or fewer steps to isolate the issue.
- Ensure that newSensorValue is correctly updated at each step and that the network's state (Xic, Aic) is correctly maintained.
- The new sensor value is fetched once per outer loop iteration. Use the latest prediction as new input in the inner loop. This simulates the real-time update more accurately by using the most recent prediction as input for the next step.
Narx network in real-time task
4 ビュー (過去 30 日間)
古いコメントを表示
Good afternoon,
I understand that the topic of NARX networks has been discussed here for over 10 years, but I would like to revisit it.
I attempted to implement a solution for processing data from a sensor in real-time, but unfortunately, I could not find any examples demonstrating how to do this correctly. Most publications on this topic either conclude with a performance evaluation of the network or focus on discussions of the code generated by the application.
Let me share some code:
% targer timeseries
T = num2cell(lfarr(1:8000));
% input timeseries from sensor
X = num2cell(source(1:8000));
The signals are extremely simple - data from the sensor and its smoothed version.
Next, I followed the standard steps outlined in the documentation and various discussions on this forum:
%create narxnet
sh = 7
d1 = [1:sh];
d2 = [1:sh];
narx_net = narxnet(d1,d2,20);
narx_netnet.divideFcn = 'divideblock';
(If Greg suddenly comes, tell him that I remember about autocorrelation and am already carefully studying his code from user group :))
% standard data preparation
[Xs,Xi,Ai,Ts] = preparets(narx_net,X,{},T);
% training
rng( 'default' )
[narx_net, tr, Ys, Es, Xf, Af ] = train(narx_net,Xs,Ts,Xi,Ai);
% performance evaluation
[Y,Xf,Af] = narx_net(Xs,Xi,Ai);
perf = perform(narx_net,Ts,Y) % perf = 3.4381e-08. I think it's not bad.
The regression diagram speaks for itself
Next I close the network and simulate signal processing on the remainder of the data that the network has not seen.
Here, I tried to base my approach on the last two paragraphs of the documentation - Following Closed-Loop Simulation with Open-Loop Simulation.
[narx_netc,Xic,Aic] = closeloop(narx_net, Xf, Af);
% number of prediction steps
k = 5;
% A loop that simulates a real-time data flow
for i = 8001:length(lf_arr)
% getting a new value from the sensor
newSensorValue = num2cell(source(i));
% local variable for indexing the prediction array
ii = 1;
% array of predictions
res = [];
% predictions for k steps
for j=i:i+k
[Yc, Xic, Aic] = narx_netc(newSensorValue, Xic, Aic);
% disp(['Predicted meaning: ', num2str(cell2mat(Yc))]);
res(ii) = cell2mat(Yc);
ii = ii+1;
end
% saving results
res1(i-8000,:) = res';
% form new input and target arrays with new input value and the predicted result
u = [X(2:end),newSensorValue];
y = [T(2:end), {res(1)}];
% repeating initialization cycle for next simulation step
[X1,Xi,Ai,T1] = preparets(narx_net,u,{},y);
[Y,Xio,Aio] = narx_net(X1,Xi,Ai);
[narx_netc,Xic,Aic] = closeloop(narx_net, Xio, Aio);
end
The network starts working, but after some steps its normal operation stops.
I would be immensely grateful for any insights into where my reasoning or actions might have gone astray.
Thanks
0 件のコメント
採用された回答
Aneela
2024 年 8 月 19 日
Hi Andrey,
If the network has stopped producing any output, it suggests a more fundamental issue that might be causing the network to fail or produce NaN/zero values.
These are the possible workarounds:
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Sequence and Numeric Feature Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!