SciML / PDERoadmap

A repository for the discussion of PDE tooling for scientific machine learning (SciML) and physics-informed machine learning
https://tutorials.sciml.ai/
18 stars 6 forks source link

Check signs of operators for time-direction/etc. #26

Closed jlperla closed 6 years ago

jlperla commented 6 years ago

@stevenzhangdx

The current transition_dynamics_example.jl is now calculating something with a time-varying payoff and plotting it to see what is happening. It does it with 2 separate approaches: First, it uses the backwards tspan approach, and the second it does a change of variables (i.e. t_tilde = T - t) and solves the resulting function of t_tilde from t_tilde = 0 to t_tilde = T.

You will see that the only time-varying thing in the PDE is the c_tilde function which is increasing with time. What I don't understand about this solution, is that it seems to me that the u(t,x) function should be increasing over time, since the payoff is increasing. Instead, unless I am missing something it seems to be decreasing.... Can you go carefully through this to see if the results make sense or if we setup a sign incorrectly? For example, if we swap the sign of the composition of the du, at least the u(t,x) seems to be increasing in t, as I would expect. Or maybe my prior that u(t,x) should be increasing is wrong itself?

stevenzhangdx commented 6 years ago

Sure, I’m working on something else now. I’ll take a look at it tonight or tomorrow morning. Can I get it back to you tomorrow?

On Tue, May 29, 2018 at 3:20 PM Jesse Perla notifications@github.com wrote:

@stevenzhangdx https://github.com/stevenzhangdx

The current transition_dynamics_example.jl is now calculating something with a time-varying payoff and plotting it to see what is happening. It does it with 2 separate approaches: First, it uses the backwards tspan approach, and the second it does a change of variables (i.e. t_tilde = T

  • t) and solves the resulting function of t_tilde from t_tilde = 0 to t_tilde = T.

You will see that the only time-varying thing in the PDE is the c_tilde function which is increasing with time. What I don't understand about this solution, is that it seems to me that the u(t,x) function should be increasing over time, since the payoff is increasing. Instead, unless I am missing something it seems to be decreasing.... Can you go carefully through this to see if the results make sense or if we setup a sign incorrectly? For example, if we swap the sign of the composition of the du, at least the u(t,x) seems to be increasing in t, as I would expect. Or maybe my prior that u(t,x) should be increasing is wrong itself?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JuliaDiffEq/PDERoadmap/issues/26, or mute the thread https://github.com/notifications/unsubscribe-auth/AdUH1wWWQYBtunnzJUJNg_YRauGJsiY0ks5t3cmcgaJpZM4UST4H .

-- Dongxiao Zhang (Steven) Ph.D Student Vancouver School of Economics The University of British Columbia

jlperla commented 6 years ago

Absolutely, thanks! And take your time to make sure things make sense in terms of the basic asset pricing example.

stevenzhangdx commented 6 years ago

I went through the code and everything looks good to me. Both plots look similar and the only difference is the order of t grids. If we reverse the horizontal axis in the second plot, the u(x, t) is increasing over time.

jlperla commented 6 years ago

Yes, but do the results make any sense? In particular, do the signs on the system of ODEs we are solving match everything correctly, and is the equation (and the sign of the du/dt capital gains) make sense given the time direction in both cases?

Note for the 2nd one, the reason the horizontal axis is flipped is that time is running backwards, but it is worth carefully going through that to make sure the interpretation of all of them is correct. Is this running backwards from T - 0.2 to T, etc.

jlperla commented 6 years ago

To see the underlying results rather than just looking at the graphs, you can go sol.t and then see sol[1] and sol[end] to see how the solution. In particular,

julia> sol.t'
1×6 RowVector{Float64,Array{Float64,1}}:
 0.2  0.199993  0.178176  0.113822  0.0494682  0.0

julia> sol[1]'
1×20 RowVector{Float64,Array{Float64,1}}:
 70.1644  70.3013  70.4967  70.7148  70.9389  …  72.8202  72.9058  72.9723  73.0182  73.0419

julia> sol[end]'
1×20 RowVector{Float64,Array{Float64,1}}:
 69.1168  69.2537  69.4491  69.6672  69.8913  …  71.7726  71.8582  71.9247  71.9705  71.9943

Does that make sense? The u(t) function is larger when t=0.0 than when t=T=0.2? Or is there an interpretation issue here missing.

Lookign at manually changed equation going backwards in time,

julia> sol_reversed.t'
1×6 RowVector{Float64,Array{Float64,1}}:
 0.0  6.86452e-6  0.022158  0.0862929  0.150428  0.2

julia> sol_reversed[1]'
1×20 RowVector{Float64,Array{Float64,1}}:
 70.1644  70.3013  70.4967  70.7148  70.9389  …  72.8202  72.9058  72.9723  73.0182  73.0419

julia> sol_reversed[end]'
1×20 RowVector{Float64,Array{Float64,1}}:
 71.1236  71.2604  71.4559  71.674  71.898  72.1201  …  73.7793  73.865  73.9314  73.9773  74.001

i.e. increasing as it goes back in time?

jlperla commented 6 years ago

OK, now that we fixed the f_reversed bug and better understand things: To summarize the results of the analysis: for a system of ODEs

du/dt = f(t, u)

where u(T) is given as the terminal condition from the solution to f(T, u(T)) = 0 and we are interesting in solving the system for t = 0, ... T

When using the ODE framework