If you have x_dot measurements and don't need to compute x_dot when using SINDyPI how do you implement that? #488
Unanswered
yemialabipurpose
asked this question in
Q&A
Replies: 1 comment
-
Hey, thanks for your question. 1) You're correct to pass Posted: model = ps.SINDy(
optimizer=sindy_opt,
feature_library=sindy_library,
differentiation_method=ps.FiniteDifference(drop_endpoints=True),
feature_names=feature_names)
model.fit(x_train, t=t_train, x_dot=dx_train, quiet=True)
model.print()` Traceback:
When you send |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am practising with a seven-state system where only two of the equations are implicit. I am using SINDyPI. I have both x and x_dot measurements so I don't want Pysindy to compute x_dot for me. How do I feed x_dot into the algorithm when using SINDyPI? how do I define differentiation method? I omitted it when initializing the SINDy model and fed x_dot in when fitting it but I get this error instead. ValueError: operands could not be broadcast together with shapes (798,1,798,3) (1,3,1) how can i fix it?
I expected the following 7 equations
wr_dot = K1 + K2theta + k3theta_dot #implicit
theta_dot = K(wt-wr)
wt_dot = K4 + K5theta + k6theta_dot #implicit
iqs_dot= K7 + K8iqs +K9ids+ K10(wreqs), + K11eds
ids_dot = K12 -K8ids -K9iqs+ K10(wreds), + K11eqs
eqs_dot = K13 +K14ids -K11eqs+ eds - K10(wreds)
eds_dot = K13 -K14iqs - K11eds - eds +K10(wreqs)
#K are the coefficients.
Here is the code with which i was trying to implement it.
`feature_names=['wr', 'theta', 'wt', 'iqs', 'ids', 'eqs', 'eds']
Initialize custom SINDy library
x_library_functions = [
lambda x: x,
lambda x, y: x * y,
]
x_dot_library_functions = [lambda x: x]
library function names includes both the
x_library_functions and x_dot_library_functions names.
library_function_names = [
lambda x: x,
lambda x, y: x + y,
#lambda x: x,
]
sindy_library = ps.SINDyPILibrary(
library_functions=x_library_functions,
t=t_train.flatten(),
function_names=library_function_names,
include_bias=True
)
sindy_opt = ps.SINDyPI(
threshold=1e-6,
tol=1e-8,
max_iter=20000,
)
model = ps.SINDy(
optimizer=sindy_opt,
feature_library=sindy_library,
differentiation_method=ps.FiniteDifference(drop_endpoints=True),
feature_names=feature_names)
model.fit(x_train, t=t_train, x_dot=dx_train, quiet=True)
model.print()`
when I run this code i get the following errors:
ValueError Traceback (most recent call last)
Cell In[79], line 36
25 sindy_opt = ps.SINDyPI(
26 threshold=1e-6,
27 tol=1e-8,
28 thresholder="l1",
29 max_iter=20000,
30 )
31 model = ps.SINDy(
32 optimizer=sindy_opt,
33 feature_library=sindy_library,
34 differentiation_method=ps.FiniteDifference(drop_endpoints=True),
35 feature_names=feature_names)
---> 36 model.fit(x_train, t=t_train, quiet=True)
37 model.print()
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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 ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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 ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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 ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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 ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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 ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pysindy\differentiation\finite_difference.py:251, in FiniteDifference._differentiate(self, x, t)
249 interior = interior + x[tuple(s)] * coeffs[i]
250 else:
--> 251 coeffs = self._coefficients(t)
252 interior = self._accumulate(coeffs, x)
253 s[self.axis] = slice((self.n_stencil - 1) // 2, -(self.n_stencil - 1) // 2)
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pysindy\differentiation\finite_difference.py:93, in FiniteDifference._coefficients(self, t)
90 self.stencil = np.transpose(t[self.stencil_inds])
92 pows = np.arange(self.n_stencil)[np.newaxis, :, np.newaxis]
---> 93 matrices = (
94 self.stencil
95 - t[
96 (self.n_stencil - 1) // 2 : -(self.n_stencil - 1) // 2,
97 np.newaxis,
98 ]
99 )[:, np.newaxis, :] ** pows
100 b = np.zeros(self.n_stencil)
101 b[self.d] = np.math.factorial(self.d)
ValueError: operands could not be broadcast together with shapes (798,1,798,3) (1,3,1)
Beta Was this translation helpful? Give feedback.
All reactions