synaptic icon indicating copy to clipboard operation
synaptic copied to clipboard

use seeded randomness

Open wighawag opened this issue 7 years ago • 6 comments

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.

wighawag avatar Sep 28 '18 09:09 wighawag

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.

ghost avatar Oct 03 '18 17:10 ghost

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

wighawag avatar Oct 03 '18 17:10 wighawag

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

flesler avatar Oct 27 '18 18:10 flesler

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

SNavleen avatar Nov 12 '18 10:11 SNavleen

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

flesler avatar Nov 12 '18 12:11 flesler

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.

SNavleen avatar Nov 13 '18 18:11 SNavleen