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

Real noise with complex SDEs with nondiagonal diffusion #543

Closed
AshtonSBradley opened this issue Sep 1, 2023 · 2 comments
Closed

Real noise with complex SDEs with nondiagonal diffusion #543

AshtonSBradley opened this issue Sep 1, 2023 · 2 comments

Comments

@AshtonSBradley
Copy link

AshtonSBradley commented Sep 1, 2023

I am trying to use real noise with a complex SDE with nondiagonal noise. I hit an error to do with sizing of the diffusion matrix compared to the noise vector. Here is a MWE that reproduces the error:

using DifferentialEquations
f(du, u, p, t) = du .= 1.01u
function g(du, u, p, t)
    du[1, 1] = 0.3u[1]
    du[1, 2] = 0.6u[1]
    du[1, 3] = 0.9u[1]
    du[1, 4] = 0.12u[1]
    du[2, 1] = 1.2u[2]
    du[2, 2] = 0.2u[2]
    du[2, 3] = 0.3u[2]
    du[2, 4] = 1.8u[2]
end

prob = SDEProblem(f, g, randn(ComplexF64,2), (0.0, 1.0), noise_rate_prototype =complex(zeros(2, 4)),noise=RealWienerProcess(0.0,0.0))

sol = solve(prob)

throwing the error:

ERROR: DimensionMismatch: first array has length 2 which does not match the length of the second, 8.

Is it a real issue, or am I doing something wrong in the setup?

@AshtonSBradley AshtonSBradley changed the title Real noise with complex SDEs Real noise with nondiagonal complex SDEs Sep 2, 2023
@AshtonSBradley AshtonSBradley changed the title Real noise with nondiagonal complex SDEs Real noise with complex SDEs with nondiagonal diffusion Sep 2, 2023
@ChrisRackauckas
Copy link
Member

You defined a scalar Wiener Process but then your g is defined for a 4-dimensional Wiener process. You need to make sure that your dimensional choices match.

using DifferentialEquations
f(du, u, p, t) = du .= 1.01u
function g(du, u, p, t)
    du[1, 1] = 0.3u[1]
    du[1, 2] = 0.6u[1]
    du[1, 3] = 0.9u[1]
    du[1, 4] = 0.12u[1]
    du[2, 1] = 1.2u[2]
    du[2, 2] = 0.2u[2]
    du[2, 3] = 0.3u[2]
    du[2, 4] = 1.8u[2]
end

prob = SDEProblem(f, g, randn(ComplexF64,2), (0.0, 1.0), noise_rate_prototype =complex(zeros(2, 4)),noise=RealWienerProcess(0.0,zeros(4)))

sol = solve(prob)

ChrisRackauckas added a commit to SciML/DiffEqBase.jl that referenced this issue Sep 3, 2023
```julia
using DifferentialEquations
f(du, u, p, t) = du .= 1.01u
function g(du, u, p, t)
    du[1, 1] = 0.3u[1]
    du[1, 2] = 0.6u[1]
    du[1, 3] = 0.9u[1]
    du[1, 4] = 0.12u[1]
    du[2, 1] = 1.2u[2]
    du[2, 2] = 0.2u[2]
    du[2, 3] = 0.3u[2]
    du[2, 4] = 1.8u[2]
end

prob = SDEProblem(f, g, randn(ComplexF64,2), (0.0, 1.0), noise_rate_prototype =complex(zeros(2, 4)),noise=RealWienerProcess(0.0,zeros(3)))

sol = solve(prob)
```

```
ERROR: Noise sizes are incompatible. The expected number of noise terms in the defined
`noise_rate_prototype` does not match the number of noise terms in the defined
`AbstractNoiseProcess`. Please ensure that
size(prob.noise_rate_prototype,2) == length(prob.noise.W[1]).

Note: Noise process definitions require that users specify `u0`, and this value is
directly used in the definition. For example, if `noise = WienerProcess(0.0,0.0)`,
then the noise process is a scalar with `u0=0.0`. If `noise = WienerProcess(0.0,[0.0])`,
then the noise process is a vector with `u0=0.0`. If `noise_rate_prototype = zeros(2,4)`,
then the noise process must be a 4-dimensional process, for example
`noise = WienerProcess(0.0,zeros(4))`. This error is a sign that the user definition
of `noise_rate_prototype` and `noise` are not aligned in this manner and the definitions should
be double checked.

size(prob.noise_rate_prototype,2) = 4
length(prob.noise.W[1]) = 3
```

Should be a much better message for SciML/StochasticDiffEq.jl#543
@ChrisRackauckas
Copy link
Member

Handled with a better error message in SciML/DiffEqBase.jl#921

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