Neural ODE for dynamic systems with input signals
조회 수: 41 (최근 30일)
이전 댓글 표시
Hi! Community!
Is it possible to consider input signals in training? That is, to define the differential equation to be:
where is the input signal.
However, dlode45 will not allow the ODE function to be with more than three inputs.
So is there any other possible approach to incorporate the input signal?
Thanks a lot!
댓글 수: 0
채택된 답변
Ben
2022년 1월 25일
Hi Bowei,
You should be able to create a new ODE function that has only three inputs as required. Let me show a few cases.
Case 1 -
In this case you can define . Assuming you have f as a function handle you can define g in code with:
g = @(t,x,theta) f(t,x,theta,e(t))
Then solve using g in dlode45.
Case 2 -
This is a special case of case 1:
g = @(t,x,theta) f(t,x,theta) + e(t)
Call dlode45 with g.
Case 3 - for
In this case you have an extra hyperparameter i which you just have to select a specific value for. For example let and . You could write this in code as:
e = @(t,i) cos(i*t);
f = @(t,x,A,i) A*x + e(t,i);
x0 = dlarray(randn());
tspan = [0,1];
A = dlarray(randn());
i = 3;
x = dlode45(@(t,x,A) f(t,x,A,i), tspan, x0, A, DataFormat="CB");
Note that in this case you can loop over the values you want for i.
Hope that helps,
Ben
댓글 수: 3
Shubham Baisthakur
2024년 1월 12일
Hello Ben,
Would you please explain how to model ODEs with external input signals using the neuralODELayer in reference to the new functionalities introduced in the recent release (R2023a)?
Thanks,
Shubham
Ben
2024년 1월 15일
Firstly neuralODELayer is only available from R2023b. If R2023a you could use a custom layer using dlode45.
To use neuralODELayer with an external input signal, you will need to be able to implement that external input signal in the dlnetwork that is passed to neuralODELayer. You create layer = neuralODELayer(odenet, tspan), if odenet has 1 input then this corresponds to integrating the ODE . If odenet has 2 inputs then it is . So if you're modelling an ODE of the form then you need implement withing the odenet.
As an example, here's how you could create .
x0 = dlarray(1,"CB");
t0 = dlarray(0,"CB");
sinLayer = functionLayer(@sin, Acceleratable=true);
hiddenSize = 10;
odenet = [
sinLayer
concatenationLayer(1,2)
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(1)];
odenet = dlnetwork(odenet,t0,x0);
tspan = [0,0.1];
odeLayer = neuralODELayer(odenet,tspan);
Here the odenet-s first input is t which becomes via the sinLayer. Then I concatenate with the second input to odenet, x to create , and pass that through standard neural network layers.
A more difficult case is that you don't know a functional form for , but only have samples . In this case, instead of sinLayer = functionLayer(@sin) you should use a layer that interpolates from the samples . One way to do this is with interp1. Here's some code demonstrating that, I'll use again just to demonstrate.
% create toy data
ti = dlarray(linspace(0,1,10));
ui = sin(ti); % in practice you aren't aware of the functional form of u(t).
interpLayer = functionLayer(@(t) dlarray(interp1(ti,ui,t),"CB"), Acceleratable=true);
Next you use interpLayer just like sinLayer above. Part of what this does is store the sample data ti, ui on the interpLayer (actually on the function_handle on that layer). A more flexible approach would be to implement a custom layer to perform this interpolation.
If you have multiple different external signals corresponding to different observations/batch elements, you may need a more intricate approach, since you will have to align the with the batch element inputs to odenet.
추가 답변 (1개)
David Willingham
2022년 1월 24일
Hi Bowei,
Thanks for the feedback on our neural ode example! For your request, can you elloborate on what type of signal e(t) might be and what use cases you're looking to apply neural ode's to?
David
참고 항목
카테고리
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!