Git Product home page Git Product logo

pytorchrbflayer's Introduction

Pytorch RBF Layer - Radial Basis Function Layer

Pytorch RBF Layer implements a radial basis function layer in Pytorch.

Radial Basis networks can be used to approximate functions, and can be combined together with other PyTorch layers.

An RBF is defined by 5 elements:

  1. A radial kernel

  2. The number of kernels , and relative centers

  3. Positive shape parameters , which are scaling factors

  4. A norm

  5. A set of weights

The output of an RBF is given by , where is the input data.

The RBFLayer class takes as input: (1) the dimensionality of ; (2) the number of desired kernels; (3) the output dimensionality; (4) the radial function; (5) the norm to use.

The parameters can be either learnt, or set to a default parameter.

For more information check

An example of input/output mapping learnt by RBF Multiclass classification example

Author: Alessio Russo (PhD Student at KTH - [email protected])

License

Our code is released under the MIT license (refer to the LICENSE file for details).

Requirements

To run the library you need atleast Python 3.5 and PyTorch.

Usage/Examples

You can start using the layer by typing python from rbf_layer import RBFLayer in your code.

To learn how to use the RBFLayer, check the examples located in the examples/ folder:

In general the code has the following structure

import torch
from rbf_layer import RBFLayer

# Define an RBF layer where the dimensionality of the input feature is 20,
# the number of kernels is 5, and 2 output features


# \ell norm
def l_norm(x, p=2):
    return torch.norm(x, p=p, dim=-1)


# Gaussian RBF
def rbf_gaussian(x):
    return (-x.pow(2)).exp()


# Use a radial basis function with euclidean norm
rbf = RBFLayer(in_features_dim=20,            # input features dimensionality
               num_kernels=5,                 # number of kernels
               out_features_dim=2,            # output features dimensionality
               radial_function=rbf_gaussian,  # radial basis function used
               norm_function=l_norm)          # l_norm defines the \ell norm


# Uniformly sample 100 points with 20 features
x = torch.rand((100, 20))

# Compute the output of the RBF layer
# y has shape(100, 2)
y = rbf(x)

Citations

If you find this code useful in your research, please, consider citing it:

@misc{pythonvrft, author = {Alessio Russo}, title = {Pytorch RBF Layer}, year = 2021, doi = {}, url = { https://github.com/rssalessio/PytorchRBFLayer } }

License: MIT

pytorchrbflayer's People

Contributors

rssalessio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pytorchrbflayer's Issues

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.