cazala / synaptic

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

use seeded randomness #335

Open wighawag opened 6 years ago

wighawag commented 6 years ago

Currently synaptic use Math.random inside the code like https://github.com/cazala/synaptic/blob/master/src/Neuron.js#L60

This means when you create a neural network, it will behave differently when run in different computers / different times

It would be a good idea to (maybe optionally) specify a seed that get used for all randomness execution.

Currently I can just monkey-patch Math.random for that but this is not ideal.

ghost commented 6 years ago

Yes, but a fine tuned NN will perform very similar on each run. Also, if you want to increase the prediction score you want to run a swarm of NNs (at least 8) and median their output. So different results are actually a good thing.

wighawag commented 6 years ago

For my use case (a game) I need reproducible output.

Note for those who want randomness for the swarm use case you mention for example, different seeds can be given. The point here is that if the library do not allow to set a seed (could be optional as mentioned), the only way to have reproducible output is to monkey patch Math.random

flesler commented 5 years ago

+1, determinism is a plus and I see no downside

SNavleen commented 5 years ago

Hi,

I just came across this, and it wouldn't hurt to have seeded randomness.

If you would like I can work on this and create a pull request. I have previously used seedrandom, in my sample neural network library. There is a np version of this library as well if needed.

If some one can assign me this task please let me know.

Thanks

flesler commented 5 years ago

I would say that just adding something like a synaptic.random() that returns Math.random() and using it everywhere, will let "us" override it any way we want. That seems simpler and overall preferable, each can decide which random implementation to override with, when to reset it, etc

SNavleen commented 5 years ago

That would be much better. I will retract my statement saying I can work on it since I am not sure how I would go about implanting it. I might still give it a try, to help me learn.