Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinity/NaN output #34

Open
dan-ryan opened this issue Apr 27, 2019 · 10 comments
Open

Infinity/NaN output #34

dan-ryan opened this issue Apr 27, 2019 · 10 comments
Labels
🕷️ bug Something isn't working

Comments

@dan-ryan
Copy link

dan-ryan commented Apr 27, 2019

An old Neataptic bug which is still bugging me.

I'm getting Infinity/NaN outputs while training. Using the latest Node.js.

My settings:

    Methods.mutation.MOD_ACTIVATION.mutateOutput = false;
    Methods.mutation.MOD_ACTIVATION.allowed = [
        Methods.activation.LOGISTIC,
        Methods.activation.TANH,
        Methods.activation.STEP,
        Methods.activation.SOFTSIGN,
        Methods.activation.SINUSOID,
        Methods.activation.GAUSSIAN,
        Methods.activation.BIPOLAR,
        Methods.activation.BIPOLAR_SIGMOID,
        Methods.activation.HARD_TANH,
        Methods.activation.INVERSE,
        Methods.activation.SELU,
        Methods.activation.RELU,
        Methods.activation.BENT_IDENTITY,
        Methods.activation.IDENTITY,
    ];

    neat = new Neat(4, 1, null,
        {
            mutation: Methods.mutation.ALL,
            popsize: 100,
            mutationRate: 0.2,
            elitism: 10,
            equal: true,
            network: new Architect.Random(4, 5, 1),
            provenance: 2,
            maxNodes: 7, 
            maxConns: 10,
            maxGates: 5,
        }
    );

Infinity Example:

The normalised data:
[0.9354838709677419, 0.5, 0.5933786078098472, 0.5880669161907702]

The genome:

{"nodes":[{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":0},{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":1},{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":2},{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":3},{"bias":1.1508084667830487,"type":"output","squash":"SELU","mask":1,"index":4}],"connections":[{"weight":1,"from":4,"to":4,"gater":4},{"weight":-0.05001360658035439,"from":3,"to":4,"gater":null},{"weight":0.9984137443904727,"from":2,"to":4,"gater":null},{"weight":-0.7832753538521565,"from":1,"to":4,"gater":null},{"weight":-0.9040067054346645,"from":0,"to":4,"gater":4}],"input":4,"output":1,"dropout":0}

NaN Example:

The normalised data:
[0.3870967741935484, 0.75, 0.5040295048190726, 0.5575469079452833]

The genome:

{"nodes":[{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":0},{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":1},{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":2},{"bias":0,"type":"input","squash":"LOGISTIC","mask":1,"index":3},{"bias":-0.0717463180924848,"type":"hidden","squash":"BENT_IDENTITY","mask":1,"index":4},{"bias":-0.02994106373052867,"type":"output","squash":"LOGISTIC","mask":1,"index":5}],"connections":[{"weight":1,"from":4,"to":4,"gater":null},{"weight":1,"from":5,"to":5,"gater":null},{"weight":-0.048341462482942354,"from":4,"to":5,"gater":null},{"weight":-0.4890970041600281,"from":3,"to":5,"gater":5},{"weight":0.9984137443904727,"from":2,"to":5,"gater":5},{"weight":-0.4890970041600281,"from":3,"to":4,"gater":4},{"weight":0.024574079733371557,"from":1,"to":5,"gater":null},{"weight":0.9984137443904727,"from":2,"to":4,"gater":4},{"weight":-0.9040067054346645,"from":0,"to":5,"gater":5},{"weight":0.049181674792330154,"from":1,"to":4,"gater":null},{"weight":0.04742932010695605,"from":0,"to":4,"gater":null}],"input":4,"output":1,"dropout":0}

wagenaartje/neataptic#130

@luiscarbonell
Copy link
Member

@dan-ryan It looks like we're carrying a few of these over.

@christianechevarria and I are a little caught up in some regular life things till Wednesday, but I'll try to squeeze out as much time as can for this one. I'm also not a fan of the NaN/Infinity bugs.

@dan-ryan
Copy link
Author

There was an attempt in the past to fix NaNs.
wagenaartje/neataptic@2fd4dbd

@luiscarbonell
Copy link
Member

luiscarbonell commented May 4, 2019

@dan-ryan I'm having a hard time replicating the Infinity/NaN bug.

The genomes that you placed, where they for the Neat.getAverage() or Neat.getFittest()?

@dan-ryan
Copy link
Author

dan-ryan commented May 4, 2019

@luiscarbonell
What I could do is share my project class that way you can debug this. What's your email?

@luiscarbonell
Copy link
Member

@luiscarbonell
What I could do is share my project class that way you can debug this. What's your email?

[email protected]

@dan-ryan
Copy link
Author

dan-ryan commented May 5, 2019

@luiscarbonell I've sent you an email. A simple enough example to get running and able to get NaNs and Infinities quickly.

@christianechevarria
Copy link
Member

Update:
Screenshot 2019-05-12 at 2 45 35 PM

@luiscarbonell
Copy link
Member

This issue is really a mutation and node.squash issue.

We need to be able to mutate activation functions on output neurons - without creating new ones.

This is sticky-water because of ranges (-1, 1) or (0,1) or (-Infinity, Infinity)

image

image

@christianechevarria
Copy link
Member

christianechevarria commented Aug 29, 2019

@dan-ryan While playing around with a logic gate demo for the repo link ran into a silent bug that could have a hand in this, turns out that architect.LSTM is spitting out NaNs, Random is failing too.

This could be related to #35 as a common root cause

Seems like a suite of tests for architect and a potential re-write is in order

@christianechevarria
Copy link
Member

christianechevarria commented Sep 4, 2019

Added a clamp to activation functions in 71301ba that keeps Infinity to Number.MAX_VALUE and -Infinity to -Number.MAX_VALUE so that they won't propagate through the network.

Although this should solve the Infinity / NaNs issue, it will create some loss of learning ability in cases where activations really should exceed the built-in numerical limits of JS.

The ideal solution would likely involve finding / implementing a big number library that would allow us to operate on numbers of arbitrary length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕷️ bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants