GithubHelp home page GithubHelp logo

Comments (4)

shuheng-liu avatar shuheng-liu commented on June 20, 2024

Hi Pablo, can you provide a minimal example of what you're trying to solve so that we can have a more specific context?

from neurodiffeq.

shuheng-liu avatar shuheng-liu commented on June 20, 2024

If I understand correctly, you are trying to solve ODEs w.r.t. u(t) involving a time-dependent coefficient (say θ(t)), where both the solution u(t) and the coefficient θ(t) are unknown. This is essentially the same as solving ODEs w.r.t. two unknown functions (u(t), θ(t)). If this is the case, the Lotka-Volterra equation in the README is a good example.

(If you don't want to enforce any initial condition for θ, you can put a neurodiffeq.conditions.NoCondition() instance as a placeholder.

from neurodiffeq.

pabloacera avatar pabloacera commented on June 20, 2024

Hi Shuheng-liu,

Thanks for the quick response. I can provide the systems of ODE that I am trying to solve.
image
I have a dataset with u and s over time and I was wondering if I could use this package to find the other variables through time. Thanks a lot! any insights would be very valuable.

from neurodiffeq.

shuheng-liu avatar shuheng-liu commented on June 20, 2024

Hi Pablo,

Assuming your data is free of noise, you can recover u(t) and s(t) by interpolating discrete data points (ti, ui) and (ti, si).
You can also recover the derivatives du/dt and ds/dt if your interpolant is differentiable (say Lagrangian polynomial).

This way, the problem is essentially solving an ODE system w.r.t. three unkonwn functions alpha(t), beta(t), and gamma(t).

from neurodiffeq import diff
from neurodiffeq.solvers import Solver1D
from neurodiffeq.conditions import NoCondition
import matplotlib.pyplot as plt

u_interp = lambda t: ... # some interpolant function (note: t is a torch.Tensor)
s_interp = lambda t: ... # some interpolant function

def eq(alpha, beta, gamma, t):
    u, s = u_interp(t), s_interp(t)
    dudt, dsdt = diff(u, t), diff(s, t)

    return [
        alpha - beta * u - dudt,
        beta * u - gamma * s - dsdt,
    ]

conditions = [
    NoCondition(),  # no constraint for alpha
    NoCondition(),  # no constraint for beta
    NoCondition(),  # no constraint for gamma
]

T_MIN, T_MAX = 0, 1

solver = Solver1D(
    eq, 
    conditions,
    t_min=T_MIN,
    t_max=T_MAX,
    n_batches_valid=1,  # [Optional] to speed up computation
)

solver.fit(max_epochs=10)

solution = solver.get_solution(best=True, copy=True)

t = np.linspace(T_MIN, T_MAX, 100)
alpha, beta, gamma = solution(t, to_numpy=True)

plt.plot(t, alpha, label='alpha')
plt.plot(t, beta, label='beta')
plt.plot(t, gamma, label='gamma')
plt.legend()

If you have constraints for alpha, beta, or gamma, you can change the corresponding entry in conditions to neurodiffeq.conditions.IVP(..., ...) or neurodiffeq.conditions.DirichletBVP(..., ...). See documentation for details.

from neurodiffeq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.