How to update the weights of a Shallow neural network by supplying one sample at a time?

2 visualizzazioni (ultimi 30 giorni)
I would like to use a shallow neural network inside a simulation loop. Every loop will generate a new input that is used to update the weights of the neural network. This online training of a shallow network.
To clarify, I am not asking how to use concurrent nerual network, or reinforcement learning. I am just asking how to make the shallow neural network perform one backprobagation operation based on one desired output. Nothing more. Thanks.
  1 Commento
Emmanouil Tzorakoleftherakis
By the way, if you are willing to try a packaged solution, please take a look at this example that shows how to train a neural state space model.

Accedi per commentare.

Risposte (1)

Venu
Venu il 25 Dic 2023
Modificato: Venu il 25 Dic 2023
Hi @EngM,
You can refer to the documentation below to start with.
To perform online training of a shallow neural network in MATLAB by supplying one sample at a time and updating the weights based on that sample, you can use the "adapt" function.
The "adapt" function is designed to perform online updates to the network weights and biases according to the specified training function (example "traingd") for each new input-target pair.
Read the "adapt" documentation for more understanding.
help adapt
doc adapt
Hope this helps
  1 Commento
EngM
EngM il 4 Gen 2024
Modificato: EngM il 5 Gen 2024
Hello, thanks for answering, I tried the adapt function, the weights/biases don't seem to be adapting (getwb(net)) .
I am using ode23 to simulate a simple 2-dof linear system that the NN is trying to fit, please review. Thanks..
The ode function file is below: input is sin(3*t)., the net is passed on with the ode function
function [dxdt] = SysLTI_2dof_NN(t,x,net)
% Auto generated function on 04-Jan-2024 11:19:18
dxdt = zeros(4,1);
dxdt(1) = x(3);
dxdt(2) = x(4);
dxdt(3) = 50*x(2) - 150*x(1) + sin(3*t);
dxdt(4) = 100*x(1) - 100*x(2) - x(4)/5;
% get the output
y1 = x(1);
y2 = x(2);
net = adapt(net,sin(3*t),[y1;y2]); % adapt function is called here.
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% network shallow feedforward:
net = feedforwardnet(10,'trainlm');
net = configure(net,input,output);
% perform initial off line training so network can get inputs/outputs configuration
[net,tr] = train(net,input,output); % input/output data were provided.
% online training
tspan = [0 1]; % simulation time.
x0 = [0;0;4;0]; % initial point of the ode.
%options = odeset('OutputFcn',@adapt_net);
[t,x] = ode23(@(t,x)SysLTI_2dof_NN(t,x,net),tspan,x0);

Accedi per commentare.

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by