Skip to content

Commit

Permalink
add methods to calculate nadir and ideal points from a set of points
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbossek committed Jun 15, 2015
1 parent 4e1c754 commit 5b7714c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ S3method(getSupportedRepresentations,ecr_operator)
S3method(is.supported,ecr_operator)
S3method(print,ecr_control)
S3method(print,ecr_result)
export(approximateIdealPoint)
export(approximateNadirPoint)
export(computeAverageHausdorffDistance)
export(computeCrowdingDistance)
export(computeDominatedHypervolume)
Expand Down
70 changes: 70 additions & 0 deletions R/approximatePoints.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#' Reference point approximations.
#'
#' Helper functions to compute nadir or ideal point from sets of points, e.g.,
#' multiple approxiamtion sets.
#'
#' @param ... [any]\cr
#' Sets as matrizes.
#' @param sets [\code{list}]\cr
#' List of sets. This is an alternative way of passing the sets. Can be used
#' exclusively or combined with \code{...}.
#' @return [numeric] Reference point.
#' @export
#' @rdname reference_point_approximation
approximateNadirPoint = function(..., sets = NULL) {
return(approximatePoint(..., sets = sets, FUN = max))
}

#' @export
#' @rdname reference_point_approximation
approximateIdealPoint = function(..., sets = NULL) {
return(approximatePoint(..., sets = sets, FUN = min))
}

# Helper to compute the Nadir point.
#
# The nadir point is constructed by the worst objective values of the
# concatenation of all given point sets.
#
# @param ... [any]\cr
# Sets as matrizes.
# @param sets [\code{list}]\cr
# List of sets. This is an alternative way of passing the sets. Can be used
# exclusively or combined with \code{...}.
# @param FUN [\code{function}]\cr
# Either min or max function.
# @return [numeric]
approximatePoint = function(..., sets = NULL, FUN) {
assertFunction(FUN)

# we can combine both types of parameter passing here
sets2 = list(...)
if (!is.null(sets)) {
assertList(sets, types = "matrix")
}
sets = c(sets, sets2)
assertListOfPointSets(sets)

# sapply returns a matrix with each row corresponding to the nadir point
# of a single set. We hence apply the FUN rowwise again.
point = apply(sapply(sets2, function(set) {
apply(set, 1L, FUN)
}), 1L, FUN)

return(point)
}


# Helper function to check if all given sets have the same dimension, i.e.,
# number of objectives.
#
# @param x [list]
# List of sets, i.e., matrizes.
# @return Nothing
assertListOfPointSets = function(x) {
assertList(x, types = "matrix")
n.rows = sapply(x, nrow)
if (length(unique(n.rows)) > 1L) {
stopf("All sets need to be of the same dimension.")
}
}
27 changes: 27 additions & 0 deletions man/reference_point_approximation.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/approximatePoints.R
\name{approximateNadirPoint}
\alias{approximateIdealPoint}
\alias{approximateNadirPoint}
\title{Reference point approximations.}
\usage{
approximateNadirPoint(..., sets = NULL)

approximateIdealPoint(..., sets = NULL)
}
\arguments{
\item{...}{[any]\cr
Sets as matrizes.}

\item{sets}{[\code{list}]\cr
List of sets. This is an alternative way of passing the sets. Can be used
exclusively or combined with \code{...}.}
}
\value{
[numeric] Reference point.
}
\description{
Helper functions to compute nadir or ideal point from sets of points, e.g.,
multiple approxiamtion sets.
}

0 comments on commit 5b7714c

Please sign in to comment.