Data2Dynamics / d2d

a modeling environment tailored to parameter estimation in dynamical systems
https://github.com/Data2Dynamics/d2d
57 stars 28 forks source link

Multi-step inputs #168

Closed gdudziuk closed 2 years ago

gdudziuk commented 2 years ago

This issue is actually a feature requests.

Currently, discontinuous inputs may be used by specifying step1 and step2 functions in the model definition file. Would it be possible to implement more-step functions? If stepN using an arbitrary number of steps is too cumbersome, can you implement a few more particular steps? At the moment, I would like to use a step input with 4 discontinuities, so step4 would be great. And possibly I will need another couple of discontinuities in the future.

adrianhauber commented 2 years ago

Hi Grzegorz,

thanks for the suggestion and great to hear that you are using D2D! I discussed this with some of the developers and we added input functions for 3 and 4 steps (see commit 92c5e353).

Best, Adrian

gdudziuk commented 2 years ago

Thanks! In the meantime, I have come up with a workaround as follow. Instead of an input like

step4(t, p0, t1, p1, t2, p2, t3, p3, t4, p4)

we can use

step1(t, p0, t1, 0) + step2(t, 0, t1, p1, t2, 0) + step2(t, 0, t2, p2, t3, 0) + step2(t, 0, t3, p3, t4, 0) + step1(t, 0, t4, p4)

The latter one is like representing the input in a basis of all 4-step inputs with discontinuities at predefined times t1...t4. With an analogous method we can define inputs in an arbitrary space comprising combination of steps, splines etc, so the approach is very generic.

I have question however, @adrianhauber. The latter input form above is mathematically equivalent to the former, but is it computationally equivalent as well? Using the latter (the "basis approach"), I'm getting the message:

8 input events detected

despite mathematically there are only 4 such events (at t1...t4). So I'm unsure how the "basis approach" affects the computations...

adrianhauber commented 2 years ago

With your method you would create duplicate input events at t2...t4 and I'm actually not so sure how this affects the computations. However, you could just use

p0 + step1(t,0,t1,p1-p0) + step1(t,0,t2,p2-p1-p0) + step1(t,0,t3,p3-p2-p1-p0) + step1(t,0,t4,p4-p3-p2-p1-p0),

which would minimize the number of input events.

gdudziuk commented 2 years ago

Right, good idea. Anyway, If you had any insights on how the duplicated input events affect the computations, I would be interested to hear.