From cf95eac86bb8697f34b1aa3ce84d3b22483cc8b2 Mon Sep 17 00:00:00 2001 From: Jakob Bossek Date: Sun, 20 Sep 2015 16:19:42 -0500 Subject: [PATCH] add summary function for EMOA results --- NAMESPACE | 1 + R/makeECRResult.R | 28 +++++++++++++---------- man/summary.ecr_multi_objective_result.Rd | 27 ++++++++++++++++++++++ tests/testthat/test_emoa.R | 23 +++++++++++++++++++ 4 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 man/summary.ecr_multi_objective_result.Rd diff --git a/NAMESPACE b/NAMESPACE index 925b437..9355b9d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/makeECRResult.R b/R/makeECRResult.R index e28f251..d34e35b 100644 --- a/R/makeECRResult.R +++ b/R/makeECRResult.R @@ -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") ) } diff --git a/man/summary.ecr_multi_objective_result.Rd b/man/summary.ecr_multi_objective_result.Rd new file mode 100644 index 0000000..4a1f8b6 --- /dev/null +++ b/man/summary.ecr_multi_objective_result.Rd @@ -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. +} + diff --git a/tests/testthat/test_emoa.R b/tests/testthat/test_emoa.R index e3a4f0f..60b6f71 100644 --- a/tests/testthat/test_emoa.R +++ b/tests/testthat/test_emoa.R @@ -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)) +})