Skip to content

[BUG] AttributeError: module 'numpy' has no attribute 'math' in 1_feature_overview [5] # Instantiate and fit the SINDy model #569

@michaelkalz

Description

@michaelkalz

I get "AttributeError: module 'numpy' has no attribute 'math'" when I run cell [5] in the binder notebook

Reproducing code example:

model = ps.SINDy()
model.fit(x_train, t=dt)
model.print()

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions