-
Notifications
You must be signed in to change notification settings - Fork 328
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
Weak SINDY for higher order ODEs #159
Comments
Hi Bhumika, The quick answer is that yes, you can do this, and the easiest way is to convert everything into a coupled system of 1st-order ODEs. In that case, you can repeat exactly what you did with the Van Der Pol equation, and indeed you need to have x, x', x'', and x''' available. Then you could integrate each of these (integrating by parts the derivative terms) and stack them together as [weak_form(x), weak_form(x'), ...] and fit a system of 1st-order equations. This is rather laborious so instead I have made a few tiny changes to the code so that you can fit a fourth order equation like this directly from data in x, including allowing for time derivatives in the library. I have pushed these changes to a new branch of the code weak_form_temporal_derivatives, and let me know if you have any issues with obtaining the code. Here is an example that should work correctly with the new code:
Best, |
@znicolaou I think we should include a flag that decides whether or not to include the temporal derivatives in the PDELibrary and WeakPDELibrary going forward, since Bhumika's case is actually not a particularly uncommon one. I'll add this to your branch whenever I get around to the pull request review. |
Many thanks Alan @akaptano for the modified code and the example. It is working well. However, I have another question regarding this. What if the differential equation in the example above had higher powers of derivatives? For example, consider the equation Best regards, |
To generate those kind of terms, you can use the GeneralizedLibrary class. With this class you can specify two (or more) separate libraries for x, x', x'', etc. so that for instance, your total library has cubic terms with x and up to quadratic terms in x''. You can also tensor all the sub-libraries together to generate mixed-library terms. Check out https://www.youtube.com/watch?v=UA8C8sccU54 and examples are also included in the Example 1 and Example 15 Jupyter notebooks. |
@akaptano Thanks very much! I looked into the GeneralizedLibrary class but I am facing a few issues in implementing it. (2) So, I tensored the WeakPDE library with itself (see the example code below) which generated a lot of duplicate terms in the tensored library. To remove the duplicate terms, I used the constrained optimizer but I haven't been able to recover the "correct" model. (3) Also, when I use the tensored library, I have to take the value of "K" equal to the length of the training data. Otherwise I get the following error (where the length of my training data is 10000 and K=100) IndexError: boolean index did not match indexed array along dimension 0; dimension is 10000 but corresponding boolean dimension is 100 See below a code for solving the differential equation
|
Looks like there are more bugs in the Tensor/GeneralizedLibrary than I anticipated. Given that, I think your easiest route forward is to convert this into a system of 1st-order ODEs and use that with the weak form. I have push a few changes to get things working on the weak_form_temporal_derivatives and you should be able to correctly run the following:
|
@znicolaou Just a heads up for the weak formulation update... currently the TensoredLibrary does not allow for weak terms (and therefore neither does the GeneralizedLibrary if any of the libraries are tensored together) and this would be a good fix. The fix is straightforward... basically just need to make sure "n_samples" is correct, since this number changes in the weak form. I made a hack-ish fix to this branch so that it works for Bhumika's application. |
Thanks very much Alan @akaptano for your help and the fix. I really appreciate it! |
Very happy to help, and please let me know if you find any other issues. This portion of the code is fairly buggy but hopefully you can make do with the type of code I showed above :) |
Sure, I will let you know. Thanks again. |
This is now implemented in the most recent branch! |
Hi,
Can Weak SINDY be used on higher order ordinary differential equations, for example the van der Pol equation (a second order differential equation):
x''(t) - mu (1-x^2) x' + x = 0
(where x' is the first order time derivative, x'' is the second order time derivative, and mu is a constant),
such that we only give the time series of x in the training data and Weak SINDy gives back either a second order differential equation or two first order differential equations for x and x'?
There is an option "derivative_order" in the weak SINDy library but I guess it is only meant for the order of the spatial derivatives in feature library.
If I have a time series of x given to me and I calculate x' (lets name it y) using some numerical methods and give the time series of both x and x' in the training data, Weak SINDy is correctly able to identify the van der Pol equation in the form of coupled set of two first order differential equations:
x' = y
y'= mu (1-x^2) x' - x
So if I have a time series x as a solution of a fourth order differential equation, say,
x''''(t) = f(x,x',x'',x''')
do I need to calculate the numerical derivatives of x up to third order and give x,x',x'',and x''' in the training data to weak SINDy so that it can identify the coupled set of 4 first order differential equations in x,x',x'', and x'''?
Thanks very much in advance.
Best regards,
Bhumika
The text was updated successfully, but these errors were encountered: