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

output layers length forgotten after json #1

Open
Aedius opened this issue Jan 7, 2014 · 1 comment
Open

output layers length forgotten after json #1

Aedius opened this issue Jan 7, 2014 · 1 comment

Comments

@Aedius
Copy link

Aedius commented Jan 7, 2014

Hello,

when save and charged an nn object with more than one hidden layers, the length of the output layer is forgotten.

i write some mocha test that prove it :

it('trains 2 in 2 out with 1 hidden', function (done) {
    var net = nn()

    //this example should work

    net.train([
        { input: [ 0 , 0.1 ],    output: [ -0.1 , 0.1 ] },
        { input: [ 0.1, 0.1 ],     output: [ 0, 0.2 ] },
        { input: [ 0.2, 0.2 ],     output: [ 0 , 0.4 ] },
        { input: [ 0.3, -0.2 ],     output: [ 0.5 ,  0.1 ] },
        { input: [ 0.4, 0.3 ],     output: [ 0.1 , 0.7 ] },
        { input: [ 0.5, -0.3 ],     output: [ 0.8, 0.2 ] },
        { input: [ 0.6, 0.4 ],     output: [ 0.2, 1 ] },
    ])

    var output = net.send([ 0.5,0.5 ]) // => [ 0, 1 ]

    console.log('trained - , + output for [0.5, 0.5] : [%s]. desiredOutput: [0, 1]', output)

    var json = net.toJson();
    var net = nn()
    net.fromJson(json);
    var output = net.send([ 0.5,0.5 ]) // => [ 0, 1 ]
    console.log('trained - , + output for [0.5, 0.5] : [%s]. desiredOutput: [0, 1]', output)
    assert(output.length = 2)
    done()
})
it('trains 2 in 2 out with 2 hidden', function (done) {

    var net = nn({
        layers: [ 5, 4 ],
        iterations: 2
    })
    //this example should work

    net.train([
        { input: [ 0  ,  0.1 ],     output: [ -0.1 , 0.1 ] },
        { input: [ 0.1,  0.1 ],     output: [  0   , 0.2 ] },
        { input: [ 0.2,  0.2 ],     output: [  0   , 0.4 ] },
        { input: [ 0.3, -0.2 ],     output: [  0.5 , 0.1 ] },
        { input: [ 0.4,  0.3 ],     output: [  0.1 , 0.7 ] },
        { input: [ 0.5, -0.3 ],     output: [  0.8 , 0.2 ] },
        { input: [ 0.6,  0.4 ],     output: [  0.2 , 1 ] },
    ])

    var output = net.send([ 0.5,0.5 ]) // => [ 0, 1 ]

    console.log('trained - , + output for [0.5, 0.5] : [%s]. desiredOutput: [0, 1]', output)

    var json = net.toJson();
    var net = nn()
    net.fromJson(json);
    var output = net.send([ 0.5,0.5 ]) // => [ 0, 1 ]
    console.log('trained - , + output for [0.5, 0.5] : [%s]. desiredOutput: [0, 1]', output)
    assert(output.length == 2)
    done()
})

good work by the way :)

@Hugo-ter-Doest
Copy link

The number of layers is not correctly set after reading the Json file. It is always 3 and therefore returns the result of the third layer. Will correct this in a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants