Giter Club home page Giter Club logo

logisticmapdnn's Introduction

LogisticMapDNN

I wanted to explore how to make DNNs (even) more non-linear and somehow visualize their non-linearness. Since DNN non-linearness comes from specific, non-linear activation function, I though trying out different activation functions might be a good start. To get a sense of how nonlinear resulting DNN is, I'll visualize its outputs in a specific way:

The network is going to take in 2 scalars (X and Y coordinates) and output a single scalar value. We're going to visualize the output values across the input space (in range [-5, 5]), so each pixel in the image represents DNN output for one point in input (x-y) space. The less smooth output values are across input-value space, less linear network should be (roughly, this is not rigorous math).

For example, if our "network" would be just picking the x-value and propagating it as output, the output image would be:

X coordinates

Model

class Model(torch.nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.affine1 = torch.nn.Linear(2, 64)
        self.affine2 = torch.nn.Linear(64, 64)
        self.affine3 = torch.nn.Linear(64, 64)
        self.affine4 = torch.nn.Linear(64, 1)

    def forward(self, x):
        x = activation_fn(self.affine1(x))
        x = activation_fn(self.affine2(x))
        x = activation_fn(self.affine3(x))
        x = activation_fn(self.affine4(x))
        return x

Very simple 4 layer MLP, activation function is something we'll play with.

ReLU

ReLU

Not very non-linear

Parameters to use if you want to replicate:

Logistic Map Iterations: 0
Cosine: False

LogisticMap

LogisticMap LogisticMap

Parameters to use if you want to replicate:

Logistic Map Iterations: 2
Logistic Map R: 3.7584300000000015
Cosine: False

Much better in terms of non-linearity. Also looks cool.

Cosine

Since LogisticMap activation seems to be more visualy "dense" in near zero, I wanted to try something that is more regular across input space. Instead of clamping input values to logistic map into (0, 1) range I instead passed them through cosine. It turns out that once you do that, logistic map doesn't make that much difference in how the output looks. I kept just cosine as activation function, which results in these nice pictures:

Cosine Cosine

Parameters to use if you want to replicate:

Logistic Map Iterations: 0
Cosine: True
Frequency: 7.9

Interestingly, these look quite similar to http://iquilezles.org/www/articles/warp/warp.htm and it seems they are also similar mathematically. Inigo's images are generated roughly by:

y = fbm(x + fbm(x + fbm(x)))

whereas DNN with cosine activation is

y = cos(W1 * cos(W2 * cos(W3 * cos(x))))

fbm is just a sum of multiple cosines, and instead of + x, we're performing more random linear transformation.

Something Artsy

By changing output to 3 scalars, we can create the output images in RGB. This produces nice, artsy, trippy images.

Art1 Art2 Art3

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.