Skip to content

Commit

Permalink
export makeAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-r committed Jan 10, 2014
1 parent 71c716c commit 9ccc8a4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
28 changes: 28 additions & 0 deletions R/Aggregation.R
Expand Up @@ -12,9 +12,37 @@
#' \item{fun [\code{function(task, perf.test, perf.train, measure, group, pred)}]}{Aggregation function.}
#' }
#' @name Aggregation
#' @seealso \code{\link{makeAggregation}}
#' @rdname Aggregation
NULL


#' @title Specifiy your own aggregation of measures
#'
#' @description
#' This is an adavanced feature of mlr. It gives access to some
#' inner workings so the result might not be compatible with everything! \cr
#'
#'
#' @param id [\code{character(1)}]\cr
#' Name of the aggregation method. (Preferably the same name as the generated function)
#' @param fun [\code{function}]\cr
#' A function with following signature: \code{function(task, perf.test, perf.train, measure, group, pred)}
#' \itemize{
#' \item{\bold{task}}: task (\code{\link{SupervisedTask}}) object
#' \item{\bold{perf.test}}: numerical vector of \link{performance} results on the test data set
#' \item{\bold{perf.train}}. numerical vector of \link{performance} results on the train data set
#' \item{\bold{measure}}: \code{\link{Measure}} object.
#' \item{\bold{group}}: grouping vector
#' \item{\bold{pred}}: \code{\link{Prediction}} object
#' }
#' @seealso \link{aggregations}, \code{\link{setAggregation}}
#' @return \link{Aggregation} object
#' @examples
#' # computes the interquartile range on all performance values
#' test.iqr = makeAggregation(id="test.iqr",
#' fun = function (task, perf.test, perf.train, measure, group, pred) IQR(perf.test))
#' @export
makeAggregation = function(id, fun) {
checkArg(id, "character", len=1L, na.ok=FALSE)
structure(list(id=id, fun=fun), class="Aggregation")
Expand Down
21 changes: 21 additions & 0 deletions R/aggregations.R
Expand Up @@ -66,6 +66,13 @@ test.sum = makeAggregation(
fun = function(task, perf.test, perf.train, measure, group, pred) sum(perf.test)
)

#' @export
#' @rdname aggregations
test.range = makeAggregation(
id = "test.range",
fun = function(task, perf.test, perf.train, measure, group, pred) diff(range(perf.test))
)

#' @export
#' @rdname aggregations
test.sqrt.of.mean = makeAggregation(
Expand Down Expand Up @@ -115,6 +122,20 @@ train.sum = makeAggregation(
fun = function(task, perf.test, perf.train, measure, group, pred) sum(perf.train)
)

#' @export
#' @rdname aggregations
train.range = makeAggregation(
id = "train.range",
fun = function(task, perf.test, perf.train, measure, group, pred) diff(range(perf.train))
)

#' @export
#' @rdname aggregations
train.sqrt.of.mean = makeAggregation(
id = "train.sqrt.of.mean",
fun = function(task, perf.test, perf.train, measure, group, pred) sqrt(mean(perf.train))
)

#' @export
#' @rdname aggregations
b632 = makeAggregation(
Expand Down
40 changes: 40 additions & 0 deletions man/makeAggregation.Rd
@@ -0,0 +1,40 @@
\name{makeAggregation}
\alias{makeAggregation}
\title{Specifiy your own aggregation of measures}
\usage{
makeAggregation(id, fun)
}
\arguments{
\item{id}{[\code{character(1)}]\cr Name of the
aggregation method. (Preferably the same name as the
generated function)}

\item{fun}{[\code{function}]\cr A function with following
signature: \code{function(task, perf.test, perf.train,
measure, group, pred)} \itemize{ \item{\bold{task}}: task
(\code{\link{SupervisedTask}}) object
\item{\bold{perf.test}}: numerical vector of
\link{performance} results on the test data set
\item{\bold{perf.train}}. numerical vector of
\link{performance} results on the train data set
\item{\bold{measure}}: \code{\link{Measure}} object.
\item{\bold{group}}: grouping vector \item{\bold{pred}}:
\code{\link{Prediction}} object }}
}
\value{
\link{Aggregation} object
}
\description{
This is an adavanced feature of mlr. It gives access to
some inner workings so the result might not be compatible
with everything! \cr
}
\examples{
# computes the interquartile range on all performance values
test.iqr = makeAggregation(id="test.iqr",
fun = function (task, perf.test, perf.train, measure, group, pred) IQR(perf.test))
}
\seealso{
\link{aggregations}, \code{\link{setAggregation}}
}

0 comments on commit 9ccc8a4

Please sign in to comment.