-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OptPath logger #142
Comments
ok. I can add an |
An even more flexible solution: no hard-coded opt.path stuff, no dedicated logger object. fn = makeSphereFunction(5L)
control = setupECRControl(
n.population = 50L,
n.offspring = 10L,
survival.strategy = "plus",
monitor = makeNullMonitor(),
stopping.conditions = list(makeMaxIterStoppingCondition(max.iter = 1000L)
representation = "float"
)
control = registerAction(control, "onEAInitialized", function(opt.state, ...) {
# do monitoring
catf("EA initialized successfully!")
# init opt path for instance
opt.state$opt.path = ...
})
control = registerAction(control, "onOffspringGenerated", function(opt.state, ...) {
# do some local search (even stuff like that possible)
if (opt.state$iter %/% 50) {
opt.state$offspring = lapply(opt.state$offspring, doLocalSearch)
}
# update opt.path
addOptPathEl(opt.state$opt.path, ...)
catf("Awesome EA magic ...")
})
res = doTheEvolution(fn, control = control) In the ecr code we place calls to the dispatcher where appropriate, e.g., ...
offspring = generateOffspring(opt.state, matingPool, control)
control$event.dispatcher$fireEvent("onOffspringGeneration", opt.state)
... This is maximally flexible in my eyes and solves a lot of problems:
What do you think? |
My 2cents: IMHO: |
Thanks for your comment Bernd.
😄 No, but IMHO this is an elegant and flexible design.
Ok, so I already mentioned use cases above.
registerAction("onOffspringGenerated", function(opt.state) myLocalSearch(opt.state$offspring))
Additionally this mechanism has benefits regarding code quality I think. Instead of a dozen internal hard-coded calls to different methods I can just write simple plugins like logger or monitor which are loosely coupled. By the way: I already wrote the dispatcher on the way home today. It is just about 30 lines of very readable code and works great. |
I dont dislike your approach that much. It makes your design really cleaner and not overly complex go for it. But I still think that all of the examples you mention above are very "specific" to EAs. What I mean is that direct functionality / hooks should be available in the package for just that
|
I already included the dispatching mechanism. Monitoring and logging are done via dispatcher plugins now. Makes everything much cleaner. However, logger and monitor can be passed to the control object which internally registers the corresponding actions (I think this is what you mean with hooks). |
At the moment I am experimenting with the best way to log. Since using the |
Well, how do you currently log? And why is that faster? |
Well, I have currently two types of loggers: my default logger and the ParamHelpers opt path logger. The default logger simply logs the entire population and some stats on the fitness in lists. The optPathLogger stores only the best individual of each generation in the opt.path (not the entire population). |
This benchmark reveals the slowness of the current opt path. This is exactly what is done within the (100+10) EA without the EA computations: par.set = makeParamSet(
makeNumericVectorParam("x", len = 100L, lower = 0, upper = 10)
)
n.iter = 10000L
res1 = system.time({
opt.path = makeOptPathDF(par.set = par.set, y.names = "y", minimize = TRUE)
for (i in seq(n.iter)) {
val = sampleValue(par.set)
y.val = runif(1L)
addOptPathEl(opt.path, x = val, y = y.val, dob = i, check.feasible = FALSE)
}
})
print(res1)
> User System verstrichen
> 251.70 20.81 274.37 |
The problem is the last |
We now have an logger which stores stuff to the ParamHelpers OptPath. However, we need to tackle the performance issue. I think preallocating a large matrix with some heuristic for expansion is sufficient for the moment. |
There are 3 obvious, complementary improvements:
1-2) are already done and help a lot. 3) I am working on. Will try to post more finished stuff soon. |
Sounds great. Thanks! |
Did you already commit 1) and 2)? |
Nope, I am working on it locally, as the 3 somehow belong together. I will try to push a branch this weekend that works |
Awesome! |
What is the status here? When are you going to commit the OptPath improvements. |
ping |
ping^2 |
ping |
2 similar comments
ping |
ping |
as this is simply a performance improvment i cannot finish this now, as there is too much to do. but i am happy to support you if you want to finish this, i made quite a lot of progess |
Ok. Thanks for the response. |
really sorry, just tried to be honest here. if you look at this too, i might also be able to invest some cycles. |
No problem. This is of minor importance at the moment. |
The
opt.path
is optional from now on (see #141).The text was updated successfully, but these errors were encountered: