mattja / sdeint

Numerical integration of Ito or Stratonovich SDEs
GNU General Public License v3.0
155 stars 25 forks source link

Expectation and Variance #18

Closed Peter230655 closed 2 years ago

Peter230655 commented 3 years ago

I love to play around (that is all I am doing, I am semi retired) with SDEINT. It gives possible realizations of the stochastic system. ( I usually use sympy.physics.mechanics to get equations of motion for some mechanical system, and then ‚exite it‘ with white noise forces).

It would be nice, if in addition, one could get the expectation and the variance of the solution. Something like:

R, E, V = itoint(f, G, times, all=True) giving everything R = itoint(f, G, times, all=False) giving only a realisation

Just a thought.

mattja commented 2 years ago

With the exception of some very simple systems, the mean and variance would just be estimated from a sample, after simulating multiple sample paths. It is quite quick to do that using numpy after simulation (or during iterated simulation), so I think not necessary to add this to sdeint itself.

Peter230655 commented 2 years ago

Dear Matt, I thought, mean and variance of the solution of a stochastic differential equation could also be obtained by a integration - but of course, I am not sure. (Would the mean not simply be the integration of the deterministic part of the system, that is without the „dW“ part?) Of course, they way you propose makes sense and certainly would be fast and simple! Take care, Peter

On Sun 13. Feb 2022 at 08:12 Matthew Aburn @.***> wrote:

With the exception of some very simple systems, the mean and variance would just be estimated from a sample, after simulating multiple sample paths. It is quite quick to do that using numpy after simulation (or during iterated simulation), so I think not necessary to add this to sdeint itself.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/18#issuecomment-1037875116, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUXDZGJ4LTVW7HJ23GDU25KWRANCNFSM5CR4YXNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Best regards,

Peter Stahlecker

Peter230655 commented 2 years ago

Dear Matt,

I checked around my book on stochastic calculus a bit ( I am just a semi retired sales man, not a scientist or mathematician)

The SDE your program solves looks like this:

dX = f(F, t) dt + G(X, t) dW

Now, what I think I found is this:

1. m(t) := E[X(t)] is the solution of: dm/dt = f(m, t)

2. Var(t) : = E[X(t)X(t).T] is the solution of: dVar/dt = G(X, t) G(X, t).T

I feel quite sure about point 1, but not very sure about point 2. Unless G(X, t) has some special form, how does one get a ODE of the form) dVar/dt = F(Var, t) ?

Any help is highly appreciated!

Thanks, Peter

On Sun 13. Feb 2022 at 10:37 Peter Stahlecker @.***> wrote:

Dear Matt, I thought, mean and variance of the solution of a stochastic differential equation could also be obtained by a integration - but of course, I am not sure. (Would the mean not simply be the integration of the deterministic part of the system, that is without the „dW“ part?) Of course, they way you propose makes sense and certainly would be fast and simple! Take care, Peter

On Sun 13. Feb 2022 at 08:12 Matthew Aburn @.***> wrote:

With the exception of some very simple systems, the mean and variance would just be estimated from a sample, after simulating multiple sample paths. It is quite quick to do that using numpy after simulation (or during iterated simulation), so I think not necessary to add this to sdeint itself.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/18#issuecomment-1037875116, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUXDZGJ4LTVW7HJ23GDU25KWRANCNFSM5CR4YXNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Best regards,

Peter Stahlecker

-- Best regards,

Peter Stahlecker

mattja commented 2 years ago

Hi Peter, Both 1. and 2. are false in general.

Peter230655 commented 2 years ago

Dear Matt,

Thanks for your prompt reply, even if disappointing! :-)) I thought, Expectation[ integral (f(X, t) * dW) ] = 0 , for any 'reasonable' f(X, t), and W ...white noise ? Anyway, I have to accept that no closed formula is available. Thanks & take care!

Peter

Am Mo., 14. Feb. 2022 um 01:29 Uhr schrieb Matthew Aburn < @.***>:

Hi Peter, Both 1. and 2. are false in general.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/18#issuecomment-1038495366, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUSCR3HA7HLFIIZUQTTU3BEHNANCNFSM5CR4YXNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Peter230655 commented 2 years ago

Dear Matt,

I think, I finally understood: I guess the reason is that E [ f(x(t) ] not equal to f ( E[ x(t) ] ) in general. Is my thinking on the right track? Thanks, Peter

Am Mo., 14. Feb. 2022 um 07:30 Uhr schrieb Peter Stahlecker < @.***>:

Dear Matt,

Thanks for your prompt reply, even if disappointing! :-)) I thought, Expectation[ integral (f(X, t) * dW) ] = 0 , for any 'reasonable' f(X, t), and W ...white noise ? Anyway, I have to accept that no closed formula is available. Thanks & take care!

Peter

Am Mo., 14. Feb. 2022 um 01:29 Uhr schrieb Matthew Aburn < @.***>:

Hi Peter, Both 1. and 2. are false in general.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/18#issuecomment-1038495366, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUSCR3HA7HLFIIZUQTTU3BEHNANCNFSM5CR4YXNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Peter230655 commented 2 years ago

Dear Matt,

I obviously like to play around with your sdeint program, hence my question:

I have created an equation of motion of some mechanical system, as I do it with sympy.phisics.mechanics, it is of the form

dX(t) = rhs(X(t), t, F), where F are external forces, which I want to model as white noise. Say dim(X) = n, dim(F) = m

  1. I create: G(X, t) = rhs.jacobian(F) ( dim(G) = (n x m )

  2. I create: f(X, t) = rhs(X, t, F).substitue(F_i = 0., i = 1, .., m)

  3. I integrate dX(t) = f(X, t) dt + G(X, t) dW using your program sdeint.

Is this the proper approach?

Thanks a lot, Peter

On Fri 18. Feb 2022 at 15:03 Peter Stahlecker @.***> wrote:

Dear Matt,

I think, I finally understood: I guess the reason is that E [ f(x(t) ] not equal to f ( E[ x(t) ] ) in general. Is my thinking on the right track? Thanks, Peter

Am Mo., 14. Feb. 2022 um 07:30 Uhr schrieb Peter Stahlecker < @.***>:

Dear Matt,

Thanks for your prompt reply, even if disappointing! :-)) I thought, Expectation[ integral (f(X, t) * dW) ] = 0 , for any 'reasonable' f(X, t), and W ...white noise ? Anyway, I have to accept that no closed formula is available. Thanks & take care!

Peter

Am Mo., 14. Feb. 2022 um 01:29 Uhr schrieb Matthew Aburn < @.***>:

Hi Peter, Both 1. and 2. are false in general.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/18#issuecomment-1038495366, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUSCR3HA7HLFIIZUQTTU3BEHNANCNFSM5CR4YXNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Best regards,

Peter Stahlecker

Peter230655 commented 2 years ago

Dear Matt,

Is there a way to pass arguments to the itoint routine of your package? The examples do not seem to show it - but I might very well be wrong!

Thanks!

Peter

On Fri 18. Feb 2022 at 17:19 Peter Stahlecker @.***> wrote:

Dear Matt,

I obviously like to play around with your sdeint program, hence my question:

I have created an equation of motion of some mechanical system, as I do it with sympy.phisics.mechanics, it is of the form

dX(t) = rhs(X(t), t, F), where F are external forces, which I want to model as white noise. Say dim(X) = n, dim(F) = m

  1. I create: G(X, t) = rhs.jacobian(F) ( dim(G) = (n x m )

  2. I create: f(X, t) = rhs(X, t, F).substitue(F_i = 0., i = 1, .., m)

  3. I integrate dX(t) = f(X, t) dt + G(X, t) dW using your program sdeint.

Is this the proper approach?

Thanks a lot, Peter

On Fri 18. Feb 2022 at 15:03 Peter Stahlecker @.***> wrote:

Dear Matt,

I think, I finally understood: I guess the reason is that E [ f(x(t) ] not equal to f ( E[ x(t) ] ) in general. Is my thinking on the right track? Thanks, Peter

Am Mo., 14. Feb. 2022 um 07:30 Uhr schrieb Peter Stahlecker < @.***>:

Dear Matt,

Thanks for your prompt reply, even if disappointing! :-)) I thought, Expectation[ integral (f(X, t) * dW) ] = 0 , for any 'reasonable' f(X, t), and W ...white noise ? Anyway, I have to accept that no closed formula is available. Thanks & take care!

Peter

Am Mo., 14. Feb. 2022 um 01:29 Uhr schrieb Matthew Aburn < @.***>:

Hi Peter, Both 1. and 2. are false in general.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/18#issuecomment-1038495366, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUSCR3HA7HLFIIZUQTTU3BEHNANCNFSM5CR4YXNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Best regards,

Peter Stahlecker

-- Best regards,

Peter Stahlecker