Skip to content

PNUVV/NeuralODE-introduction

 
 

Repository files navigation

README

Introduction

Theory and general introduction

Tutorial

  • Refer to NeuralODE_tutorial.ipynb

Installation

Jupyter notebook

  • Install jupyter notebook: pip install jupyter
  • Run jupyter notebook: jupyter notebook

Pytorch and torchdyn with a GPU

1. Create new env: conda create --name py38torch python=3.8
2. Active env: conda activate py38torch
4. Install torchdyn: pip install torchdyn==1.0.3
5. Install torch: conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
==> Install 4, 5 in the end to avoid packages overwritten

Note

  • Recommend to use conda to install packages for convenience

  • If you dont have GPU, please refer to Torch website for more details

Recommendations for further reading

NeuralODEs and its applications

Other Time series forecasting models

Marine vehicles hydrodynamics and related machine learning applications

Tips for reading articles on Medium or towardsdatascience without subscription

  • Clear the cookies of your tab browser when you reach the limit of reading articles

When using venv in WSL2 or Linux

  • [issue] Expected numpy array as input but given PyTorchTensors causing error

plot_2D_space_depth이 텐서를 받아들이지만 int 함수를 적용하려고 하여 발생하는것 같습니다. 따라서 아래 수식으로 lib의 torchdyn/utils.py 코드를 변경하였습니다.

Usage

Here is how to use the plot_2D_space_depth function to plot 2D trajectories in a 3D space:

import numpy as np
import torch
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

def plot_2D_space_depth(s_span, trajectory, yn, n_lines):
    "Plots 2D trajectories in a 3D space (2 dimensions of the system + time)."
    # Convert the Tensors to numpy arrays if necessary
    s_span = s_span.detach().cpu().numpy() if torch.is_tensor(s_span) else s_span
    trajectory = trajectory.detach().cpu().numpy() if torch.is_tensor(trajectory) else trajectory
    yn = yn.detach().cpu().numpy() if torch.is_tensor(yn) else yn

    colors = ['orange', 'blue']
    fig = plt.figure(figsize=(6,3))
    ax = Axes3D(fig, auto_add_to_figure=False)
    fig.add_axes(ax)
    for i in range(n_lines):
        ax.plot(s_span, trajectory[:,i,0], trajectory[:,i,1], color=colors[yn[i].astype(int)], alpha = .1)
        ax.view_init(30, -110)

    ax.set_xlabel(r"$s$ [Depth]")
    ax.set_ylabel(r"$h_0$")
    ax.set_zlabel(r"$h_1$")
    ax.set_title("Flows in the space-depth")
    ax.xaxis._axinfo["grid"]['color'] =  (1,1,1,0)
    ax.yaxis._axinfo["grid"]['color'] =  (1,1,1,0)
    ax.zaxis._axinfo["grid"]['color'] =  (1,1,1,0)

# Create some example data
s_span = torch.linspace(0, 10, 100)
trajectory = torch.rand((100, 5, 2))  # 100 time steps, 5 lines, 2 dimensions
yn = torch.randint(0, 2, (5,))  # 5 lines

# Call the function
plot_2D_space_depth(s_span, trajectory, yn, len(trajectory[0]))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 67.8%
  • HTML 31.5%
  • CSS 0.7%