-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add methods to calculate nadir and ideal points from a set of points
- Loading branch information
1 parent
4e1c754
commit 5b7714c
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
|