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

Prediction using DMD using windowed data #484

Open
drhaserr opened this issue Jan 10, 2024 · 2 comments
Open

Prediction using DMD using windowed data #484

drhaserr opened this issue Jan 10, 2024 · 2 comments

Comments

@drhaserr
Copy link

The objective

I will submit a paper this month where I employ PYDMD. However, I am encountering challenges in locating documentation on predicting time series using windowed data. I need help to determine the optimal approach for fitting the model using windowed data, specifying a window size (e.g., window-size = 10), and subsequently making predictions for a specified number of data points (e.g., predicting the next 3 values).

Thank you :-)

@greinerth
Copy link
Contributor

greinerth commented Jan 22, 2024

Do you want to make sure that all samples are used during the regression? Then you could directly set the svd_rank. E.g.

import numpy as np
from pydmd import DMD

# I assume you have some measurements "obs" of shape nxm which are measured with sampling time dt.
# When considering all measurements of "obs", m-1 samples can be used at maximum for your computation.
dmd = DMD(svd_rank=obs.shape[-1] - 1)
dmd.fit(obs)

For extrapolation of the timeseries you can easily use the modes, the eigenvalues and the amplitudes of the DMD class.

omegas = np.log(dmd.eigs) / dt

# define some arbitrary timestamps here
time = np.arange(10) * dt
prediction = dmd.modes  @ (np.exp(np.outer(omegas, time)) * dmd.amplitudes[:, None])

@Doublonmousse
Copy link
Contributor

Well, on older versions of pydmd you had to extract modes, eigenvalues and amplitude and reconstruct everything manually.

Now this is no longer necessary using the dmd_time dictionnary. See in the tutorial 6 on hodmd

hodmd.dmd_time["tend"] = 50

And the documentation on the .dmd_time and .original_time dictionnaries

    :cvar dict original_time: dictionary that contains information about the
        time window where the system is sampled:

           - `t0` is the time of the first input snapshot;
           - `tend` is the time of the last input snapshot;
           - `dt` is the delta time between the snapshots.

    :cvar dict dmd_time: dictionary that contains information about the time
        window where the system is reconstructed:

            - `t0` is the time of the first approximated solution;
            - `tend` is the time of the last approximated solution;
            - `dt` is the delta time between the approximated solutions.

In your case just add n to .dmd_time["tend"] and calling dmd_obj.reconstructed_data will return you the reconstructed data on the windowed data + the n next timesteps. Changing .dmd_time["t0"] and you may be able to return just the prediction.

You have to double check that the dt are correct on both dictionnaries. By default dt is 1 and correspond to a single time step of your original data

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