cazala / synaptic

architecture-free neural network library for node.js and the browser
http://caza.la/synaptic
Other
6.92k stars 665 forks source link

Using the trained network #127

Open mazing opened 8 years ago

mazing commented 8 years ago

I have tried using the example from Normalization 101 in the wiki, but I don't know what to do after I have trained the network.

Can I now input 10 new values (e.g. [1,1,1,0.77,0,1,1,1,0,0]) and get whether it was enjoyable or not (e.g. 1 or 0)?

How do I use the trained network?

I have tried writing the perceptron object to a file to see what has happened, but I don't understand the output. It seems it holds an array with all the neurons in the network and an array with all the connections between the neurons, each with some weights.

var Architect = synaptic.Architect;
var perceptron = new Architect.Perceptron(10, 7, 1);
var trainingSet = [
    {
        input: [0,0,1,0.12,0,0,0,0,1,1],
        output: [1]
    },
    {
        input:  [0,1,0,0.045,0,0,1,1,0,0],
        output: [0]
    },
    {
        input:  [1,0,0,0.42,1,1,0,0,0,0],
        output: [1]
    }
];
var trainingOptions = {
    rate: .1,
    iterations: 20000,
    error: .005,
};
perceptron.trainer.train(trainingSet, trainingOptions);
fs.writeFile('perceptron.json', JSON.stringify(perceptron, null, '\t'), (err) => {
    if (err) throw err;
    console.log('It\'s saved!');
});
bobalazek commented 8 years ago

Just trigger the activate function:

var input = [0, ...., 1];
var output = perceptron.activate(input);
console.log(output);