R Under development (unstable) (2025-12-31 r89265) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "GA" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('GA') Loading required package: foreach Loading required package: iterators Package 'GA' version 3.2.4 Type 'citation("GA")' for citing this R package in publications. Attaching package: ‘GA’ The following object is masked from ‘package:utils’: de > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("binary2decimal") > ### * binary2decimal > > flush(stderr()); flush(stdout()) > > ### Name: binary2decimal > ### Title: Binary encoding of decimal numbers and vice versa. > ### Aliases: binary2decimal decimal2binary > > ### ** Examples > > # for integer values > dval <- 12 > (bval <- decimal2binary(dval)) [1] 1 1 0 0 > binary2decimal(bval) [1] 12 > > # for real values > dval <- 12.456 > # use > (bval <- decimal2binary(dval*1000)) [1] 1 1 0 0 0 0 1 0 1 0 1 0 0 0 > binary2decimal(bval)/1000 [1] 12.456 > > > > cleanEx() > nameEx("binary2gray") > ### * binary2gray > > flush(stderr()); flush(stdout()) > > ### Name: binary2gray > ### Title: Gray encoding for binary strings > ### Aliases: binary2gray gray2binary > > ### ** Examples > > # Consider a five-bit encoding of values 15 and 16 using the standard > # binary coding > decimal2binary(15, 5) [1] 0 1 1 1 1 > decimal2binary(16, 5) [1] 1 0 0 0 0 > # Moving from 15 to 16 (or vice versa) all five bits need to be changed, > # but using Gray encoding the two binary strings differ by one bit. > binary2gray(decimal2binary(15, 5)) [1] 0 1 0 0 0 > binary2gray(decimal2binary(16, 5)) [1] 1 1 0 0 0 > > > > cleanEx() > nameEx("de") > ### * de > > flush(stderr()); flush(stdout()) > > ### Name: de > ### Title: Differential Evolution via Genetic Algorithms > ### Aliases: de show,de-method print,de-method > ### Keywords: optimize > > ### ** Examples > > # 1) one-dimensional function > f <- function(x) abs(x)+cos(x) > curve(f, -20, 20) > > DE <- de(fitness = function(x) -f(x), lower = -20, upper = 20) > plot(DE) > summary(DE) ── Differential Evolution ────────────── DE settings: Type = real-valued Population size = 10 Number of generations = 100 Elitism = 0 Stepsize = 0.8 Crossover probability = 0.5 Mutation probability = 0 Search domain = x1 lower -20 upper 20 DE results: Iterations = 100 Fitness function value = -1 Solution = x1 [1,] 0 > > curve(f, -20, 20, n = 1000) > abline(v = DE@solution, lty = 3) > > # 2) "Wild" function, global minimum at about -15.81515 > > wild <- function(x) 10*sin(0.3*x)*sin(1.3*x^2) + 0.00001*x^4 + 0.2*x + 80 > plot(wild, -50, 50, n = 1000) > > # from help("optim") > SANN <- optim(50, fn = wild, method = "SANN", + control = list(maxit = 20000, temp = 20, parscale = 20)) > unlist(SANN[1:2]) par value -15.6616 67.4703 > > DE <- de(fitness = function(...) -wild(...), lower = -50, upper = 50) > plot(DE) > summary(DE) ── Differential Evolution ────────────── DE settings: Type = real-valued Population size = 10 Number of generations = 100 Elitism = 0 Stepsize = 0.8 Crossover probability = 0.5 Mutation probability = 0 Search domain = x1 lower -50 upper 50 DE results: Iterations = 100 Fitness function value = -67.65118 Solution = x1 [1,] -15.65693 > > # 3) two-dimensional Rastrigin function > > Rastrigin <- function(x1, x2) + { + 20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2)) + } > > x1 <- x2 <- seq(-5.12, 5.12, by = 0.1) > f <- outer(x1, x2, Rastrigin) > persp3D(x1, x2, f, theta = 50, phi = 20, col.palette = bl2gr.colors) > > DE <- de(fitness = function(x) -Rastrigin(x[1], x[2]), + lower = c(-5.12, -5.12), upper = c(5.12, 5.12), + popSize = 50) > plot(DE) > summary(DE) ── Differential Evolution ────────────── DE settings: Type = real-valued Population size = 50 Number of generations = 100 Elitism = 0 Stepsize = 0.8 Crossover probability = 0.5 Mutation probability = 0 Search domain = x1 x2 lower -5.12 -5.12 upper 5.12 5.12 DE results: Iterations = 100 Fitness function value = -9.222845e-12 Solution = x1 x2 [1,] -1.476754e-07 1.571135e-07 > > filled.contour(x1, x2, f, color.palette = bl2gr.colors, + plot.axes = { axis(1); axis(2); + points(DE@solution, + col = "yellow", pch = 3, lwd = 2) }) > > # 4) two-dimensional Ackley function > > Ackley <- function(x1, x2) + { + -20*exp(-0.2*sqrt(0.5*(x1^2 + x2^2))) - + exp(0.5*(cos(2*pi*x1) + cos(2*pi*x2))) + exp(1) + 20 + } > > x1 <- x2 <- seq(-3, 3, by = 0.1) > f <- outer(x1, x2, Ackley) > persp3D(x1, x2, f, theta = 50, phi = 20, col.palette = bl2gr.colors) > > DE <- de(fitness = function(x) -Ackley(x[1], x[2]), + lower = c(-3, -3), upper = c(3, 3), + stepsize = NA) > plot(DE) > summary(DE) ── Differential Evolution ────────────── DE settings: Type = real-valued Population size = 20 Number of generations = 100 Elitism = 0 Stepsize = runif(0.5,1.0) Crossover probability = 0.5 Mutation probability = 0 Search domain = x1 x2 lower -3 -3 upper 3 3 DE results: Iterations = 100 Fitness function value = -2.488335e-09 Solution = x1 x2 [1,] 3.082543e-10 8.239874e-10 > > filled.contour(x1, x2, f, color.palette = bl2gr.colors, + plot.axes = { axis(1); axis(2); + points(DE@solution, + col = "yellow", pch = 3, lwd = 2) }) > > # 5) Curve fitting example (see Scrucca JSS 2013) > > ## Not run: > ##D # subset of data from data(trees, package = "spuRs") > ##D tree <- data.frame(Age = c(2.44, 12.44, 22.44, 32.44, 42.44, 52.44, 62.44, > ##D 72.44, 82.44, 92.44, 102.44, 112.44), > ##D Vol = c(2.2, 20, 93, 262, 476, 705, 967, 1203, 1409, > ##D 1659, 1898, 2106)) > ##D richards <- function(x, theta) > ##D { theta[1]*(1 - exp(-theta[2]*x))^theta[3] } > ##D fitnessL2 <- function(theta, x, y) > ##D { -sum((y - richards(x, theta))^2) } > ##D DE <- de(fitness = fitnessL2, x = tree$Age, y = tree$Vol, > ##D lower = c(3000, 0, 2), upper = c(4000, 1, 4), > ##D popSize = 500, maxiter = 1000, run = 100, > ##D names = c("a", "b", "c")) > ##D summary(DE) > ## End(Not run) > > > > > cleanEx() > nameEx("ga") > ### * ga > > flush(stderr()); flush(stdout()) > > ### Name: ga > ### Title: Genetic Algorithms > ### Aliases: ga show,ga-method print,ga-method > ### Keywords: optimize > > ### ** Examples > > # 1) one-dimensional function > f <- function(x) abs(x)+cos(x) > curve(f, -20, 20) > > fitness <- function(x) -f(x) > GA <- ga(type = "real-valued", fitness = fitness, lower = -20, upper = 20) > summary(GA) ── Genetic Algorithm ─────────────────── GA settings: Type = real-valued Population size = 50 Number of generations = 100 Elitism = 2 Crossover probability = 0.8 Mutation probability = 0.1 Search domain = x1 lower -20 upper 20 GA results: Iterations = 100 Fitness function value = -1.000022 Solution = x1 [1,] 2.239645e-05 > plot(GA) > > curve(f, -20, 20) > abline(v = GA@solution, lty = 3) > > # 2) one-dimensional function > f <- function(x) (x^2+x)*cos(x) # -10 < x < 10 > curve(f, -10, 10) > > # write your own tracing function > monitor <- function(obj) + { + curve(f, -10, 10, main = paste("iteration =", obj@iter)) + points(obj@population, obj@fitness, pch = 20, col = 2) + rug(obj@population, col = 2) + Sys.sleep(0.2) + } > ## Not run: > ##D GA <- ga(type = "real-valued", fitness = f, lower = -10, upper = 10, monitor = monitor) > ## End(Not run) > # or if you want to suppress the tracing > GA <- ga(type = "real-valued", fitness = f, lower = -10, upper = 10, monitor = NULL) > summary(GA) ── Genetic Algorithm ─────────────────── GA settings: Type = real-valued Population size = 50 Number of generations = 100 Elitism = 2 Crossover probability = 0.8 Mutation probability = 0.1 Search domain = x1 lower -10 upper 10 GA results: Iterations = 100 Fitness function value = 47.70562 Solution = x1 [1,] 6.560536 > > monitor(GA) > abline(v = GA@solution, lty = 3) > > # 3) two-dimensional Rastrigin function > > Rastrigin <- function(x1, x2) + { + 20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2)) + } > > x1 <- x2 <- seq(-5.12, 5.12, by = 0.1) > f <- outer(x1, x2, Rastrigin) > persp3D(x1, x2, f, theta = 50, phi = 20, col.palette = bl2gr.colors) > filled.contour(x1, x2, f, color.palette = bl2gr.colors) > > GA <- ga(type = "real-valued", fitness = function(x) -Rastrigin(x[1], x[2]), + lower = c(-5.12, -5.12), upper = c(5.12, 5.12), + popSize = 50, maxiter = 100) > summary(GA) ── Genetic Algorithm ─────────────────── GA settings: Type = real-valued Population size = 50 Number of generations = 100 Elitism = 2 Crossover probability = 0.8 Mutation probability = 0.1 Search domain = x1 x2 lower -5.12 -5.12 upper 5.12 5.12 GA results: Iterations = 100 Fitness function value = -7.889556e-06 Solution = x1 x2 [1,] -0.00015417 -0.0001264876 > plot(GA) > > # 4) Parallel GA > # Simple example of an expensive fitness function obtained artificially by > # introducing a pause statement. > ## Not run: > ##D Rastrigin <- function(x1, x2) > ##D { > ##D Sys.sleep(0.1) > ##D 20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2)) > ##D } > ##D > ##D system.time(GA1 <- ga(type = "real-valued", > ##D fitness = function(x) -Rastrigin(x[1], x[2]), > ##D lower = c(-5.12, -5.12), upper = c(5.12, 5.12), > ##D popSize = 50, maxiter = 100, monitor = FALSE, > ##D seed = 12345)) > ##D > ##D system.time(GA2 <- ga(type = "real-valued", > ##D fitness = function(x) -Rastrigin(x[1], x[2]), > ##D lower = c(-5.12, -5.12), upper = c(5.12, 5.12), > ##D popSize = 50, maxiter = 100, monitor = FALSE, > ##D seed = 12345, parallel = TRUE)) > ## End(Not run) > > # 5) Hybrid GA > # Example of GA with local search > > Rastrigin <- function(x1, x2) + { + 20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2)) + } > > GA <- ga(type = "real-valued", + fitness = function(x) -Rastrigin(x[1], x[2]), + lower = c(-5.12, -5.12), upper = c(5.12, 5.12), + popSize = 50, maxiter = 100, + optim = TRUE) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/minus.h:336:15: runtime error: signed integer overflow: 51 - -2147483648 cannot be represented in type 'typename storage_type<13>::type' (aka 'int') #0 0x7fc79b96e933 in Rcpp::sugar::Minus_Primitive_Vector<13, true, Rcpp::Vector<13, Rcpp::PreserveStorage>>::operator[](long) const /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/minus.h:336:15 #1 0x7fc79b96e933 in void Rcpp::Vector<13, Rcpp::PreserveStorage>::import_expression>>(Rcpp::sugar::Minus_Primitive_Vector<13, true, Rcpp::Vector<13, Rcpp::PreserveStorage>> const&, long) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:1082:9 #2 0x7fc79b91ad63 in void Rcpp::Vector<13, Rcpp::PreserveStorage>::assign_object>>(Rcpp::sugar::Minus_Primitive_Vector<13, true, Rcpp::Vector<13, Rcpp::PreserveStorage>> const&, Rcpp::traits::integral_constant) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:1051:9 #3 0x7fc79b91ad63 in Rcpp::Vector<13, Rcpp::PreserveStorage>& Rcpp::Vector<13, Rcpp::PreserveStorage>::operator=>>(Rcpp::sugar::Minus_Primitive_Vector<13, true, Rcpp::Vector<13, Rcpp::PreserveStorage>> const&) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:245:9 #4 0x7fc79b91ad63 in rank_asR(Rcpp::Vector<14, Rcpp::PreserveStorage>, bool) /data/gannet/ripley/R/packages/tests-clang-UBSAN/GA/src/genope.cpp:21:23 #5 0x7fc79b9427a0 in optimProbsel_Rcpp(Rcpp::Vector<14, Rcpp::PreserveStorage>, double) /data/gannet/ripley/R/packages/tests-clang-UBSAN/GA/src/genope.cpp:1703:39 #6 0x7fc79b90eb09 in _GA_optimProbsel_Rcpp /data/gannet/ripley/R/packages/tests-clang-UBSAN/GA/src/RcppExports.cpp:466:34 #7 0x55de87130e53 in R_doDotCall (/data/gannet/ripley/R/R-clang/bin/exec/R+0x8ee53) #8 0x55de8717fdaf in bcEval_loop eval.c #9 0x55de87168beb in bcEval eval.c #10 0x55de87168374 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc6374) #11 0x55de87185768 in R_execClosure eval.c #12 0x55de87184c6b in applyClosure_core eval.c #13 0x55de871687c5 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc67c5) #14 0x55de8718ad6d in do_set (/data/gannet/ripley/R/R-clang/bin/exec/R+0xe8d6d) #15 0x55de8716859f in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc659f) #16 0x55de871ba717 in Rf_ReplIteration (/data/gannet/ripley/R/R-clang/bin/exec/R+0x118717) #17 0x55de871bc21e in run_Rmainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a21e) #18 0x55de871bc28a in Rf_mainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a28a) #19 0x55de870a3da7 in main (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1da7) #20 0x7fc7ac1135f4 in __libc_start_call_main (/lib64/libc.so.6+0x35f4) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #21 0x7fc7ac1136a7 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x36a7) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #22 0x55de870a3cc4 in _start (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1cc4) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/minus.h:336:15 > summary(GA) ── Genetic Algorithm ─────────────────── GA settings: Type = real-valued Population size = 50 Number of generations = 100 Elitism = 2 Crossover probability = 0.8 Mutation probability = 0.1 Search domain = x1 x2 lower -5.12 -5.12 upper 5.12 5.12 GA results: Iterations = 100 Fitness function value = 0 Solution = x1 x2 [1,] 0 0 > > > > > cleanEx() > nameEx("gaControl") > ### * gaControl > > flush(stderr()); flush(stdout()) > > ### Name: gaControl > ### Title: A function for setting or retrieving defaults genetic operators > ### Aliases: gaControl > > ### ** Examples > > # get and save defaults > defaultControl <- gaControl() > print(defaultControl) $binary $binary$population [1] "gabin_Population" $binary$selection [1] "gabin_lrSelection" $binary$crossover [1] "gabin_spCrossover" $binary$mutation [1] "gabin_raMutation" $`real-valued` $`real-valued`$population [1] "gareal_Population" $`real-valued`$selection [1] "gareal_lsSelection" $`real-valued`$crossover [1] "gareal_laCrossover" $`real-valued`$mutation [1] "gareal_raMutation" $permutation $permutation$population [1] "gaperm_Population" $permutation$selection [1] "gaperm_lrSelection" $permutation$crossover [1] "gaperm_oxCrossover" $permutation$mutation [1] "gaperm_simMutation" $eps [1] 1.490116e-08 $useRcpp [1] TRUE > # get current defaults only for binary search > gaControl("binary") $population [1] "gabin_Population" $selection [1] "gabin_lrSelection" $crossover [1] "gabin_spCrossover" $mutation [1] "gabin_raMutation" > # set defaults for selection operator of binary search > gaControl("binary" = list(selection = "gabin_tourSelection")) > gaControl("binary") $population [1] "gabin_Population" $selection [1] "gabin_tourSelection" $crossover [1] "gabin_spCrossover" $mutation [1] "gabin_raMutation" > # set defaults for selection and crossover operators of binary search > gaControl("binary" = list(selection = "ga_rwSelection", + crossover = "gabin_uCrossover")) > gaControl("binary") $population [1] "gabin_Population" $selection [1] "ga_rwSelection" $crossover [1] "gabin_uCrossover" $mutation [1] "gabin_raMutation" > # restore defaults > gaControl(defaultControl) > gaControl() $binary $binary$population [1] "gabin_Population" $binary$selection [1] "gabin_lrSelection" $binary$crossover [1] "gabin_spCrossover" $binary$mutation [1] "gabin_raMutation" $`real-valued` $`real-valued`$population [1] "gareal_Population" $`real-valued`$selection [1] "gareal_lsSelection" $`real-valued`$crossover [1] "gareal_laCrossover" $`real-valued`$mutation [1] "gareal_raMutation" $permutation $permutation$population [1] "gaperm_Population" $permutation$selection [1] "gaperm_lrSelection" $permutation$crossover [1] "gaperm_oxCrossover" $permutation$mutation [1] "gaperm_simMutation" $eps [1] 1.490116e-08 $useRcpp [1] TRUE > > > > cleanEx() > nameEx("ga_pmutation") > ### * ga_pmutation > > flush(stderr()); flush(stdout()) > > ### Name: ga_pmutation > ### Title: Variable mutation probability in genetic algorithms > ### Aliases: ga_pmutation ga_pmutation_R ga_pmutation_Rcpp > > ### ** Examples > > ## Not run: > ##D Rastrigin <- function(x1, x2) > ##D { > ##D 20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2)) > ##D } > ##D > ##D GA <- ga(type = "real-valued", > ##D fitness = function(x) -Rastrigin(x[1], x[2]), > ##D lower = c(-5.12, -5.12), upper = c(5.12, 5.12), > ##D popSize = 50, maxiter = 500, run = 100, > ##D pmutation = ga_pmutation) > ##D plot(GA) > ##D > ##D GA <- ga(type = "real-valued", > ##D fitness = function(x) -Rastrigin(x[1], x[2]), > ##D lower = c(-5.12, -5.12), upper = c(5.12, 5.12), > ##D popSize = 50, maxiter = 500, run = 100, > ##D pmutation = function(...) ga_pmutation(..., p0 = 0.1)) > ##D plot(GA) > ## End(Not run) > > > > cleanEx() > nameEx("gaisl") > ### * gaisl > > flush(stderr()); flush(stdout()) > > ### Name: gaisl > ### Title: Islands Genetic Algorithms > ### Aliases: gaisl show,gaisl-method print,gaisl-method > ### Keywords: optimize > > ### ** Examples > > ## Not run: > ##D # two-dimensional Rastrigin function > ##D Rastrigin <- function(x1, x2) > ##D { > ##D 20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2)) > ##D } > ##D > ##D x1 <- x2 <- seq(-5.12, 5.12, by = 0.1) > ##D f <- outer(x1, x2, Rastrigin) > ##D persp3D(x1, x2, f, theta = 50, phi = 20) > ##D filled.contour(x1, x2, f, color.palette = jet.colors) > ##D > ##D GA <- gaisl(type = "real-valued", > ##D fitness = function(x) -Rastrigin(x[1], x[2]), > ##D lower = c(-5.12, -5.12), upper = c(5.12, 5.12), > ##D popSize = 80, maxiter = 500, > ##D numIslands = 4, migrationInterval = 50) > ##D summary(GA) > ##D plot(GA) > ## End(Not run) > > > > cleanEx() > nameEx("numericOrNA-class") > ### * numericOrNA-class > > flush(stderr()); flush(stdout()) > > ### Name: numericOrNA-class > ### Title: Virtual Class "numericOrNA" - Simple Class for sub-assignment > ### Values > ### Aliases: numericOrNA-class > ### Keywords: classes > > ### ** Examples > > showClass("numericOrNA") Virtual Class "numericOrNA" [package "GA"] No Slots, prototype of class "numeric" Known Subclasses: Class "numeric", directly Class "logical", directly Class "integer", by class "numeric", distance 2 Class "double", by class "numeric", distance 2 Class "factor", by class "numeric", distance 3 Class "ordered", by class "numeric", distance 4 > > > > cleanEx() > nameEx("palettes") > ### * palettes > > flush(stderr()); flush(stdout()) > > ### Name: palettes > ### Title: Colours palettes > ### Aliases: jet.colors spectral.colors bl2gr.colors > ### Keywords: hplot > > ### ** Examples > > jet.colors(9) [1] "#00007F" "#0000FF" "#007FFF" "#00FFFF" "#7FFF7F" "#FFFF00" "#FF7F00" [8] "#FF0000" "#7F0000" > spectral.colors(9) [1] "#2B83BA" "#6BB0AF" "#ABDDA4" "#D4EEB1" "#FFFFBF" "#FED690" "#FDAE61" [8] "#EA633E" "#D7191C" > bl2gr.colors(9) [1] "#073F80" "#0862A6" "#2582B9" "#42A4CB" "#67BFCB" "#8DD2BE" "#B1E0B8" [8] "#CEECC7" "#DFF2DA" > > par(mfrow = c(3,1), mar = c(1,1,1,1)) > n = 21 > image(1:21, 1, as.matrix(1:21), col = jet.colors(21), + ylab = "", xlab = "", xaxt = "n", yaxt = "n", bty = "n") > image(1:21, 1, as.matrix(1:21), col = spectral.colors(21), + ylab = "", xlab = "", xaxt = "n", yaxt = "n", bty = "n") > image(1:21, 1, as.matrix(1:21), col = bl2gr.colors(21), + ylab = "", xlab = "", xaxt = "n", yaxt = "n", bty = "n") > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() > nameEx("persp3D") > ### * persp3D > > flush(stderr()); flush(stdout()) > > ### Name: persp3D > ### Title: Perspective plot with colour levels > ### Aliases: persp3D > ### Keywords: hplot > > ### ** Examples > > y <- x <- seq(-10, 10, length=60) > f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r } > z <- outer(x, y, f) > persp3D(x, y, z, theta = 30, phi = 30, expand = 0.5) > persp3D(x, y, z, col.palette = heat.colors, phi = 30, theta = 225, + box = TRUE, border = NA, shade = .4) > x1 <- seq(-3,3,length=50) > x2 <- seq(-3,3,length=50) > y <- function(x1, x2) sin(x1)+cos(x2) > persp3D(x1, x2, outer(x1,x2,y), zlab="y", theta = 150, phi = 20, expand = 0.6) > > > > cleanEx() > nameEx("plot.de-method") > ### * plot.de-method > > flush(stderr()); flush(stdout()) > > ### Name: plot.de-method > ### Title: Plot of Differential Evolution search path > ### Aliases: plot,de-method > ### Keywords: methods hplot > > ### ** Examples > > # See examples in help(de) > > > > cleanEx() > nameEx("plot.ga-method") > ### * plot.ga-method > > flush(stderr()); flush(stdout()) > > ### Name: plot.ga-method > ### Title: Plot of Genetic Algorithm search path > ### Aliases: plot,ga-method plot.ga > ### Keywords: methods hplot > > ### ** Examples > > # See examples in help(ga) > > # The following code shows how to obtain graphs using the > # ggplot2 plotting system > ## Not run: > ##D GA <- ga(type = "real-valued", > ##D fitness = function(x) -(abs(x)+cos(x)), > ##D lower = -20, upper = 20, > ##D popSize = 20, pmutation = 0.2, maxiter = 50) > ##D out <- plot(GA) > ##D library(reshape2) > ##D df <- melt(out[,c(1:3,5)], id.var = "iter") > ##D library(ggplot2) > ##D ggplot(out) + > ##D geom_ribbon(aes(x = iter, ymin = median, ymax = max, > ##D colour = "median", fill = "median")) + > ##D geom_line(aes(x = iter, y = max, colour = "max")) + > ##D geom_point(aes(x = iter, y = max, colour = "max")) + > ##D geom_line(aes(x = iter, y = mean, colour = "mean"), lty = 2) + > ##D geom_point(aes(x = iter, y = mean, colour = "mean"), pch = 1) + > ##D xlab("Generation") + ylab("Fitness values") + > ##D scale_colour_manual(breaks = c("max", "mean", "median"), > ##D values = c("green3", "dodgerblue3", adjustcolor("green3", alpha.f = 0.1))) + > ##D scale_fill_manual(breaks = "median", > ##D values = adjustcolor("green3", alpha.f = 0.1)) + > ##D guides(fill = "none", > ##D colour = guide_legend(override.aes = > ##D list(fill = c(NA, NA, adjustcolor("green3", alpha.f = 0.1)), > ##D pch = c(19,1,NA)))) + > ##D theme_bw() + > ##D theme(legend.title = element_blank(), > ##D legend.pos = "top", > ##D legend.background = element_blank()) > ## End(Not run) > > > > cleanEx() > nameEx("plot.gaisl-method") > ### * plot.gaisl-method > > flush(stderr()); flush(stdout()) > > ### Name: plot.gaisl-method > ### Title: Plot of Islands Genetic Algorithm search path > ### Aliases: plot,gaisl-method plot.gaisl > ### Keywords: methods hplot > > ### ** Examples > > # See examples in help(gaisl) > > > > cleanEx() > nameEx("summary.de-method") > ### * summary.de-method > > flush(stderr()); flush(stdout()) > > ### Name: summary.de-method > ### Title: Summary for Differential Evolution > ### Aliases: summary,de-method summary.de print.summary.de > ### Keywords: optimize > > ### ** Examples > > f <- function(x) abs(x)+cos(x) > DE <- de(fitness = function(x) -f(x), + lower = -20, upper = 20, run = 50) > out <- summary(DE) > print(out) ── Differential Evolution ────────────── DE settings: Type = real-valued Population size = 10 Number of generations = 100 Elitism = 0 Stepsize = 0.8 Crossover probability = 0.5 Mutation probability = 0 Search domain = x1 lower -20 upper 20 DE results: Iterations = 90 Fitness function value = -1 Solution = x1 [1,] 5.55337e-17 > str(out) List of 12 $ type : chr "real-valued" $ popSize : num 10 $ maxiter : num 100 $ elitism : int 0 $ stepsize : num 0.8 $ pcrossover : num 0.5 $ pmutation : num 0 $ domain : num [1:2, 1] -20 20 ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:2] "lower" "upper" .. ..$ : chr "x1" $ suggestions: NULL $ iter : int 90 $ fitness : num -1 $ solution : num [1, 1] 5.55e-17 ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr "x1" - attr(*, "class")= chr "summary.de" > > > > cleanEx() > nameEx("summary.ga-method") > ### * summary.ga-method > > flush(stderr()); flush(stdout()) > > ### Name: summary.ga-method > ### Title: Summary for Genetic Algorithms > ### Aliases: summary,ga-method summary.ga print.summary.ga > ### Keywords: optimize > > ### ** Examples > > f <- function(x) abs(x)+cos(x) > GA <- ga(type = "real-valued", + fitness = function(x) -f(x), + lower = -20, upper = 20, run = 50) > out <- summary(GA) > print(out) ── Genetic Algorithm ─────────────────── GA settings: Type = real-valued Population size = 50 Number of generations = 100 Elitism = 2 Crossover probability = 0.8 Mutation probability = 0.1 Search domain = x1 lower -20 upper 20 GA results: Iterations = 100 Fitness function value = -1.000022 Solution = x1 [1,] 2.239645e-05 > str(out) List of 11 $ type : chr "real-valued" $ popSize : num 50 $ maxiter : num 100 $ elitism : int 2 $ pcrossover : num 0.8 $ pmutation : num 0.1 $ domain : num [1:2, 1] -20 20 ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:2] "lower" "upper" .. ..$ : chr "x1" $ suggestions: NULL $ iter : int 100 $ fitness : num -1 $ solution : num [1, 1] 2.24e-05 ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr "x1" - attr(*, "class")= chr "summary.ga" > > > > cleanEx() > nameEx("summary.gaisl-method") > ### * summary.gaisl-method > > flush(stderr()); flush(stdout()) > > ### Name: summary.gaisl-method > ### Title: Summary for Islands Genetic Algorithms > ### Aliases: summary,gaisl-method summary.gaisl print.summary.gaisl > ### Keywords: optimize > > ### ** Examples > > ## Not run: > ##D f <- function(x) abs(x)+cos(x) > ##D GA <- gaisl(type = "real-valued", > ##D fitness = function(x) -f(x), > ##D lower = -20, upper = 20, run = 10, > ##D numIslands = 4) > ##D out <- summary(GA) > ##D print(out) > ##D str(out) > ## End(Not run) > > > > ### *