Inversion of control for getFitness()?

已查看 30 次
跳至第一个未读帖子

Ian Clarke

未读,
2011年6月9日 14:04:072011/6/9
收件人 epo...@googlegroups.com
I'm wondering if there is any way to do an "inversion of control" in how we determine getFitness()?

To clarify, I'm using EpochX to try to evolve a bot that can speculate on the Bitcoin-USD market.  My fitness function involves simulating a bot's behavior across a period of time, and seeing how much money the bot makes.  I do this in 1-minute "ticks" over a 7 day period.  At each tick, the bot gets a new piece of information (the market price and related data), and decides to buy, sell, or hold.

The problem is that the setup required for each "tick" is relatively intensive, and for each GPCandidateProgram.getFitness() I have to do it about 10 thousand times, and of course I have to do that for each of the 1,000 candidates in each generation.

I think it would be more efficient if I could measure the fitness of all the candidates "in parallel" - so do the setup for the first tick, check the behavior of all candidates, recording what they do, then the next tick, and so-on.

This way, I only need to do one-pass through the 7 days of behavior, rather than 1,000 passes.

I realize this is a long-shot, but is there any (reasonably sane) way to achieve this?

Ian.

Tom Castle

未读,
2011年6月9日 18:23:312011/6/9
收件人 EpochX
Yes, that would make sense. Unfortunately, there's not a nice way to
do this at the moment. Each candidate program's evaluation is rather
independent of the others. This is a bit of a flaw actually, and will
be changing in the v.2.0 release.

I think there might be a slightly hacky work around you could use
though. Each program caches its fitness when it is first requested
(unless you've turned fitness caching off). So, you can artificially
create an evaluation step, when you evaluate all the programs
simultaneously.

The way I'd go about this is to use the generation hook, which should
occur before any programs are evaluated (unless any of your genetic
operators call getFitness on the child programs it creates - probably
not). In the hook, you'll receive the whole population. Calculate the
fitness of all the programs in parallel here, storing the fitness
values in an array the same length as the population. Then, before
returning the hook, iterate over the population (keeping track of the
index) and call each program's getFitness method in turn. This will
trigger a call to your model's getFitness method. Replace your model's
current getFitness method with a lookup to the array using the index.
This should result in a population of programs with the correct
fitnesses cached.

Hopefully that makes sense!

Tom
回复全部
回复作者
转发
0 个新帖子