neurophysik / jitcdde

Just-in-time compilation for delay differential equations
Other
56 stars 14 forks source link

Collect the Solution for Bifurcation in a file #21

Closed drsaroj closed 4 years ago

drsaroj commented 5 years ago

My problem is the following:

  1. I want to solve a system of DDEs say for example 2D prey-predator model with some given initial function in interval [0, Tf].

  2. Next, I want to collect all solutions in a text file having three columns(in this case) where the 1st column is time steps, 2nd for prey population and 3rd for the predator population. Given examples only gives the dependent states eg. prey and predator. Although we know the time steps as we have given in for loop.

  3. my second problem is for bifurcation diagram, where I want to collect all the maximum points in consecutive three points taken for each iterate and for each dependent variable in whole time sapce and at a partcular value of parameter 'p' i.e.

say y1(t_i) represent the solution of the system at ith time step. y1'=f1(y1(t),y2(t),y1(t-tau1),y2(t-tau2),p) y2'=f2(y1(t),y2(t),y1(t-tau1),y2(t-tau2),p) at p, then program should do the following

For p=0.1:0.1: 10
solve y1 and y2
For each i from 600 to 1000
    a1=y1(i), a2=y1(i+1), a3=y1(i+2)
    if a1<a2 & a2>a3, then
          c=a2
       save p with c in file with 1st column as p and second column as c
     end if
  end for
end for

Finally, my second file should contain the 1st column as p and the second column as values c i.e. y1 which is maximum in the selected three points. If there is no maximum for given i, it should go to the next value of i till the last point without printing p and c.

  1. The solver given by Thompson and Shampine has event locator facility inbuilt. Is there anything like this in jitcxde where it can be used for impulsive differential equation solution.
Wrzlprmft commented 5 years ago
  1. Next, I want to collect all solutions in a text file having three columns(in this case) where the 1st column is time steps, 2nd for prey population and 3rd for the predator population. Given examples only gives the dependent states eg. prey and predator. Although we know the time steps as we have given in for loop.

    I am not exactly sure what you want, but you can always get the current time of the integrator by DDE.t (if DDE is your integrator object).

  2. You are not really asking a question here, but yes this is possible. I won’t write the entire code for you, but from the JiTCDDE side, the following may be relevant:

    You can either compute the entire solution first and then detect local extrema or you can do this on the fly, which is more tedious, since you have to keep track of the past. Alternatively you can use get_state and determine whether the cubic Hermite interpolant has a local maximum and use this (which will be a bit more precise).

    Also, you can avoid compiling for every parameter value using set_parameters, but you have to address initial continuities every time you do.

    Most of this is a simple Python problem though, so I suggest that you get a bit more familiar with it first.

  3. The solver given by Thompson and Shampine has event locator facility inbuilt. Is there anything like this in jitcxde where it can be used for impulsive differential equation solution.

    No. However in case of a simple threshold criterion, you can rather easily build this yourself by applying get_state and determining when the interpolation of the last two points crosses the threshold.

drsaroj commented 5 years ago

Any idea how to get the solution under the following error:

Traceback (most recent call last): File "mine.py", line 99, in state = DDE.integrate(time) File "/Users/sarojkumar/Library/Python/3.7/lib/python/site-packages/jitcdde/_jitcdde.py", line 799, in integrate if self._adjust_step_size(): File "/Users/sarojkumar/Library/Python/3.7/lib/python/site-packages/jitcdde/_jitcdde.py", line 732, in _adjust_step_size self._control_for_min_step() File "/Users/sarojkumar/Library/Python/3.7/lib/python/site-packages/jitcdde/_jitcdde.py", line 718, in _control_for_min_step raise UnsuccessfulIntegration(message) jitcdde._jitcdde.UnsuccessfulIntegration: Could not integrate with the given tolerance parameters:

atol: 1.000000e-18 rtol: 1.000000e-15 min_step: 1.000000e-10

The most likely reasons for this are: • You did not sufficiently address initial discontinuities. • The DDE is ill-posed or stiff.

The system actually has solutions but yet in spite of modifying the tolerance value, the integrator is unable to solve it. mine.txt

Wrzlprmft commented 5 years ago

Your values for atol and rtol are very low. In fact rtol is close to the relative representation accuracies of (double-precision floating-point) numbers. Therefore it is not surprising that your integration failed. Do you also have issues with the default values? Apart from that, it’s hard to say anything without your code.

drsaroj commented 5 years ago

Yes I got the error when default values of tolerance was there, that is why I changed it to current value. Moreover, the code is attached as text file "mine.txt", please check the previous massage.

Wrzlprmft commented 5 years ago

Your dynamics is happening on a time scale that is too small for the standard settings of step_on_discontinuities. You can fix this with DDE.step_on_discontinuities(max_step=0.01) (and not adjusting the integration parameters otherwise).

drsaroj commented 5 years ago

Thank you for your comment. Now it is working perfectly.