-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add trace (forgot it in the last commit), update examples
- Loading branch information
1 parent
12fd0f7
commit 82ce1ba
Showing
5 changed files
with
126 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Four cases: | ||
How to solve that elegantly? | ||
1. Standard genotype, single-objective | ||
-> x and **best** y can be saved in optPath as well as entire population | ||
2. Standard genotype, multi-objective | ||
-> x and y can be saved in optPath, but there is no *best* | ||
3. Custom genotype, single-objective | ||
-> **only** (best) y can be saved (x values not scalar or vector) | ||
4. Custom genotype, multi-objective | ||
-> **only** y values can be saved (there is no best and x values not scalar) | ||
|
||
Possible solutions (these are just some considerations) | ||
- Principally do not use optPath to store x-values. Always save them in a list -> this way we need not distinguish between all the genotype variants | ||
- setup 'ecr templates': one for custom representations and one for standard representations. This way we could always store all the stuff in the opt.path for default without hindering and we would still have a mess for custom representations :-( | ||
- | ||
|
||
Moreover! | ||
optPath is passed to terminator objects. | ||
-> Terminators need to become ecr_operators with supported.objectives field (like selectors). E.g. stop if global optimum is approximated is not suitable as an emoa stopping condition. | ||
|
||
|
||
|
||
:-( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Helper - Generator for trace objects. | ||
# | ||
# Trace objects are kind of a wrapper for optPath and other stuff which is specific | ||
# to single- and multiobjective tracing respectively. | ||
# | ||
# @param control [ecr_control] | ||
# Control object. | ||
# @param population [ecr_population] | ||
# Current population. | ||
# @param n.objecjtive [integer(1)] | ||
# Number of targets/objectives. | ||
# @param y.names [character(1)] | ||
# Names for the y-columns in the opt.path. | ||
# @return [ecr_single_objective_trace | ecr_multi_objective_trace] | ||
initTrace = function(control, population, n.objectives, y.names) { | ||
par.set = control$par.set | ||
opt.path = makeOptPathDF(par.set, y.names = y.names, minimize = rep(TRUE, n.objectives), include.extra = TRUE, include.exec.time = TRUE) | ||
|
||
if (n.objectives == 1L) { | ||
best = getBestIndividual(population) | ||
return(makeS3Obj( | ||
opt.path = opt.path, | ||
best = best, | ||
classes = c("ecr_single_objective_trace") | ||
)) | ||
} | ||
return(makeS3Obj( | ||
opt.path = opt.path, | ||
classes = c("ecr_multi_objective_trace") | ||
)) | ||
} | ||
|
||
# Helper - Updates a trace with the information of the current population. | ||
# | ||
# @param trace [ecr_{single,multi}_objective_trace] | ||
# Trace to update. | ||
# @param iter [integer(1)] | ||
# Current iteration/generation. | ||
# @param population [ecr_population] | ||
# Population object. | ||
# @param start.time [POSIXct] | ||
# Beginning of the optimization process. | ||
# @param exec.time [numeric(1)] | ||
# Time it took to generate the initial population or set up the new population | ||
# respectively. | ||
# @param control [ecr_control] | ||
# Control object. | ||
# @return [ecr_{single,multi}_objective_trace] Modified trace. | ||
updateTrace = function(trace, iter, population, start.time, exec.time, control) { | ||
UseMethod("updateTrace") | ||
} | ||
|
||
# see generic updateTrace | ||
updateTrace.ecr_single_objective_trace = function(trace, iter, population, start.time, exec.time, control) { | ||
par.set = control$par.set | ||
best = getBestIndividual(population) | ||
extras = getListOfExtras(iter, population, start.time, control) | ||
if (length(par.set$pars) == 1L) { | ||
best.param.values = list(best$individual) | ||
names(best.param.values) = getParamIds(par.set) | ||
} else { | ||
best.param.values = as.list(best$individual) | ||
names(best.param.values) = getParamIds(par.set, repeated = TRUE, with.nr = TRUE) | ||
} | ||
#FIXME: dummy value for custom representation | ||
if (control$representation == "custom") { | ||
best.param.values = list("x" = 0.5) | ||
} | ||
addOptPathEl(trace$opt.path, x = best.param.values, y = unlist(best$fitness), dob = iter, | ||
exec.time = exec.time, extra = extras, check.feasible = FALSE) | ||
trace$best = best | ||
return(trace) | ||
} | ||
|
||
# see generic updateTrace | ||
updateTrace.ecr_multi_objective_trace = function(trace, iter, population, start.time, exec.time, control) { | ||
par.set = control$par.set | ||
extras = getListOfExtras(iter, population, start.time, control) | ||
#FIXME: handle this specific stuff here. | ||
if (control$representation == "custom") { | ||
stopf("Multi-objective optimization with custom genotypes is not yet finished.") | ||
best.param.values = list("x" = 0.5) | ||
} | ||
n.population = length(population$individuals) | ||
#FIXME: since we store the entire population anew, we set the eol stuff | ||
# if (iter > 1L) { | ||
# dobs = getOptPathDOB(trace$opt.path) | ||
# idx = which(dobs == (iter - 1L)) | ||
# setOptPathElEOL(trace$opt.path, index = idx, eol = iter) | ||
# } | ||
|
||
for (i in seq(n.population)) { | ||
x = as.list(population$individuals[[i]]) | ||
names(x) = getParamIds(control$par.set, with.nr = TRUE, repeated = TRUE) | ||
addOptPathEl(trace$opt.path, x = x, y = population$fitness[, i], dob = iter, | ||
exec.time = 0, extra = extras, check.feasible = FALSE) | ||
} | ||
return(trace) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters