-
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
[BUG] AttributeError: module 'numpy' has no attribute 'math' in 1_feature_overview [5] # Instantiate and fit the SINDy model #569
Comments
I have the same issue with the notebook for the original paper. I'm on Python 3.10, Numpy 2.0, Pysindy 1.7.5 Monkey patching may fix the immediate problem:
However for me the notebook still failed to execute due to subsequent errors. BTW, I've noticed that latest dev doesn't seem to have this |
Related: #551 |
I had the same issue as @humatic, but after fixing the numpy bug, the major problem was the self differentiation function and that of the optimizer and I don't know how to go about it. |
I'm having the same error. You can see it in the logs for my unit tests of my interfere package For what it's worth, this stack exchange makes it sound like |
Also, most of my unit tests for SINDY passed. Only the tests that use a mix of differentiation methods failed. |
Facing the same issue. Downgrading numpy to "1.26.4" as mentioned here does the trick #551. |
Here's what worked for me: import math |
When using customized libraries (
|
I get "AttributeError: module 'numpy' has no attribute 'math'" when I run cell [5] in the binder notebook
Reproducing code example:
Error message:
AttributeError Traceback (most recent call last)
Cell In[5], line 3
1 # Instantiate and fit the SINDy model
2 model = ps.SINDy()
----> 3 model.fit(x_train, t=dt)
4 model.print()
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/pysindy.py:343, in SINDy.fit(self, x, t, x_dot, u, multiple_trajectories, unbias, quiet, ensemble, library_ensemble, replace, n_candidates_to_drop, n_subset, n_models, ensemble_aggregator)
337 u = validate_control_variables(
338 x,
339 u,
340 trim_last_point=(self.discrete_time and x_dot is None),
341 )
342 self.n_control_features_ = u[0].shape[u[0].ax_coord]
--> 343 x, x_dot = self._process_multiple_trajectories(x, t, x_dot)
345 # Set ensemble variables
346 self.ensemble = ensemble
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/pysindy.py:665, in SINDy._process_multiple_trajectories(self, x, t, x_dot)
663 x = [xi[:-1] for xi in x]
664 else:
--> 665 x_dot = [
666 self.feature_library.calc_trajectory(
667 self.differentiation_method, xi, ti
668 )
669 for xi, ti in _zip_like_sequence(x, t)
670 ]
671 return x, x_dot
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/pysindy.py:666, in (.0)
663 x = [xi[:-1] for xi in x]
664 else:
665 x_dot = [
--> 666 self.feature_library.calc_trajectory(
667 self.differentiation_method, xi, ti
668 )
669 for xi, ti in _zip_like_sequence(x, t)
670 ]
671 return x, x_dot
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/feature_library/base.py:87, in BaseFeatureLibrary.calc_trajectory(self, diff_method, x, t)
85 def calc_trajectory(self, diff_method, x, t):
86 axes = x.dict
---> 87 x_dot = diff_method(x, t=t)
88 return AxesArray(x_dot, axes)
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/differentiation/base.py:49, in BaseDifferentiation.call(self, x, t)
48 def call(self, x, t=1):
---> 49 return self._differentiate(x, t)
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/differentiation/finite_difference.py:237, in FiniteDifference._differentiate(self, x, t)
234 if not np.isscalar(t):
235 dt = t[1] - t[0]
--> 237 coeffs = self._constant_coefficients(dt)
238 dims = np.array(x.shape)
239 dims[self.axis] = x.shape[self.axis] - (self.n_stencil - 1)
File /srv/conda/envs/notebook/lib/python3.10/site-packages/pysindy/differentiation/finite_difference.py:199, in FiniteDifference._constant_coefficients(self, dt)
195 matrices = (dt * (np.arange(self.n_stencil) - (self.n_stencil - 1) // 2))[
196 np.newaxis, :
197 ] ** pows
198 b = np.zeros(self.n_stencil)
--> 199 b[self.d] = np.math.factorial(self.d)
200 return np.linalg.solve(matrices, b)
File /srv/conda/envs/notebook/lib/python3.10/site-packages/numpy/init.py:414, in getattr(attr)
411 import numpy.char as char
412 return char.chararray
--> 414 raise AttributeError("module {!r} has no attribute "
415 "{!r}".format(name, attr))
AttributeError: module 'numpy' has no attribute 'math'
PySINDy/Python version information:
Binder Notebook from here.
The text was updated successfully, but these errors were encountered: