Closed SunandanAdhikary closed 5 months ago
Here is the detailed error for your reference : pysindy_error.txt
This seems like an issue with AxesArray
. FWIW, rather than uploading files, if they're long and distracting, you can put them in a spoiler dropdown. I hope you don't mind, I edited your comment to show you how. But it looks like the way you copied and saved the error lost line endings and messed up the encoding, so it's a little bit unreadable.
I tried running your code (adding
import numpy
x_train = np.arange(2* 251).reshape((251,2))
u_train = np.arange(2* 251).reshape((251,2))
) but I don't know what dp
is (in model.fit(x_train, u=u_train, t = float(dp.Ts), quiet=True)
), so I'm getting a NameError.
Excuse me. I have hurriedly uploaded it in the wrong format. PFA the error here. dp is an object that I created. You can use 0.04 as the sampling interval.
@Jacob-Stevens-Haas Is this an error from my end, or is there an issue with the library?
When you typed
lib_func = [lambda vx: 1/vx,
lambda vx: 1/vx^2]
Did you mean to do bitwise XOR (^
) or exponentiation (**
)? Bitwise XOR isn't supported for floats.
I'm going to assume exponentiation, but there's still another error. The SINDy object needs feature names for both the state variables and control variables. Thus,
model = ps.SINDy(feature_names=states, ...
should be:
model = ps.SINDy(feature_names=states + inputs, ...)
Correcting this and the exponentiation gives:
(beta)' = -0.335 1 + 0.209 beta + -0.536 r + 0.620 delta
(r)' = 0.105 1 + 0.539 beta + -0.280 delta
So not specifically a bug, but our documentation of the feature_names
argument really should call out that it needs to handle state and control.
Also, if the change suggested in #387 is approved, this may be clearer.
Thanks, it runs without any error after adding inputs in feature_names.
I am getting an error while trying to fit a linear parameter-varying model that looks like this:
The error :
_Note that the
x_train
andu_train
are numpy ndarrays of 251x2 dimension with float64 elements. Here is the whole code._ Can you please help in figuring out the problem here?Reproducing code example:
Error message:
` TypeError: ufunc 'bitwise_xor' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''`
``` --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[14], [line 37](vscode-notebook-cell:?execution_count=14&line=37) [31](vscode-notebook-cell:?execution_count=14&line=31) gen_lib = ps.GeneralizedLibrary([poly_lib, custom_lib], [32](vscode-notebook-cell:?execution_count=14&line=32) tensor_array=tensoring_libs, [33](vscode-notebook-cell:?execution_count=14&line=33) inputs_per_library=varuse_libwise) [35](vscode-notebook-cell:?execution_count=14&line=35) model = ps.SINDy(feature_names=states, optimizer=ensemble_opt, feature_library=gen_lib) ---> [37](vscode-notebook-cell:?execution_count=14&line=37) model.fit(x_train, u=u_train, t = float(dp.Ts), quiet=True) [39](vscode-notebook-cell:?execution_count=14&line=39) model.get_feature_names() [41](vscode-notebook-cell:?execution_count=14&line=41) model.print() File [c:\Users\sunan\miniconda3\lib\site-packages\pysindy\pysindy.py:414](file:///C:/Users/sunan/miniconda3/lib/site-packages/pysindy/pysindy.py:414), 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) [412](file:///C:/Users/sunan/miniconda3/lib/site-packages/pysindy/pysindy.py:412) warnings.filterwarnings(action, category=LinAlgWarning) [413](file:///C:/Users/sunan/miniconda3/lib/site-packages/pysindy/pysindy.py:413) warnings.filterwarnings(action, category=UserWarning) --> [414](file:///C:/Users/sunan/miniconda3/lib/site-packages/pysindy/pysindy.py:414) self.model.fit(x, x_dot) [416](file:///C:/Users/sunan/miniconda3/lib/site-packages/pysindy/pysindy.py:416) # New version of sklearn changes attribute name [417](file:///C:/Users/sunan/miniconda3/lib/site-packages/pysindy/pysindy.py:417) if float(__version__[:3]) >= 1.0: File [c:\Users\sunan\miniconda3\lib\site-packages\sklearn\pipeline.py:402](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:402), in Pipeline.fit(self, X, y, **fit_params) [376](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:376) """Fit the model. [377](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:377) [378](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:378) Fit all the transformers one after the other and transform the (...) [399](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:399) Pipeline with fitted steps. [400](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:400) """ [401](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:401) fit_params_steps = self._check_fit_params(**fit_params) --> [402](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:402) Xt = self._fit(X, y, **fit_params_steps) [403](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:403) with _print_elapsed_time("Pipeline", self._log_message(len(self.steps) - 1)): [404](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:404) if self._final_estimator != "passthrough": File [c:\Users\sunan\miniconda3\lib\site-packages\sklearn\pipeline.py:360](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:360), in Pipeline._fit(self, X, y, **fit_params_steps) [358](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:358) cloned_transformer = clone(transformer) [359](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:359) # Fit or load from cache the current transformer --> [360](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:360) X, fitted_transformer = fit_transform_one_cached( [361](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:361) cloned_transformer, [362](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:362) X, [363](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:363) y, [364](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:364) None, [365](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:365) message_clsname="Pipeline", [366](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:366) message=self._log_message(step_idx), [367](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:367) **fit_params_steps[name], [368](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:368) ) [369](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:369) # Replace the transformer of the step with the fitted [370](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:370) # transformer. This is necessary when loading the transformer [371](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:371) # from the cache. [372](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:372) self.steps[step_idx] = (name, fitted_transformer) File [c:\Users\sunan\miniconda3\lib\site-packages\joblib\memory.py:349](file:///C:/Users/sunan/miniconda3/lib/site-packages/joblib/memory.py:349), in NotMemorizedFunc.__call__(self, *args, **kwargs) [348](file:///C:/Users/sunan/miniconda3/lib/site-packages/joblib/memory.py:348) def __call__(self, *args, **kwargs): --> [349](file:///C:/Users/sunan/miniconda3/lib/site-packages/joblib/memory.py:349) return self.func(*args, **kwargs) File [c:\Users\sunan\miniconda3\lib\site-packages\sklearn\pipeline.py:894](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:894), in _fit_transform_one(transformer, X, y, weight, message_clsname, message, **fit_params) [892](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:892) with _print_elapsed_time(message_clsname, message): [893](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:893) if hasattr(transformer, "fit_transform"): --> [894](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:894) res = transformer.fit_transform(X, y, **fit_params) [895](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:895) else: [896](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/pipeline.py:896) res = transformer.fit(X, y, **fit_params).transform(X) File [c:\Users\sunan\miniconda3\lib\site-packages\sklearn\utils\_set_output.py:142](file:///C:/Users/sunan/miniconda3/lib/site-packages/sklearn/utils/_set_output.py:142), in _wrap_method_output.PySINDy/Python version information:
Using python 3.9.15 and pysindy version: 1.7.5 @IpsitaKoley @Aditya16828