-
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.
- Loading branch information
1 parent
028a704
commit 8e41b03
Showing
6 changed files
with
70 additions
and
2 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,27 @@ | ||
#' Generator for some frequently used stopping conditions. | ||
#' | ||
#' Setting up stopping conditions is flexible and straight-forward, but | ||
#' it needs a lot of writing. This function generates a list of frequently | ||
#' used stopping conditions with just a single function call. | ||
#' | ||
#' @param max.iter [\code{integer(1)}]\cr | ||
#' Maximal number of iterations. Default ist \code{Inf}. | ||
#' @param max.time [\code{integer(1)}]\cr | ||
#' Time budget in seconds. Default ist \code{Inf}. | ||
#' @return [list] | ||
#' List of \code{ecr_stoppingCondition} objects, which can be passed to \code{ecr}. | ||
#' @export | ||
#FIXME: this is not very flexible. What if we add new stopping conditions. In | ||
# this case we have to change this function every time. | ||
# The stopping condition generators should have attributes 'checkFunction' and | ||
# default value (see ecr operators). This way setupStoppingCondition could | ||
# iterate over all available stopping conditions. | ||
setupStoppingConditions = function(max.iter = Inf, max.time = Inf) { | ||
if (is.infinite(max.iter) && is.infinite(max.time)) { | ||
stopf("At least max.iter or max.time must be finite.") | ||
} | ||
list( | ||
makeMaximumIterationsStoppingCondition(max.iter), | ||
makeMaximumTimeStoppingCondition(max.time) | ||
) | ||
} |
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
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,25 @@ | ||
% Generated by roxygen2 (4.1.0): do not edit by hand | ||
% Please edit documentation in R/setupStoppingConditions.R | ||
\name{setupStoppingConditions} | ||
\alias{setupStoppingConditions} | ||
\title{Generator for some frequently used stopping conditions.} | ||
\usage{ | ||
setupStoppingConditions(max.iter = Inf, max.time = Inf) | ||
} | ||
\arguments{ | ||
\item{max.iter}{[\code{integer(1)}]\cr | ||
Maximal number of iterations. Default ist \code{Inf}.} | ||
|
||
\item{max.time}{[\code{integer(1)}]\cr | ||
Time budget in seconds. Default ist \code{Inf}.} | ||
} | ||
\value{ | ||
[list] | ||
List of \code{ecr_stoppingCondition} objects, which can be passed to \code{ecr}. | ||
} | ||
\description{ | ||
Setting up stopping conditions is flexible and straight-forward, but | ||
it needs a lot of writing. This function generates a list of frequently | ||
used stopping conditions with just a single function call. | ||
} | ||
|
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,15 @@ | ||
context("generator for list of stopping conditions") | ||
|
||
test_that("generator for list of stopping conditions works well", { | ||
# at least on of {max.time, max.iter} must be finite | ||
expect_error(setupStoppingConditions()) | ||
|
||
scs = setupStoppingConditions(100L, 1e6) | ||
expect_is(scs, "list") | ||
expect_equal(length(scs), 2L) | ||
lapply(scs, function(sc) { | ||
expect_is(sc, "ecr_stoppingCondition") | ||
}) | ||
|
||
}) | ||
|