The mutator

This time we consider a mutator with memory, first obtain the code from:
https://github.com/jhlq/trademaker/blob/master/AI2.jl
Then load it into julia:
julia -L AI2

Create the mutator and its neural network:
mutator=init()

The mutator keeps track of the network, now we need some training samples.
example,target=rsample()

Examples consist of bars describing how dispersed the previous hundred trades were and a target value to assign to these bars depending on how fast two bids on the spread are bought.

The net is untrained so the result is random:
score(mutator.net,example,target)

Let’s poke it.
poke!(mutator,example,target)

The mutator pokes the net in various ways to make it conform to the target and also remembers the effect of poking a specific node, maximum score per example is 1.
score(mutator.net,example,target)

Ever had your brain poked continuously a thousand times?
for poke in 1:1000;println(poke!(mutator,example,target));end
score(mutator.net,example,target) #0.9999999

Let’s see what result we get on several samples
examples,targets=rsamples(10)

The score function is overloaded to handle sample arrays.
score(mutator.net,examples,targets)
poke!(mutator,examples,targets)
score(mutator.net,examples,targets)
sum(score(mutator.net,examples,targets))

The poke! function also, the exclamation point is a julia convention for functions that modify their arguments.
poke!(mutator,examples,targets)
sum(score(mutator.net,examples,targets))

The overloaded poker pokes once for each sample, because of this the end result is sometimes worse. So we use the pocket algorithm, it works like this: we take the best result so far, and put it in our pocket.

The pocket algorithm is part of the evolve function, let’s do ten iterations:
mutator=evolve(mutator,examples,targets,10);

Each time a better net is pocketed the new score is printed. Let’s evolve a lot.
mutator=evolve(mutator,examples,targets,10000);

After a while the rate of improvement decreases, this means we need to decrease the mutation factor which defaults to 0.1, a value that determines the strength of the poke!
mutator=evolve(mutator,examples,targets,1000,0.03);
mutator=evolve(mutator,examples,targets,1000,0.01);

Next up we will download the full trade history and make the mutator more agile.

Advertisements

About jhlq

"The leaf and his body were one. Neither possessed a separate permanent self. Neither could exist independently from the rest of the universe."
This entry was posted in Miscellaneous. Bookmark the permalink.

Spread a little love

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s