Skip to main content

Multigrid Neural Network implemented in PyTorch

Project description

MGNet

MultiGrid Methods + Neural Networks = MgNet

tl;dr

MultiGrid methods cool. Repository implements paper with pytorch.

Background

I first came up with the idea of using multigrid methods in deep learning after attending the seminar algebraic multigrid, in which we studied the publication by Jinchao Xu and Ludmil Zikatanov.

If multigrid methods are one of the fastest solvers for partial differential equality problems by use of grids, then knowing that images are functions on grids, multigrid methods can be used in machine learning, especially in FNNs and CNNs ...

i thought. Unfortunately, Sir Xu beat me up to the idea and published a paper 2 years before.

As I couldn't find a ready-to-use implementation of the paper, the work in this repository came to be.

Theory of operation

This type of network generalizes multiple preexisting models like the famous ResNet and DenseNet into a single configurable system.

The premise is built upon the idea of multigrid: the solution u is smoothened and its errors are projected on layers of various sizes.

A single step consists of three phases:

  1. Relaxation: Given a smooth S, the solution of the problem u is computed using S(u) = f several time, to obtain an improved solution v. The residuum of the equation is computed r = f - S(v)
  2. Restriction: the residuum r is transferred on a layer of lower size and the approximation of the error A_{r}e_{r} = r is computed
  3. Prolongation or interpolation: the error e is projected back on the original layer A_{p}e_{r} = r_{p} and the original solution updated: v = v + e_{r}
---
title: Basic multigrid
---
flowchart TD;
    s[Start: v<sup>h</sup> = 0] --> v1    
    subgraph "Relaxation"
        v1["Solve: S<sup>h</sup> * u<sup>h</sup> = f<sup>h</sup>"]--> v["Compute residuum: r = f - S * v"]
    end
    subgraph Restriction 
        v["Compute residuum: r<sup>h</sup> = f<sup>h</sup> - S<sup>h</sup>v<sup>h</sup>"] --> r1
        r1["Project residuum on coarse layer: G<sup>2h</sup>: r<sup>2h</sup>"] --> r2
    end
    subgraph Prolongation
        r2["Compute error: S<sup>2h</sup> * e<sup>2h</sup>= r<sup>2h</sup>"] --> r3
    end
    r3["Project error on finer layer: G<sup>h</sup>: e<sup>h</sup>"] --> p1["Updated solution: v<sup>h</sub> = v<sup>h</sub> + e<sup>h</sub>"]

Building and Running

Local:
Install dependencies:

uv sync

Run inference test (default values already set. Use --help option for help):

PYTHONPATH="${PYTHONPATH}:${PWD}" uv run tests/test_inference.py

Docker:
Build image:

docker build . -t mgnet

Run image in container:

docker run mgnet --help

Literatur

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mgnet-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file mgnet-0.1.1.tar.gz.

File metadata

  • Download URL: mgnet-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mgnet-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f7f713480377a3b21408a7906e5cfa12a84c2afe9eacf6378d4e32d104ec2dfc
MD5 5f8d1166efa738e88f4d14d662ad044d
BLAKE2b-256 167b8fc3b2686fcac1f181c5576f155d0bdecf9fde524c64443268036833a76a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page