Giter Club home page Giter Club logo

pywsindy-for-pdes's Introduction

WSINDy for PDEs (Python)

A Python 3 implementation of the Weak-form Sparse Identification of Nonlinear Dynamics (WSINDy) algorithm for partial differential equations (PDEs).
Based on the JCP paper by D. A. Messenger, D. M. Bortz 2021.
See authors' original MatLab code repository (copyright 2020, all rights reserved by original authors).
For other existing implementations, see also PySINDy documentation.
Stable as of August, 2024.

Python 3.10 Open In Colab

wsindy_github_pic

Notebooks

  • WSINDy.ipynb
    Open in Colab
    A template for running WSINDy on your own data. See the 'Usage' section below for details.
    Stable as of August, 2024.

  • WSINDy_Tutorial.ipynb
    Open in Colab
    This notebook serves as a walkthrough and introduction to the WSINDy algorithm. As an example, it shows how the Kuramoto-Sivashinksy equation can be recovered from data (see the picture above).
    Stable as of July, 2024.

  • WSINDy_SH23.ipynb
    Open in Colab
    The WSINDy algorithm applied to the Swift-Hohenberg (23) equation. Simulation data were obtained using MatLab's chebfun package; see sh23_simulation.m and chebfun.org (navigate to examples > Swift Hohenberg).
    Stable as of July, 2024.

  • JHTDB_WSINDy.ipynb
    Open in Colab
    Uses a numerical simulation of the ideal MHD equations, sourced from the Johns Hopkins Tubulence Database, as a dataset for WSINDy.
    Stable as of August, 2024.

To access a dataset stored in Google Drive (e.g., /content/drive/My Drive/WSINDy/dataset_name.txt) while using Google Colab, use the following commands to change directories:
# Create directory if necessary
!mkdir -p "/content/drive/My Drive/WSINDy"

from google.colab import drive
drive.mount('/content/drive')

%cd /content/drive/My Drive/WSINDy

Python Files

  • wsindy.py
    Python 3.10
    Returns sparse weights for candidate basis functions. See the 'Usage' section below for details.
    Stable as of July, 2024.

Libraries

This algorithm uses the following dependencies:
import torch
import numpy as np
import matplotlib.pyplot as plt
import scipy
import symengine as sp
import itertools
import re
Optional dependencies based upon GPU/parallelism features are as follows:
import torch.nn.functional as nnF # GPU
from concurrent.futures import ProcessPoolExecutor, as_completed # Parallelism

Usage

For a dataset U (tensor), function library fj (dictionary), and derivative library alpha (tuple), the syntax is as follows:
w = wsindy(U, fj, alpha, **params)
Example algorithm hyperparameter specification:
# Grid parameters (should match dimension of dataset)
(Lx, Ly, T) = (30*np.pi, 30*np.pi, 20)
(dx, dy, dt) = (Lx/U.shape[0], Ly/U.shape[1], T/U.shape[-1])

# Function library
fields = 1 # Number of scalar fields
powers = 4 # Maximum monomial power
poly = get_poly(powers, fields)
trig = () # (Frequency, phase) pairs
fj = {'poly': poly, 'trig': trig}

# Derivative library
lhs = ((0,0,1),) # Evolution operator D^0
dimension = 2 # Spatial dimensions
pure_derivs = 4 # Include up to fourth order
cross_derivs = 2 # Include up to second order
rhs = get_alpha(dimension, pure_derivs, cross_derivs)
alpha = lhs + rhs

params = {
    # x = spatial domain(s)
    # dx = spatial discretization(s)
    # t = temporal domain
    # dt = temporal discretization
    # aux_fields = extra library variables
    # aux_scales = scaling factors for aux fields
    #--------------------------------------------
    'x' : [(0, Lx), (0, Ly)],
    'dx' : [dx, dy],
    't' : (0, T),
    'dt' : dt,

    # m = explicit (mx,...,mt) values
    # s = explicit (sx,...,st) values
    # lambdas = MSTLS threshold search space
    # threshold = known optimal threshold
    # p = explicit (px,...,pt) values
    # tau = test function tolerance
    # tau_hat = Fourier test function tolerance
    # scales = explicit (yu,yx,yt) scaling factors
    # M = explicit scaling matrix
    #---------------------------------------------

    # verbosity = report info and create plots? (0 or 1)
    # init_guess = [x0, y0, m1, m2], for (kx,kt) curve fit
    # max_its = specify maximum number of MSTLS iterations
    # sigma_NR = noise ratio of artifical gaussian noise
    # sparsify = use 'original' or 'scaled' data in MSTLS
    #-----------------------------------------------------
    'verbosity' : 1,
    'sigma_NR' : 0.0,
    'sparsify' : 'original'}

pywsindy-for-pdes's People

Contributors

sethminor avatar

Stargazers

 avatar

Watchers

 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.