Skip to content

Conversation

MkLahane
Copy link

@MkLahane MkLahane commented Feb 9, 2018

Created a multilayer neural network class which uses the matrix library in this repository for matrix operations. Some functionality is changed like you need to pass only 2 parameters(number of input nodes, number of output nodes) to the constructor of the neural network and for adding a hidden layer you need to call the function addHiddenLayer(number of neurons) for adding a hiddenLayer to your neural network and before training and after calling all addHiddenLayer function calls you need to call the config() function.

Created a multilayer neural network class  which uses the matrix library in this repository for matrix operations. Some functionality is changed like you need to pass only 2 parameters(number of input nodes, number of output nodes) to the constructor of the neural network and for adding a hidden layer you need to call the function addHiddenLayer(number of neurons) for adding a hiddenLayer to your neural network and before training and after calling all addHiddenLayer function calls you need to call the config() function.
@xxMrPHDxx
Copy link

You may be interested on this

@MkLahane
Copy link
Author

MkLahane commented Feb 9, 2018

Wow, it is really great. Your code is quite optimised and is much more short and precise than mine.

@xxMrPHDxx
Copy link

Thank you. But I'm not really sure that it will produce the expected result. Yours seems much better and promising though.

@AR-234
Copy link

AR-234 commented Feb 11, 2018

Haven't looked in here before i've wrote my Version, i've merged it into the nn.js file, so it's not breaking the examples, but i like your approach. And i've broke the serialize and have no clue how to fix it..
Maybe somebody of you know a way to fix it? link

@xxMrPHDxx yours looks really awesome!

@xxMrPHDxx
Copy link

xxMrPHDxx commented Feb 11, 2018

You can try to use this serialize function instead

serialize() {
   let cache = [];
   return JSON.stringify(this,(key, value) => {
      if (typeof value === 'object' && value !== null) {
         if (cache.indexOf(value) !== -1) {
            // Circular reference found, discard key
            return;
         }
         // Store value in our collection
         cache.push(value);
      }
      return value;
   });
   cache = null;
}

and for the deserialize function use

    static deserialize(data) {
        if(typeof data == 'string')
        {
            data = JSON.parse(data);
        }
        let nn = new NeuralNetwork(data.input_nodes, data.hidden_nodes, data.output_nodes);
        nn.layer.map(obj => {
            let nnlayer = new NeuralNetworkLayer(nn,obj.weights.cols,obj.weights.rows);
            nnlayer.weights = obj.weights;
            nnlayer.bias = obj.bias;
        });
        return nn;
    }

@shiffman
Copy link
Member

Thank you so much for this contribution and discussion! At the moment I prefer #61 and keeping just a single NeuralNetwork class as well as adding a Layer class.

@shiffman shiffman closed this Feb 11, 2018
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

Successfully merging this pull request may close these issues.

4 participants