Johan Broddfelt

Rock, Scissor, Paper neural net

Play best out of 10

Are you good at Rock, Scissor, Paper. Then try to beat this program to 10 points... How did it go? No, the program does not know what you have pressed before selecting what to play. It is just analyzing the pattern you are playing with and if you have any bias on how you select what to play the neural net will pick up on that and beat you. In the current setup I use the 6 last inputs from you as training data and the winning choice for the next play as expected output. The first time the network just selects by random, then it adds the result for each round. Every round is saved as a training sample and the network is then trained on all the data.

// First training data
var input = [[0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0]];
var desired = [[[1,0,0]]];

// Training data after 8 rounds
var input = [
	[0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0],
	[0,1,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0],
	[0,0,1, 0,1,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0],
	[0,1,0, 0,0,1, 0,1,0, 0,0,0, 0,0,0, 0,0,0],
	[1,0,0, 0,1,0, 0,0,1, 0,1,0, 0,0,0, 0,0,0],
	[0,1,0, 1,0,0, 0,1,0, 0,0,1, 0,1,0, 0,0,0],
	[0,0,1, 0,1,0, 1,0,0, 0,1,0, 0,0,1, 0,1,0],
	[0,0,1, 0,0,1, 0,1,0, 1,0,0, 0,1,0, 0,0,1],
	[0,1,0, 0,0,1, 0,0,1, 0,1,0, 1,0,0, 0,1,0]
	];
var desired = [[
	[1,0,0],
	[0,1,0],
	[1,0,0],
	[0,0,1],
	[1,0,0],
	[0,1,0],
	[0,1,0],
	[1,0,0]
	]];

This is perhaps not the most interesting use case of a neural net, but this strategy of tracing data over time can be used to servile large amounts of input data and if the data for some reason breaks the regular pattern the network can send an alert, telling you that something is wrong. This is also one of the ways you can do predictions of weather, stocks, and other events in your business.

This is the verbose version that outputs information about the network as you play.

- rock-scissor-paper, neural net, software

<< Noughts and crosses neural net version
Follow using RSS
Lessons from building a spam filter >>

Comment

Name
Mail (Not public)
Send mail updates on new comments
0 comment