GithubHelp home page GithubHelp logo

jviquerat / rbf Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 9 KB

An RBF network implementation for interpolation

License: MIT License

Python 82.53% Gnuplot 17.15% Shell 0.31%
radial-basis-function rbf-network interpolation rbf

rbf's Introduction

rbf

An implementation of a simple radial basis function network. Given the final purpose of this implementation, the center selection is made directly from the samples (no k-means clustering).

Example : approximation of a 1D modulated exponential

We approximate the function f(x) = -exp(|x|)*sin(4*pi*x) in [-1,1] with (i) a grid sampling of increasing resolution (from 2 to 20, left panel) and (ii) a latin hypercube sampling, with the same resolution (right panel). In both cases, normalized inverse multiquadric RBFs are used. The blue dots at the bottom indicate the positions of the centroids.

Description

The scope of this project is strictly limited to the interpolation of a limited amount of data. Hence, the centers of the RBF network are directly the provided data samples (no k-means clustering).

For testing purpose, the start.py file defines an analytical (1D or 2D) function that can be sampled in different ways (using a random sampling, a grid or a latin hypercube sampling) and then interpolated with the RBF. Please note that when using grid sampling in 2D, the actual number of samples used is the square of the provided number.

Several RBF are available, such as gaussian, inverse multiquadric or bump. It is also possible to use normalized versions of rbf (recommended).

After the interpolation is computed, the exact and approximate functions are sampled on a grid with resolution n_grid for visualization (this is also tunable in start.py).

Usage

Set everything in the start.py header, and then just launch python3 start.py. This will output two files:

  • A dataset_x.dat file that contains the rbf centers and weights
  • A grid_x.dat file that contains the sampling of the exact and approximate functions

You can obtain plots of the solution using gnuplot files : gnuplot plot.gnu will write a .png file of the exact and approximate solutions.

A batch file is also available to generate approximations with increasing level of sampling: bash batch_rbf.sh 2 1 10 will execute start.py using 2 to 10 rbf with a step of 1. You can generate a gif of the results obtained with gnuplot -c plot_gif_2d.gnu 2 1 10 (you must provide the parameters again to the gnuplot script). Different scripts are used for 1D and 2D, make sure to call the correct one.

Known issues

  • The real parameter beta, used in most rbf definitions, can have a major impact on the accuracy of the interpolation. In this implementation, it is computed as the inverse of the squared average distance from current center to all other centers.
  • The computation of the pseudo-inverse of the interpolation matrix uses np.pinv. The cutoff value rcond that is used to neglect the small singular values can also have an impact on the maximal accuracy level

Examples

Approximation of a 1D sinusoidal curve

We approximate the function f(x) = sin(6x) in [-pi,pi] with (i) a grid sampling of increasing resolution (from 6 to 30, left panel) and (ii) a latin hypercube sampling, with the same resolution (right panel). In both cases, normalized inverse multiquadric RBFs are used. The blue dots at the bottom indicate the positions of the centroids. Results are obtained using the batch script bash batch_rbf.sh 2 2 30. The gif is obtained using gnuplot -c plot_gif_1d.gnu 2 2 30.

Approximation of a 2D sinusoidal surface

We approximate the function f(x,y) = sin(5x)*cos(3y) in [-1,1]x[-1,1] with a grid sampling. The plot is obtained using gnuplot plot_2d.gnu.

Approximation of a modulated 2D parabola

We approximate the function f(x,y) = x^2 + sin(3x)*y^2 in [-1,1]x[-1,1] with a grid sampling. Results are obtained using the batch script bash batch_rbf.sh 2 1 9. The gif is obtained using gnuplot -c plot_gif_2d.gnu 2 1 9.

rbf's People

Contributors

jviquerat avatar

Watchers

 avatar

Forkers

mrtyss

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.