Skip to content

Commit

Permalink
No big changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Dec 22, 2017
1 parent 01266a3 commit 3a26879
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 69 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -9,7 +9,7 @@ Authors@R: c(
)
Description: An implementation of Karaboga (2005) Artificial Bee Colony
Optimization algorithm <http://mf.erciyes.edu.tr/abc/pub/tr06_2005.pdf>.
This was developed upon the basic version programmed in C and distributed
This was developed upon the basic version programmed in C and available
at the algorithm's official website.
Classification/ACM: G.1.6
Classification/JEL: C61
Expand All @@ -26,3 +26,4 @@ Imports:
RoxygenNote: 6.0.1.9000
Suggests: testthat,
covr
Roxygen: list(markdown = TRUE)
24 changes: 10 additions & 14 deletions R/ABCoptim-package.R
Expand Up @@ -3,33 +3,29 @@
#' An implementation of the Artificial Bee Colony (ABC) Algorithm
#'
#' This is an implementation of Karaboga (2005) ABC optimization algorithm. It
#' was developed upon the basic version programmed in \code{C} and distributed
#' was developed upon the basic version programmed in `C` and distributed
#' at the algorithm's official website (see the references).
#'
#' Please consider that this version is in alpha state of development, thus any
#' evident (precision) error should be blaimed to the package author (not to
#' the algorithm itself)
#' Any evident (precision) error should be blaimed to the package author (not to
#' the algorithm itself).
#'
#' Please visit the project home for more information:
#' \url{https://github.com/gvegayon/ABCoptim}.
#' https://github.com/gvegayon/ABCoptim.
#'
#' @name ABCoptim-package
#' @aliases ABCoptim-package ABCoptim abc
#' @docType package
#' @author George Vega Yon \email{g.vegayon@@gmail.com} [aut],
#'
#' Enyelbert Muñoz \email{enyeldoc2011@@gmail.com} [cnt)
#' @references D. Karaboga, \emph{An Idea based on Honey Bee Swarm for
#' Numerical Optimization}, tech. report TR06,Erciyes University, Engineering
#' @references D. Karaboga, *An Idea based on Honey Bee Swarm for
#' Numerical Optimization*, tech. report TR06,Erciyes University, Engineering
#' Faculty, Computer Engineering Department, 2005
#' \url{http://mf.erciyes.edu.tr/abc/pub/tr06_2005.pdf}
#' http://mf.erciyes.edu.tr/abc/pub/tr06_2005.pdf
#'
#'
#' Artificial Bee Colony (ABC) Algorithm (website)
#' \url{http://mf.erciyes.edu.tr/abc/index.htm}
#' http://mf.erciyes.edu.tr/abc/index.htm
#'
#' Basic version of the algorithm implemented in \code{C} (ABC's official
#' website) \url{http://mf.erciyes.edu.tr/abc/form.aspx}
#' Basic version of the algorithm implemented in `C` (ABC's official
#' website) http://mf.erciyes.edu.tr/abc/form.aspx
#' @keywords package
#' @examples
#'
Expand Down
4 changes: 2 additions & 2 deletions R/RcppExports.R
@@ -1,7 +1,7 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

