Skip to content

Commit

Permalink
add summary function for EMOA results
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbossek committed Sep 20, 2015
1 parent 0912652 commit cf95eac
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ S3method(print,ecr_recombinator)
S3method(print,ecr_result)
S3method(print,ecr_selector)
S3method(print,ecr_single_objective_result)
S3method(summary,ecr_multi_objective_result)
export(approximateIdealPoint)
export(approximateNadirPoint)
export(asemoa)
Expand Down
28 changes: 16 additions & 12 deletions R/makeECRResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,30 @@ print.ecr_multi_objective_result = function(x, ...) {
printAdditionalInformation(x)
}

# @title
# Summary function for multi objective ecr result.
#
# @param object [\code{ecr_multi_objective_result}]\cr
# Result object.
# @param ref.points [\code{matrix}]\cr
# Matrix of reference points (one point per column) used for the emoa quality
# indicators, i.e., epsilon indicator and hypervolume indicator.
# @return [\code{ecr_multi_objective_result_summary}]
# @export
#FIXME: finish and export
#' @title
#' Summary function for multi objective ecr result.
#'
#' @param object [\code{ecr_multi_objective_result}]\cr
#' Result object.
#' @param ref.points [\code{matrix}]\cr
#' Matrix of reference points (one point per column) used for the emoa quality
#' indicators, i.e., epsilon indicator and hypervolume indicator.
#' @param ... [any]\cr
#' Furhter parameters passed to R\{1,2,3\} computation functions. See e.g.
#' \code{\link{computeR1Indicator}} for details.
#' @return [\code{ecr_multi_objective_result_summary}]
#' @export
summary.ecr_multi_objective_result = function(object, ref.points = NULL, ...) {
# convert the data frame to matrix
pf = t(object$pareto.front)
#FIXME: maybe add the possibility to pass ref point to control and use it here?
makeS3Obj(
n.nondom = ncol(pf),
dom.hv = computeDominatedHypervolume(pf),
eps.ind = if (!is.null(ref.points)) computeEpsilonIndicator(pf, ref.points) else NA,
hv.ind = if (!is.null(ref.points)) computeHypervolumeIndicator(pf, ref.points) else NA,
r1.ind = if (!is.null(ref.points)) computeR1Indicator(pf, ref.points, ...) else NA,
r2.ind = if (!is.null(ref.points)) computeR2Indicator(pf, ref.points, ...) else NA,
r3.ind = if (!is.null(ref.points)) computeR3Indicator(pf, ref.points, ...) else NA,
classes = c("list", "ecr_multi_objective_result_summary")
)
}
Expand Down
27 changes: 27 additions & 0 deletions man/summary.ecr_multi_objective_result.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/makeECRResult.R
\name{summary.ecr_multi_objective_result}
\alias{summary.ecr_multi_objective_result}
\title{Summary function for multi objective ecr result.}
\usage{
\method{summary}{ecr_multi_objective_result}(object, ref.points = NULL, ...)
}
\arguments{
\item{object}{[\code{ecr_multi_objective_result}]\cr
Result object.}

\item{ref.points}{[\code{matrix}]\cr
Matrix of reference points (one point per column) used for the emoa quality
indicators, i.e., epsilon indicator and hypervolume indicator.}

\item{...}{[any]\cr
Furhter parameters passed to R\{1,2,3\} computation functions. See e.g.
\code{\link{computeR1Indicator}} for details.}
}
\value{
[\code{ecr_multi_objective_result_summary}]
}
\description{
Summary function for multi objective ecr result.
}

23 changes: 23 additions & 0 deletions tests/testthat/test_emoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,26 @@ test_that("preimplemented EMOAs work well", {
list(n.pop = n.pop, n.archive = 5L))
}
})

test_that("Summary function for EMOA result works", {
# Check multiple parents support
zdt1 = smoof::makeZDT1Function(dimensions = 2L)
# test NSGA-II
res = nsga2(
task = makeOptimizationTask(zdt1),
n.population = 30L,
n.offspring = 10L,
max.evals = 200L
)

xx = summary(res)
expect_class(xx, c("list", "ecr_multi_objective_result_summary"))
expect_true(is.integer(xx$n.nondom))
expect_true(is.numeric(xx$dom.hv) && xx$dom.hv >= 0)

# since we did not pass any any reference points, all the other indicators are NA
expect_true(all(is.na(xx[which(names(xx) %nin% c("n.nondom", "dom.hv"))])))

xx = summary(res, ref.points = t(res$pareto.front))
expect_true(all(xx >= 0))
})

0 comments on commit cf95eac

Please sign in to comment.