$ cd ../
Neural ODEs -- continuous flow vs ResNet from scratch — bash

user@devops:~$ cat README.md

Neural ODEs -- continuous flow vs ResNet from scratch

# Description

Neural Ordinary Differential Equations (Chen et al. 2018) implemented from scratch in PyTorch, no torchdiffeq. A residual block h_{t+1} = h_t + f(h_t, θ) is one Euler step of the ODE dh/dt = f(h(t), t, θ). Part 1: two interleaved spirals, 1,600 points (train 1,200 / test 400), seed 42. Part 2: discrete ResNet = 8-step Euler, time-aware MLP 2-32-32-2 with last layer zeroed (identity init), 1,256 params, test acc 0.7825. Part 3: the same f integrated with Euler-8 (acc 0.6325, early-stop) and RK4 (4 steps NFE 16 acc 0.6600; 8 steps NFE 32 acc 1.0000, CE 0.070). Part 4: trajectories -- the ResNet takes discrete jumps, RK4 a continuous flow that unrolls the spirals until a linear head separates them. Part 5: irregular series, 28 noisy observations of dz/dt = A z (A = [[-0.18, 2.15], [-2.15, -0.18]]); an autonomous NODE interpolates the orbit (obs MSE 0.0109, dense MSE 0.0256). Part 6: discrete adjoint of Euler-1 vs backprop-through-solver: cosine dL/dh0 = 1 and dL/dθ = 1, relative error 0. Finding: a fixed-step ResNet IS the Euler discretisation of a Neural ODE; 8 NFE cannot unroll the spirals, RK4 with 32 NFE can; the adjoint matches BPTS and keeps memory O(1) in T. CPU ~12 s. 7 figures.

# Key features

$ f from scratch: MLP 2-32-32-2 tanh, concat t, last layer zeroed (identity init)

$ ResNet = Euler-8 of the same ODE: 1,256 params, test acc 0.7825

$ RK4-8 (NFE 32) splits the spirals at 100% (CE 0.070); Euler-8 stays at 0.63-0.78

$ Trajectories: ResNet discrete jumps vs continuous flow that unrolls the plane

$ Irregular series: 28 obs. of a spiral A z; dense interpolation MSE 0.026

$ Discrete adjoint vs BPTS: cosine 1.000000 on dh0 and dθ, relative error 0

$ Deterministic checkpoint (seed 42): re-run rebuilds metrics and figures without retraining

$ 7 figures: data, curves, trajectories, field, boundaries, NFE, series

# Gallery

Project terminal
Neural ODEs -- continuous flow vs ResNet from scratch - Project terminal
Training spirals
Neural ODEs -- continuous flow vs ResNet from scratch - Training spirals
CE and accuracy curves
Neural ODEs -- continuous flow vs ResNet from scratch - CE and accuracy curves
Discrete jumps vs flow
Neural ODEs -- continuous flow vs ResNet from scratch - Discrete jumps vs flow
Vector field f(h,t)
Neural ODEs -- continuous flow vs ResNet from scratch - Vector field f(h,t)
ResNet / Euler / RK4 boundaries
Neural ODEs -- continuous flow vs ResNet from scratch - ResNet / Euler / RK4 boundaries
NFE vs accuracy
Neural ODEs -- continuous flow vs ResNet from scratch - NFE vs accuracy
Spiral interpolation
Neural ODEs -- continuous flow vs ResNet from scratch - Spiral interpolation

# Technologies used

Python PyTorch NumPy Pandas scikit-learn Matplotlib