abc_cpp_ <- function(par, fn, lb, ub, FoodNumber = 20L, limit = 100L, maxCycle = 1000L, criter = 50L) {
.Call(`_ABCoptim_abc_cpp_`, par, fn, lb, ub, FoodNumber, limit, maxCycle, criter)
.abc_cpp <- function(par, fn, lb, ub, FoodNumber = 20L, limit = 100L, maxCycle = 1000L, criter = 50L) {
.Call(`_ABCoptim_abc_cpp`, par, fn, lb, ub, FoodNumber, limit, maxCycle, criter)
}

64 changes: 32 additions & 32 deletions R/abc_optim.R
Expand Up @@ -6,62 +6,62 @@
#' @param fn A function to be minimized, with first argument of the vector of
#' parameters over which minimization is to take place. It should return a
#' scalar result.
#' @param ... In the case of \code{abc_*}, further arguments to be passed to 'fn',
#' @param ... In the case of `abc_*`, further arguments to be passed to 'fn',
#' otherwise, further arguments passed to the method.
#' @param FoodNumber Number of food sources to exploit. Notice that the param
#' \code{NP} has been deprecated.
#' `NP` has been deprecated.
#' @param lb,ub Numeric vectors or scalars. Upper and lower bounds of the
#' parameters to be optimized.
#' @param limit Integer scalar. Limit of a food source.
#' @param maxCycle Integer scalar. Maximum number of iterations.
#' @param optiinteger Logical scalar. Whether to optimize binary parameters or not.
#' @param criter Integer scalar. Stop criteria (numer of unchanged results) until stopping
#' @param parscale Numeric vector of length \code{length(par)}. Scale applied
#' to the parameters (see \code{\link[stats:optim]{optim}}).
#' @param fnscale Numeric scalar. Scale applied function. If \code{fnscale < 0},
#' then the problem becomes a maximization problem (see \code{\link[stats:optim]{optim}}).
#' @param parscale Numeric vector of length `length(par)`. Scale applied
#' to the parameters (see [stats:optim::optim()]).
#' @param fnscale Numeric scalar. Scale applied function. If `fnscale < 0`,
#' then the problem becomes a maximization problem (see [stats:optim::optim()]).
#'
#' @details
#'
#' This implementation of the ABC algorithm was developed based on the basic
#' version written in \code{C} and published at the algorithm's official
#' version written in `C` and published at the algorithm's official
#' website (see references).
#'
#' \code{abc_optim} and \code{abc_cpp} are two different implementations of the
#' algorithm, the former using pure \code{R} code, and the later using \code{C++},
#' `abc_optim` and `abc_cpp` are two different implementations of the
#' algorithm, the former using pure `R` code, and the later using `C++`,
#' via the \pkg{Rcpp} package. Besides of the output, another important
#' difference between the two implementations is speed, with \code{abc_cpp}
#' difference between the two implementations is speed, with `abc_cpp`
#' showing between 50\% and 100\% faster performance.
#'
#' Upper and Lower bounds (\code{ub}, \code{lb}) equal to infinite will be replaced
#' by either \code{.Machine$double.xmax} or \code{-.Machine$double.xmax}.
#' Upper and Lower bounds (`ub`, `lb`) equal to infinite will be replaced
#' by either `.Machine$double.xmax` or `-.Machine$double.xmax`.
#'
#' If \code{D} (the number of parameters to be optimzed) is greater than one,
#' then \code{lb} and \code{ub} can be either scalars (assuming that all the
#' If `D` (the number of parameters to be optimzed) is greater than one,
#' then `lb` and `ub` can be either scalars (assuming that all the
#' parameters share the same boundaries) or vectors (the parameters have
#' different boundaries each other).
#'
#' @return An list of class \code{abc_answer}, holding the following elements:
#' @return An list of class `abc_answer`, holding the following elements:
#' \item{Foods}{Numeric matrix. Last position of the bees.}
#' \item{f}{Numeric vector. Value of the function evaluated at each set of \code{Foods}.}
#' \item{fitness}{Numeric vector. Fitness of each \code{Foods}.}
#' \item{trial}{Integer vector. Number of trials at each \code{Foods}.}
#' \item{f}{Numeric vector. Value of the function evaluated at each set of `Foods`.}
#' \item{fitness}{Numeric vector. Fitness of each `Foods`.}
#' \item{trial}{Integer vector. Number of trials at each `Foods`.}
#' \item{value}{Numeric scalar. Value of the function evaluated at the optimum.}
#' \item{par}{Numeric vector. Optimum found.}
#' \item{counts}{Integer scalar. Number of cycles.}
#' \item{hist}{Numeric matrix. Trace of the global optimums.}
#'
#' @author George Vega Yon \email{g.vegayon@@gmail.com}
#' @references D. Karaboga, \emph{An Idea based on Honey Bee Swarm for
#' Numerical Optimization}, tech. report TR06,Erciyes University, Engineering
#' @references D. Karaboga, *An Idea based on Honey Bee Swarm for
#' Numerical Optimization*, tech. report TR06,Erciyes University, Engineering
#' Faculty, Computer Engineering Department, 2005
#' \url{http://mf.erciyes.edu.tr/abc/pub/tr06_2005.pdf}
#' http://mf.erciyes.edu.tr/abc/pub/tr06_2005.pdf
#'
#' Artificial Bee Colony (ABC) Algorithm (website)
#' \url{http://mf.erciyes.edu.tr/abc/index.htm}
#' http://mf.erciyes.edu.tr/abc/index.htm
#'
#' Basic version of the algorithm implemented in \code{C} (ABC's official
#' website) \url{http://mf.erciyes.edu.tr/abc/form.aspx}
#' Basic version of the algorithm implemented in `C` (ABC's official
#' website) http://mf.erciyes.edu.tr/abc/form.aspx
#' @keywords optimization
#' @examples
#'
Expand Down Expand Up @@ -428,7 +428,7 @@ abc_optim <- function(
}

#' @export
#' @param x An object of class \code{abc_answer}.
#' @param x An object of class `abc_answer`.
#' @rdname abc_optim
print.abc_answer <- function(x, ...) {
cat("\n")
Expand Down Expand Up @@ -545,7 +545,7 @@ abc_cpp <- function(

fun <- function(par) fn(par/parscale, ...)/fnscale

ans <- abc_cpp_(par, fun, lb, ub, FoodNumber, limit, maxCycle, criter)
ans <- .abc_cpp(par, fun, lb, ub, FoodNumber, limit, maxCycle, criter)
ans[["fn"]] <- fn

structure(
Expand All @@ -557,18 +557,18 @@ abc_cpp <- function(
}

#' @export
#' @details The \code{plot} method shows the trace of the objective function
#' @details The `plot` method shows the trace of the objective function
#' as the algorithm unfolds. The line is merely the result of the objective
#' function evaluated at each point (row) of the \code{hist} matrix return by
#' \code{abc_optim}/\code{abc_cpp}.
#' function evaluated at each point (row) of the `hist` matrix return by
#' `abc_optim`/`abc_cpp`.
#'
#' For now, the function will return with error if \code{...} was passed to
#' \code{abc_optim}/\code{abc_cpp}, since those argumens are not stored with the
#' For now, the function will return with error if `...` was passed to
#' `abc_optim`/`abc_cpp`, since those argumens are not stored with the
#' result.
#'
#' @rdname abc_optim
#' @param y Ignored
#' @param main,xlab,ylab,type Passed to \code{\link[graphics:plot.default]{plot}}.
#' @param main,xlab,ylab,type Passed to [graphics:plot.default::plot()].
plot.abc_answer <- function(
x,
y = NULL,
Expand Down
11 changes: 5 additions & 6 deletions man/ABCoptim-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/abc_optim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/RcppExports.cpp
Expand Up @@ -5,9 +5,9 @@

using namespace Rcpp;

// abc_cpp_
List abc_cpp_(NumericVector& par, Function& fn, const NumericVector& lb, const NumericVector& ub, int FoodNumber, int limit, int maxCycle, int criter);
RcppExport SEXP _ABCoptim_abc_cpp_(SEXP parSEXP, SEXP fnSEXP, SEXP lbSEXP, SEXP ubSEXP, SEXP FoodNumberSEXP, SEXP limitSEXP, SEXP maxCycleSEXP, SEXP criterSEXP) {
// abc_cpp
List abc_cpp(NumericVector& par, Function& fn, const NumericVector& lb, const NumericVector& ub, int FoodNumber, int limit, int maxCycle, int criter);
RcppExport SEXP _ABCoptim_abc_cpp(SEXP parSEXP, SEXP fnSEXP, SEXP lbSEXP, SEXP ubSEXP, SEXP FoodNumberSEXP, SEXP limitSEXP, SEXP maxCycleSEXP, SEXP criterSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -19,13 +19,13 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< int >::type limit(limitSEXP);
Rcpp::traits::input_parameter< int >::type maxCycle(maxCycleSEXP);
Rcpp::traits::input_parameter< int >::type criter(criterSEXP);
rcpp_result_gen = Rcpp::wrap(abc_cpp_(par, fn, lb, ub, FoodNumber, limit, maxCycle, criter));
rcpp_result_gen = Rcpp::wrap(abc_cpp(par, fn, lb, ub, FoodNumber, limit, maxCycle, criter));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_ABCoptim_abc_cpp_", (DL_FUNC) &_ABCoptim_abc_cpp_, 8},
{"_ABCoptim_abc_cpp", (DL_FUNC) &_ABCoptim_abc_cpp, 8},
{NULL, NULL, 0}
};

Expand Down
4 changes: 2 additions & 2 deletions src/abc.cpp
Expand Up @@ -207,8 +207,8 @@ void SendScoutBees(
return;
}

// [[Rcpp::export]]
List abc_cpp_(
// [[Rcpp::export(name=".abc_cpp")]]
List abc_cpp(
NumericVector & par,
Function & fn,
const NumericVector & lb,
Expand Down

0 comments on commit 3a26879

Please sign in to comment.