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

Accessing EnsembleSolution elements #105

Open
Skumin opened this issue Sep 13, 2022 · 1 comment
Open

Accessing EnsembleSolution elements #105

Skumin opened this issue Sep 13, 2022 · 1 comment

Comments

@Skumin
Copy link

Skumin commented Sep 13, 2022

I'm trying to use diffeqpy to simulate some trajectories of the geometric Brownian motion but I'm having some issues accessing the elements of the solution.

My code is the following:

from diffeqpy import de
import numpy as np

def gbm(A0, mu, sigma, t0, t1, dt=0.01, trajectories=1):
    def f(du, u, p, t):
        du[0] = u[0] * p[0]

    def g(du, u, p, t):
        du[0] = u[0] * p[1]

    prob = de.SDEProblem(f, g, [A0], (t0, t1), [mu, sigma])
    eprob = de.EnsembleProblem(prob)

    return de.solve(
        eprob,
        de.SRIW1(),
        de.EnsembleThreads(),
        dt=dt,
        adaptive=False,
        trajectories=trajectories,
    )

res = gbm(100.0, 0.05, 0.2, 0.0, 1.0, trajectories=5)

In Julia, I would do simply res[1] to get the first path. I could then also do res[1](x) to get the value of that path at some arbitrary x in the domain of the solution. Can I do this in Python somehow?

When I try res[0] in Python, I get an error:

>>> res[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'PyCall.jlwrap' object is not subscriptable

I know that I could bypass this partly by using saveat=np.arange(t0, t1 + dt, dt), for example, in the call to de.solve, but that requires knowing x in advance.

@ChrisRackauckas
Copy link
Member

res.u[i] works, the indexing doesn't seem to carry over for some reason.

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