Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write julia version of basic transition dynamics #23

Closed
jlperla opened this issue May 11, 2018 · 7 comments
Closed

Write julia version of basic transition dynamics #23

jlperla opened this issue May 11, 2018 · 7 comments
Assignees

Comments

@jlperla
Copy link
Contributor

jlperla commented May 11, 2018

We should Julia version of one of our basic dynamics tests, such as https://github.com/econtoolkit/continuous_time_methods/blob/master/matlab/tests/discretize_time_varying_univariate_diffusion_test.m#L47

I wrote this up as https://github.com/JuliaDiffEq/PDERoadmap/blob/master/BellmanDiffusion.md which you can modify as you see fit.

Given that matrix as a function of the time, we can do something along the run of

using DifferentialEquations
function f(du,u,p,t)
  L = < calculation of LQ as a tridiagonal matrix>
  A_mul_B!(du,L,u)
  du .-= c(t,L.grid)
end
solve(f, Euler(), tstops=0:0.01:10)
jlperla added a commit that referenced this issue May 16, 2018
I made a few tweaks to get it running, and changed the time range. to something small (which executes fine now).  It is possible that with a large T it really was unstable (at least with that time-stepping method).
@jlperla
Copy link
Contributor Author

jlperla commented May 16, 2018

Looking like some great progress. I am still not 100% sure about the composition of the operators.

  • I thought that we would have the composition as a L_1_plus and a L_2 of size MxM instead and then multiply the constants in line with Operator composition question for constant multiplication #24.
  • I think it works here because of the homogeneous boundary conditions, so we can do our tweaks to the corners of the L_1 and L_2 individually and then do the multiplication and subtraction from the r I. But I could be wrong.
  • It doesn't especially matter if it delivers the same L (which should be the L Q in the current notation). But I am a little worried about the r I subtraction as I am having trouble thinking through the offsets.

stevenzhangdx added a commit that referenced this issue May 16, 2018
@jlperla
Copy link
Contributor Author

jlperla commented May 16, 2018

The latest commit isn't compiling for me. the L_2 referes to the L_tilde, wich hasn't been implemented yet. Try to recompile it and you will see.

Also, can I move some of this to Julia files? Do you have atom up and running now?

@stevenzhangdx
Copy link
Contributor

stevenzhangdx commented May 17, 2018 via email

@jlperla
Copy link
Contributor Author

jlperla commented May 17, 2018

Sounds good. I pushed a variation of the code for atom that you should get as an update. You can delete it, or maybe check out the only change of substance (where I pass in the algorithm type as a setting

@jlperla
Copy link
Contributor Author

jlperla commented May 19, 2018

Steven,
To finish this issue, why don't you follow some of the modifications from #25 (comment)

In particular, make sure to pull from the server to get the copy I put up there,

  • Change it to go backwards in time. It looks like this requires both swapping the order of the time range and making sure you get the sign correct on the addition/multiplication
  • Change the discretization of the L_1_plus and L_2 operators to avoid the resizing/etc. as we discussed. That is, directly constructing a Tridiagonal.
    • just create the 3 diagonals (of size M-1, M, and M-1 respectively) directly and then create the Tridiagonal matrix
    • I may convert these over to BandedMatrices.jl at some point later.
  • Test the dynamics a little bit with sufficient time variation so that we can avoid the numerical instability Chris was talking about in Test variations on DifferentialEquations parameters for the PDE proof of concept #25
  • Start with adaptive time-stepping if there is enough time-variation
    • But you can try out a few of the algorithms Chris points out in his comment to get a feel for stability.
    • If things are unstable, then feel free to try a fixed dt size.

Close the issue and push to github when you think it is complete, and we can discuss next steps

@stevenzhangdx
Copy link
Contributor

I changed our function to go backwards in time and tested different solving algorithm for stability. I wrote a few comments to show the stability of each algorithm. Most of them are quite stable with our numerical setup, but I could not figure out how to properly plot graphs. It seems like the plotting requests to adjust the corresponding time axis.

@jlperla
Copy link
Contributor Author

jlperla commented May 27, 2018

Great! The code looks very clean. I think the plotting problems are a bug: SciML/DifferentialEquations.jl#300 but could be wrong.

I will close the bug and we can do the plotting/etc. separately.

@jlperla jlperla closed this as completed May 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants