-
Notifications
You must be signed in to change notification settings - Fork 331
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
Request for advice about shape of control_features when using PDELibrary #164
Comments
Hi Anirban, Could you explain why the data is shape (123, 2001, 1)? For instance, is the training data a set of 123 trajectories, each of 2001 time points, and in a 1D state space? Or are you trying to fit a 123D system of ODEs? Or is this a spatiotemporal field that is function of 123 spatial grid points and 2001 temporal grid points? Please also post your PySINDy version, since there are some known bugs in the reshaping in the previous few versions. Best, |
Thanks for your prompt response. As you said, my data is a spatiotemporal field with 123 spatial grid points and 2001 temporal grid points. I want to employ two different control variables separately,i.e., one is constant over the spatiotemporal grid, and another is varying. I have reshaped my spatiotemporal field to (Nx, Nt, 1) following the PDEFIND example. Name: pysindy Regards, |
Excellent, so your data appears to be in the correct shape to fit a PDE model with controls. Can you print how you are initializing the pysindy.PDELibrary that you are using for the model? Note that for spatiotemporal fields you need to be using the PDELibrary class |
Initialization of SINDy model: library_functions = [lambda x: x, |
What is the shape of space_arr and can you try this with periodic=False? |
space_arr has a size of 123. STLSQ model: STLSQ model: |
time_arr has a size of 2001. |
Hi, any suggestions on how to solve this error. |
Yes, this is a legit bug that we will fix in the coming release. For now, you need to take the lines
in pysindy.py and move them to right above the lines
This will fix the bug. You should now be able to run the following full example:
|
Thanks a lot. |
@akaptano I tried to modify the same code for multiple trajectories as follows: from typing import Sequence if isinstance(U, Sequence): model.fit(X, u=U, t=t_arr, multiple_trajectories=True) I am getting the following error: X is a list. Moreover, when I am trying to simulate the same data from the model from the initial condition, I am facing the following error: t_arr = np.linspace(1, 2001, 2001) def ufunc(time): sim = model.simulate(x[:, 0, 0], u=ufunc, t=t_arr, interpolator=CubicSpline) capi_return is NULL Regards, |
Hi Anirban, Yes this is a similar issue. To my knowledge you are the first person trying to identify PDEs with control inputs with the new functionality. I will implement a fix in the next release. For now you can simply omit multiple_trajectories and just concatenate all your trajectories together (this is what the code does anyways). So now your data should have shape (123, 2001 * n_trajectories, 1) and similar for u. Sorry for the inconvenience. |
I believe this is resolved in the new release, closing this now. |
@akaptano After building the SINDy model, when I am trying to simulate the future behaviour with inputs: initial condition of shape (122, 8, 1, 2) and time-array of size 1001, I get the following error: Traceback (most recent call last): pysindy package details: |
This one is exactly what the error message says. The y0 in model.simulate (using scipy solve_ivp) should be a single point in your state at time t0... so if your state space is 2, it should be size 2. Assuming that your "extra" dimensions are actually spatial dimensions, it would not even make sense to use model.simulate, because this is an ODE solver not a PDE solver! |
@akaptano Thanks, I have missed that. To simulate future behavior for spatio-temporal dynamical system, what one should do? And yes, my data-frame is dependent on x, y, t. 2001 sample points are taken along time-axis. |
General PDE solvers are very complicated! PDE solvers are typically chosen based on the type of PDE (for instance, linear PDEs can be solved with Fourier transforms). For these reasons we do not provide any PDE solvers in PySINDy -- you must build or find PDE solvers appropriate for your identified PDE. |
I have a data frame of size (123, 2001, 1). I am trying to fit this data into a SINDy model with a control value, u. u has the same shape as the data frame, the following error comes up:
Traceback (most recent call last):
File "SINDy_trial.py", line 100, in
model.fit(my_d1, u=depthOnenm, t=time_arr)
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/pysindy.py", line 299, in fit
u = validate_control_variables(
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/utils/base.py", line 75, in validate_control_variables
u_arr = _check_control_shape(x, u, trim_last_point)
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/utils/base.py", line 98, in _check_control_shape
raise ValueError(
ValueError: control variables u must have same number of rows as x. u has 246123 rows and x has 123 rows
In the pysindy.py, line 296 shows self.n_control_features_ = u.shape[1]. So, I have reshaped my control_feature u to an array of size (246123, 1). In this case, I am getting the same valuerror:
At line 99 of base.py file, I made the following change,
And the following error comes up,
Traceback (most recent call last):
File "SINDy_trial.py", line 101, in
model.print()
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/pysindy.py", line 676, in print
eqns = self.equations(precision)
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/pysindy.py", line 658, in equations
return equations(
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/utils/base.py", line 391, in equations
input_features = pipeline.steps[0][1].get_feature_names(input_features)
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/feature_library/pde_library.py", line 212, in get_feature_names
self.function_names[i]([input_features[j] for j in c])
File "/home/ee_student/.local/lib/python3.8/site-packages/pysindy/feature_library/pde_library.py", line 212, in
self.function_names[i]([input_features[j] for j in c])
IndexError: list index out of range
Please let me know how to correctly employ the control input in the PDELibrary, i.e. what should be the size of the control array. I would greatly appreciate any help you could provide.
Regards,
Anirban
The text was updated successfully, but these errors were encountered: