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

Refactor networks #7

Merged
merged 20 commits into from
Dec 16, 2016
Merged

Refactor networks #7

merged 20 commits into from
Dec 16, 2016

Conversation

0x33467
Copy link
Member

@0x33467 0x33467 commented Dec 9, 2016

A better implementation of the neural nets that allows to add new activation functions easily

@targos
Copy link
Member

targos commented Dec 9, 2016

Is it a fix for #6 ?
/cc @zafarali

@0x33467
Copy link
Member Author

0x33467 commented Dec 9, 2016

yes, I didn't implement the functions that receives the alpha parameter but it should be easy to do.

@targos
Copy link
Member

targos commented Dec 9, 2016

don't worry about the travis failures. nodejs.org has issues at the moment: nodejs/build#562

@zafarali
Copy link
Contributor

zafarali commented Dec 9, 2016

Looks good!

@zafarali
Copy link
Contributor

zafarali commented Dec 10, 2016

It seems that all layers get the same activation with this commit?

Also wouldn't it be better to allow activation function parameters to be passed as an object

activation_params = {
 alpha: 0.005,
 gamma: 0.04
}

and then the activation functions can pick out whatever parameters necessary?

@0x33467
Copy link
Member Author

0x33467 commented Dec 10, 2016

ok, I will change the activation params. I you can pass the parameters as an array or object but now the current parametric activation functions takes only 1 argument as the Wikipedia functions that you propose...

@@ -0,0 +1,88 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a lower case name for this file (it doesn't export a class)


var Matrix = require('ml-matrix');

class Utils {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it a usual export of functions instead of a class ?
Then the filename can be lowercase

* @param {Matrix} B
* @return {Matrix} A
*/
static matrixSum(A, B) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the same as A.add(B) ? Same question for the other methods

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the current version of matrix I didn't find those methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are currently not documented but they exist.
See here for a list of all supported operators and here for general Math methods.

@@ -1,3 +1,3 @@
'use strict';

module.exports = require('./feedforwardNeuralNetwork');
module.exports = require('./FeedForwardNeuralNetwork');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of re-exporting FeedForwardNeuralNetwork from here, you can remove this file and change the main field in package.json

* @return {Matrix} the new delta values for the next layer.
*/
backpropagation(delta, a) {
this.dW = a.transpose().mmul(delta);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can win some time and memory by using a Matrix view for the transpose here and in other places. Just replace a.transpose() with a.transposeView().
This is a relatively new feature. You can see how it works here: https://github.com/mljs/matrix/blob/master/src/views/transpose.js
And the list of currently implemented views: https://mljs.github.io/matrix/#Matrix#transposeView

also small changes on filenames and export methods.
@0x33467
Copy link
Member Author

0x33467 commented Dec 12, 2016

I'm getting a timeout error, should I do a shorter test?

@targos
Copy link
Member

targos commented Dec 12, 2016

If you know it will take less than say 10secs, you can call this.timeout(10000) in the corresponding test: http://mochajs.org/#test-level
Otherwise if it's too long or unpredictable, yes, you should try to make it shorter.

@0x33467
Copy link
Member Author

0x33467 commented Dec 12, 2016

ok, those changes are now ok? @targos

@targos
Copy link
Member

targos commented Dec 14, 2016

Thanks, I'll finish the review tomorrow


var Layer = require('./Layer');
var OutputLayer = require('./OutputLayer');
var Utils = require('./utils');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use const for this cases?

* @param {number} [options.activationParam=1] - if the selected activation function needs a parameter.
*/
constructor(options) {
if (options === undefined) options = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options = options || {} it's just nicer

this.activation = options.activation === undefined ? 'tanh' : options.activation;
this.activationParam = options.activationParam === undefined ? 1 : options.activationParam;
if (!(this.activation in Object.keys(ACTIVATION_FUNCTIONS))) {
//console.warn("Setting default activation function: 'tanh'");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this old code commented should be removed or at least comment why it's commented like this

@0x33467
Copy link
Member Author

0x33467 commented Dec 16, 2016

Ok, I added your changes @maasencioh

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any outstanding issue. If @maasencioh is OK with it, you can merge. Do not forget to make a major version bump if you release it, because the API has changed.

@maasencioh
Copy link
Member

For me you can merge, thanks!

@0x33467 0x33467 merged commit aad95d8 into master Dec 16, 2016
@targos targos deleted the refactorNetworks branch December 19, 2016 19:26
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