GithubHelp home page GithubHelp logo

Comments (14)

Jacob-Stevens-Haas avatar Jacob-Stevens-Haas commented on August 19, 2024

PI is my least familiar part of the repo, but I see why it might not. But it looks like it creates coef_ in the correct shape, so what happens if you give it a try?

from pysindy.

niuyushuo avatar niuyushuo commented on August 19, 2024

PI is my least familiar part of the repo, but I see why it might not. But it looks like it creates coef_ in the correct shape, so what happens if you give it a try?

Thanks for your response. After getting the fitted implicit ODEs model, model.predict() works well.
To demonstrate the question, here are two models from my results:

x0_t = -0.031 1 + -0.104 x2 + 0.053 x5 + 0.132 x6 + 0.081 x0x1 + 0.024 x0x0 + -0.843 x5_t + 0.728 x0x0_t
x7_t = 0.015 1 + -0.044 x0 + 0.054 x5 + -0.156 x7 + 0.002 x0x1 + 0.030 x0x0

Follow your suggestion, save the model coefficient by: coefs = model.coefficients()
If I let the coefficients corresponding to x7_t (which has no x_t terms on the right hand side) loop the dataset, will get the same results compared to the resutls from model.predict(). It is consistent with the documentation which is 'result = [self.model.predict([xi]) for xi in x]'.
Then the question is how model.predict() loop data if there are x_t terms on the right hand side of implicit ODEs model?
Thanks.

from pysindy.

Jacob-Stevens-Haas avatar Jacob-Stevens-Haas commented on August 19, 2024

I'm sorry, I don't understand everything you've done. How many models did SINDyPI fit in your example? And what do you mean when you say you "let the coefficients corresponding to x7_t loop the dataset?"

from pysindy.

niuyushuo avatar niuyushuo commented on August 19, 2024

I'm sorry, I don't understand everything you've done. How many models did SINDyPI fit in your example? And what do you mean when you say you "let the coefficients corresponding to x7_t loop the dataset?"

Hi thanks for your response.
For the first question, my dataset has 8 features. The library functions are defined below:

library_functions = [
    lambda x: x,
    lambda x, y: x * y,
    lambda x: x ** 2,
]
x_dot_library_functions = [lambda x: x]

library_function_names = [
    lambda x: x,
    lambda x, y: x + y,
    lambda x: x + x,
] 

So I got a total of 405 models (model0 -model404).
For the second question, I picked up model 45 and model 53 which are

x0_t = -0.031 1 + -0.104 x2 + 0.053 x5 + 0.132 x6 + 0.081 x0x1 + 0.024 x0x0 + -0.843 x5_t + 0.728 x0x0_t
x7_t = 0.015 1 + -0.044 x0 + 0.054 x5 + -0.156 x7 + 0.002 x0x1 + 0.030 x0x0

The reason I picked up those two as the first model has x_t terms on the right hand side and the second one does not.
I am using those two models to try to understand how model. predict () works.
As described in the documentation, the model.predict() works as 'result = [self.model.predict([xi]) for xi in x]'.
https://github.com/dynamicslab/pysindy/blob/master/pysindy/pysindy.py, at line 274
If I get the coefficients from x7_t, and loop the dataset. The results are consistent with the results model.predict(dataset)[:,53].
Then the question is just like the title, how model.predict() works if the fitted model (just like model x0_t here) has x_t terms on the right hand side? We only give x (to be input) to this function instead of x_t.
I test model.predict(dataset) by myself, and it works without any issues. Thanks.

from pysindy.

Jacob-Stevens-Haas avatar Jacob-Stevens-Haas commented on August 19, 2024

Which library are you using? PDELibrary, or CustomLibrary?

from pysindy.

niuyushuo avatar niuyushuo commented on August 19, 2024

It is PDELibrary.
Here is my code:

sindy_library = ps.PDELibrary(
    library_functions=library_functions,
    temporal_grid=t,
    function_names=library_function_names,
    include_bias=True,
    implicit_terms=True,
    derivative_order=1
)


sindy_opt = ps.SINDyPI(      ### lambda = threshold^2 / (2 * nu)
    threshold=1e-2,
    tol=1e-8,
    thresholder="l1",
    max_iter=20000,
)

model = ps.SINDy(
    optimizer=sindy_opt,
    feature_library=sindy_library,
    differentiation_method=ps.SINDyDerivative(kind="kalman", alpha=0.6)
)

model.fit(X_sm_poly, t=t)
model.print()

sindy_library.get_feature_names()

from pysindy.

Jacob-Stevens-Haas avatar Jacob-Stevens-Haas commented on August 19, 2024

My guess is that predict is giving you bad outputs. I don't think you can trust what you get out. My guess is that SINDyPI is reordering the features internally between each model it's fitting.

Also, you can format your code in Github comments. Heads up, I did this for a few of your comments.

from pysindy.

niuyushuo avatar niuyushuo commented on August 19, 2024

OK, thanks for your reply. I just wonder, for the multiple features implicit ODE model, is there any function/way in pysindy to evaluate each fitted model? If I follow the example 9_sindypi_with_sympy.ipynb. The method from 'Check all the model fits produce sensible models' to 'integrate and plot the new equations for x_dot' part, only works for single feature ODE model. I tested by myself, this method could not work for multiple features. Thanks.

from pysindy.

Jacob-Stevens-Haas avatar Jacob-Stevens-Haas commented on August 19, 2024

I'm sorry, you would need to troubleshoot further. That code involves heavy use of sympy, which I've never used. Specifically, can you see where pysindy provides something unexpected?

from pysindy.

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.