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

ValueError in model simulation due to wrong assumption #94

Closed
msis opened this issue Sep 29, 2020 · 4 comments
Closed

ValueError in model simulation due to wrong assumption #94

msis opened this issue Sep 29, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@msis
Copy link

msis commented Sep 29, 2020

When calling model.simulate, it is assumed that time 1 is can be interpolated:

if ndim(u_fun(1)) == 1:

This assumption is wrong is t is a given array.

Example:

import numpy as np

import pysindy as ps

t = np.linspace(0, 1, 100)
u = np.array([0]*100)
x = np.power(t, 2)

model = ps.SINDy()
model.fit(
    x,
    t=t,
    u=u,
)
print(model.print())

def gen_u(t):
    return t

x0 = 6

t_test_success = np.arange(0, 1.1, 0.1)
u_test_success = gen_u(t_test_success)

t_test_fail = np.arange(0, 1, 0.1)
u_test_fail = gen_u(t_test_fail)

sim_success = model.simulate(
    [x0],
    t=t_test_success,
    u=u_test_success,
)
sim_fail = model.simulate(
    [x0],
    t=t_test_fail,
    u=u_test_fail,
)

In this example, sim_fail will raise a ValueError exception as 1 is out of the interpolation range (see linked line above).

Proposed fix:

Replace : if ndim(u_fun(1)) == 1: with if ndim(u_fun(t[0])) == 1: .

@briandesilva
Copy link
Member

Thanks for pointing this out. I'll push a fix this afternoon.

@briandesilva briandesilva self-assigned this Sep 29, 2020
@briandesilva briandesilva added the bug Something isn't working label Sep 29, 2020
@briandesilva
Copy link
Member

Fixed in 9d58553. I've got another bug fix or two in the pipeline that I'd like to bundle with this in a new release. It should be out by the end of the week. If you urgently need this fixed, feel free to clone the master branch and install it in development mode:

git clone https://github.com/dynamicslab/pysindy.git
cd pysindy
pip install -e .

@msis
Copy link
Author

msis commented Sep 29, 2020

Thanks @briandesilva !

I've been using the following work around for my situation:

sim_fail = model.simulate(
    [x0],
    t=t_test_fail-t_test_fail[0],
    u=u_test_fail,
)

@briandesilva
Copy link
Member

You shifted the time to start at 0—clever!

jpcurbelo pushed a commit to jpcurbelo/pysindy_fork that referenced this issue May 9, 2024
With the new datetime logic (neuralhydrology/neuralhydrology#30), the ensembling would fail because of a type incompatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants