Git Product home page Git Product logo

from_fourier_to_koopman's Introduction

From Fourier to Koopman: Spectral methods for Long-term Forecasting

Fourier and Koopman constitute spectral algorithms for learning linear and non-linear oscillators from data respectively. Both algorithms solve a global optimization problem in frequency domain and allow for modeling of systems of any dimensionality. The algorithms are written in numpy and pytorch.

The objective of the algorithms is, respectively:

Koopman and Fourier forecasting objectives

This code accompanies the following paper. A video abstract of the paper can be found here. Results on modeling a number of fluid flows can be found here.

-----------------How to use Fourier -----------------

Fourier fits a linear oscillator to data. The number of frequencies k that the signal is assumed to exhibit and a learning rate needs to be specified. It is recommended to whiten the signal (zero-mean and unit-variance).

To learn the oscillator from data, do:

from fourier_koopman import fourier
import numpy as np

x = (np.sin([2*np.pi/24*np.arange(5000)]) + np.sin([2*np.pi/33*np.arange(5000)])).T
x = x.astype(np.float32)

f = fourier(num_freqs=2)
f.fit(x[:3500], iterations = 1000)

To perform forecasting, do:

x_hat = f.predict(5000)

-----------------How to use Koopman -----------------

Because of the many different ways in which the Koopman algorithm can be utilized, running it is more involved and might require writing a custom model_object. Below we provide an example where f is a simple MLP and the squared loss is employed. In general, the class koopman is instantiated with a model object that specifies:

  • the topology of f
  • the loss
  • the number of frequencies num_freqs
from fourier_koopman import koopman, fully_connected_mse
import numpy as np

x = np.sin(2*np.pi/24*np.arange(5000))**17
x = np.expand_dims(x,-1).astype(np.float32)

k = koopman(fully_connected_mse(x_dim=1, num_freqs=1, n=512), device='cuda:0')
k.fit(x[:3500], iterations = 1000, interval = 100, verbose=True)

To perform forecasting, do:

x_hat = k.predict(5000)

Examples

In the following, a more involved example is given that uses a 1D tranpose-convolutional Neural Network to learn a traveling wave.

TO DO: ADD EXAMPLE

Koopman and Fourier forecasting objectives

License

Please see the LICENSE file.

from_fourier_to_koopman's People

Contributors

helange23 avatar alextmallen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.