You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have difficulties to fit a PySindy model to my data. Here is an image showing my results
I want to model the evolution of some feature (the one in blue in the middle zone) from a control time series (the bottom one). There is usually some latence between the modifications of the control signal and the effect on the blue curve. Above curve is the gap between model (in red) and "true" curve (in blue, as said earlier). As you can see, the "transitions" are not weel modeled. For the moment, I am using this:
import pandas as pd
import pysindy as ps
# Function to create time-lagged features
def create_time_lagged_features(df, input_col, lag=5):
for i in range(1, lag + 1):
df[f'{input_col}_lag_{i}'] = df[input_col].shift(i)
return df
# Parameters
lag = 5
target = ['target_variable'] # Replace with your actual target column names
targets = ['target_variable1', 'target_variable2'] # Replace with your actual targets
data = pd.DataFrame() # Replace with your actual DataFrame
# Create time-lagged features
features = create_time_lagged_features(data, 'ctr_variable', lag)
features = features[[f'ctr_variable_lag_{i}' for i in range(1, lag + 1)] + target + ['TimeSpan[s]']].dropna()
# Prepare training data
X_train = features[[f'ctr_variable_lag_{i}' for i in range(1, lag + 1)]].values
y_train = features[targets].values
t_train = features['TimeSpan[s]'].values
# Define the SINDy model components
stlsq_optimizer = ps.STLSQ(threshold=0.05, alpha=0.01, max_iter=100)
pol_library = ps.PolynomialLibrary(degree=2, include_interaction=False, include_bias=True)
# Create and fit the SINDy model
model = ps.SINDy(
optimizer=stlsq_optimizer,
feature_library=pol_library,
discrete_time=False,
differentiation_method=ps.SmoothedFiniteDifference()
)
model.fit(y_train, u=X_train, t=t_train)
# Simulate the model
y_train0 = y_train[0]
x_sim = model.simulate(y_train0, u=X_train, t=t_train)
Do you have any suggestion to improve the model ?
Another hurdle is the fact that I have several "batches" of data, that is, several sequences of control-response similar to the one on the figure mais not perfectly identical -- the control variable might vary along a different pattern. As for now, I trained a different model for each of the batch but I got very different models -- though all more or less well adapted to its own batch, up to the concern explained above. Do you have any hint to give on how to robustify/aggregate the model(s) ?
Many thanks in advance for your help -- I have been stuck for a while on this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have difficulties to fit a PySindy model to my data. Here is an image showing my results
I want to model the evolution of some feature (the one in blue in the middle zone) from a control time series (the bottom one). There is usually some latence between the modifications of the control signal and the effect on the blue curve. Above curve is the gap between model (in red) and "true" curve (in blue, as said earlier). As you can see, the "transitions" are not weel modeled. For the moment, I am using this:
Do you have any suggestion to improve the model ?
Another hurdle is the fact that I have several "batches" of data, that is, several sequences of control-response similar to the one on the figure mais not perfectly identical -- the control variable might vary along a different pattern. As for now, I trained a different model for each of the batch but I got very different models -- though all more or less well adapted to its own batch, up to the concern explained above. Do you have any hint to give on how to robustify/aggregate the model(s) ?
Many thanks in advance for your help -- I have been stuck for a while on this
Beta Was this translation helpful? Give feedback.
All reactions