dynamicslab / pysindy

A package for the sparse identification of nonlinear dynamical systems from data
https://pysindy.readthedocs.io/en/latest/
Other
1.36k stars 304 forks source link

There is a significant divergence between the model based on experimental data and the analytical solution #525

Open Marcel0436 opened 1 week ago

Marcel0436 commented 1 week ago

Hi.

I am modeling an RLC circuit for alternating current (AC) using a data-driven approach. I use the variables current (i), charge (q), and frequency (f). The model is diverging from the analytical solution. Could someone please help me?"

My code:

poly_order = 0
poly_library = ps.PolynomialLibrary(degree=poly_order,  interaction_only=True)
fourier_library = ps.FourierLibrary(include_cos=False)
combined_library = poly_library + fourier_library

feature_names = ['i', 'q', 'f']

ensemble_optimizer = ps.EnsembleOptimizer(
    ps.STLSQ(normalize_columns=True),
    bagging=True,
    n_subset=int(0.6* x_train.shape[0])
)

model = ps.SINDy(feature_names=feature_names,differentiation_method=ps.FiniteDifference(drop_endpoints=True),optimizer=ensemble_optimizer,feature_library = combined_library)
model.fit(x_train, t0, ensemble = True,
    n_models = 20,replace=True, quiet=True)
model.print()

My results:

(i)' = -41.144 1 + 436.417 sin(1 i) + -18908612133.648 sin(1 q) + -14.919 sin(1 f) (q)' = 0.997 sin(1 i) (f)' = 21.980 1

The term (f)' is correct. For (q)', it is somewhat accurate, It is necessary to remove sin(i) because, for my solution (q)' = i. However, (i)' is problematic. The term -18908612133.648 sin(1 q) is very large because according to the analytical solution, this is term should be i*sin(1 q).

I have tried several approaches to solve this issue, but so far I haven't found an effective solution. output

Jacob-Stevens-Haas commented 2 days ago
  1. (q)'=sin (1 i) is very close to (q)' = i if i is close to zero, which it appears to be in your plot.
  2. i*sin(1 q) would come out of a TensoredLibrary. Your addition combined_library = poly_library + fourier_library provides a ConcatLibrary. See these lines of source code.
  3. Nevertheless 18908612133.648 sin(1 q) is nowhere close to i sin(1 q) on the scale of the plot, where i is $\mathcal O(1e-2)$