Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in model.fit with timedelays #35

Open
moonlians opened this issue Jul 29, 2023 · 2 comments
Open

Bug in model.fit with timedelays #35

moonlians opened this issue Jul 29, 2023 · 2 comments

Comments

@moonlians
Copy link

from pykoopman.regression import EDMD
from sklearn.metrics import mean_absolute_percentage_error
from sklearn.metrics import mean_absolute_error
pred = 4
S = np.array(data)
n_output_vars = S.shape[1]  # Get the number of output variables
n_delays = 100
n = 310
regressor = EDMD()

# Loop through each timestep
for timestep in range(n, len(S) - pred):
    try:
        obs = TimeDelay(n_delays=n_delays)

        # Prepare input data for the current timestep
        X1 = S[:timestep-1].T
        X2 = S[1:timestep].T

        model = pk.Koopman(observables=obs, regressor=regressor)
        model.fit(X1.T, y=X2.T) 

        n_steps = timestep - n_delays + pred
        x0_td = X1[:,:n_delays+1].T

        Xkoop = model.simulate(x0_td, n_steps=n_steps)
        Xkoop2 = np.vstack([x0_td, Xkoop]) # add initial condition to simulated data for comparison below

    except ValueError as ve:
        print("Timestep:", timestep, "X1 shape:", X1.shape)
        print(ve)
        continue
        ```
        
```Timestep: 401 X1 shape: (488, 400)
x has too few rows. To compute time-delay features with delay = 1 and n_delays = 100 x must have at least 101 rows.```

It happens at timestep 301 too.
All other timesteps complete fine. 

99 time delays seems fine. Delays >100 error.

@pswpswpsw
Copy link
Collaborator

could you please provide the data as well so maybe I can replicate this issue?

@liano159
Copy link

f.csv

Thanks. You can use this but any array >200 should work.
Delays >100 produce errors.
If it's possible to fix it would be very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants