Skip to content

Commit

Permalink
Expose missing methods defaultMethod and valueOf0 (#118)
Browse files Browse the repository at this point in the history
* fix: expose defaultMethod and valueof0

* bump version

* update codemeta

* re-knit README

* add news entry

* add PR number

* fix: typo
  • Loading branch information
hsloot committed Apr 18, 2024
1 parent 41ca6a2 commit 801723b
Show file tree
Hide file tree
Showing 33 changed files with 338 additions and 44 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rmo
Title: A package for the Marshall-Olkin distribution
Version: 0.8.7
Version: 0.8.8
Authors@R:
person(given = "Henrik",
family = "Sloot",
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(ParetoBernsteinFunction)
export(PoissonBernsteinFunction)
export(ScaledBernsteinFunction)
export(SumOfBernsteinFunctions)
export(defaultMethod)
export(exIntensities)
export(exQMatrix)
export(intensities)
Expand All @@ -23,9 +24,11 @@ export(rpextmo)
export(stieltjesDensity)
export(uexIntensities)
export(valueOf)
export(valueOf0)
exportClasses(BernsteinFunction)
exportClasses(CompleteBernsteinFunction)
exportClasses(LevyBernsteinFunction)
exportMethods(defaultMethod)
exportMethods(exIntensities)
exportMethods(exQMatrix)
exportMethods(intensities)
Expand All @@ -34,6 +37,7 @@ exportMethods(show)
exportMethods(stieltjesDensity)
exportMethods(uexIntensities)
exportMethods(valueOf)
exportMethods(valueOf0)
importFrom(Rcpp,sourceCpp)
importFrom(Rdpack,reprompt)
importFrom(checkmate,assert)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rmo 0.9

- Improve extensibility by exposing `defaultMethod` and `valueOf0` (#118)

- Review and improve documentation (#116)

- Re-organize S4 code and documentation (#117)
Expand Down
6 changes: 5 additions & 1 deletion R/s4-AlphaStableBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ setMethod(
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @importFrom checkmate assert qassert check_numeric check_complex
#' @keywords internal
#' @export
setMethod(
"valueOf0", "AlphaStableBernsteinFunction",
function(object, x, cscale = 1, ...) {
Expand Down
14 changes: 0 additions & 14 deletions R/s4-BernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,6 @@ setClass("BernsteinFunction", # nolint
#' @docType methods
NULL


#' @include s4-valueOf0.R s4-valueOf.R
#' @importFrom methods setMethod
#' @keywords internal
setMethod(
"valueOf0", "BernsteinFunction",
function(object, x, cscale = 1, ...) {
valueOf(
object, x,
difference_order = 0L, n = 1L, k = 0L, cscale = cscale, ...
)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams uexIntensities
Expand Down
13 changes: 13 additions & 0 deletions R/s4-CompositeScaledBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ setMethod( # nocov start
}
) # nocov end

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @export
setMethod(
"valueOf0", "CompositeScaledBernsteinFunction",
function(object, x, cscale = 1, ...) {
valueOf(object, x, cscale = cscale)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf
Expand Down
13 changes: 13 additions & 0 deletions R/s4-ConstantBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ setMethod( # nocov start
}
) # nocov end

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @export
setMethod(
"valueOf0", "ConstantBernsteinFunction",
function(object, x, cscale = 1, ...) {
valueOf(object, x, cscale = cscale)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf
Expand Down
13 changes: 13 additions & 0 deletions R/s4-ConvexCombinationOfBernsteinFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ setMethod( # nocov start
}
) # nocov end

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @export
setMethod(
"valueOf0", "ConvexCombinationOfBernsteinFunctions",
function(object, x, cscale = 1, ...) {
valueOf(object, x, cscale = cscale)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf
Expand Down
12 changes: 10 additions & 2 deletions R/s4-ExponentialBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,25 @@ setMethod(
}
)

#' @keywords internal
#' @rdname hidden_aliases
#'
#' @inheritParams defaultMethod
#'
#' @export
setMethod(
"defaultMethod", "ExponentialBernsteinFunction",
function(object) {
"stieltjes"
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @importFrom checkmate assert qassert check_numeric check_complex
#' @keywords internal
#' @export
setMethod(
"valueOf0", "ExponentialBernsteinFunction",
function(object, x, cscale = 1, ...) {
Expand Down
6 changes: 5 additions & 1 deletion R/s4-GammaBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,13 @@ setMethod(
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @importFrom checkmate assert qassert check_numeric check_complex
#' @keywords internal
#' @export
setMethod(
"valueOf0", "GammaBernsteinFunction",
function(object, x, cscale = 1, ...) {
Expand Down
6 changes: 5 additions & 1 deletion R/s4-InverseGaussianBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ setMethod(
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @importFrom checkmate assert qassert check_numeric check_complex
#' @keywords internal
#' @export
setMethod(
"valueOf0", "InverseGaussianBernsteinFunction",
function(object, x, cscale = 1, ...) {
Expand Down
14 changes: 11 additions & 3 deletions R/s4-LevyBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ setClass("LevyBernsteinFunction",
contains = c("BernsteinFunction", "VIRTUAL")
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-defaultMethod.R
#' @keywords internal
#' @export
setMethod(
"defaultMethod", "LevyBernsteinFunction",
function(object) {
Expand Down Expand Up @@ -173,9 +177,13 @@ setMethod(
}
)

#' @include s4-valueOf0.R s4-valueOf.R
#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R s4-valueOf.R s4-defaultMethod.R
#' @importFrom methods setMethod
#' @keywords internal
#' @export
setMethod(
"valueOf0", "LevyBernsteinFunction",
function(object, x, cscale = 1, method = defaultMethod(object), ...) {
Expand Down
13 changes: 13 additions & 0 deletions R/s4-LinearBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ setMethod( # nocov start
}
) # nocov end

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @export
setMethod(
"valueOf0", "LinearBernsteinFunction",
function(object, x, cscale = 1, ...) {
valueOf(object, x, cscale = cscale)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf
Expand Down
6 changes: 5 additions & 1 deletion R/s4-ParetoBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ setMethod(
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @importFrom checkmate assert qassert check_numeric check_complex
#' @importFrom stats pgamma
#' @keywords internal
#' @export
setMethod(
"valueOf0", "ParetoBernsteinFunction",
function(object, x, cscale = 1, ...) {
Expand Down
6 changes: 5 additions & 1 deletion R/s4-PoissonBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ setMethod(
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @importFrom checkmate assert qassert check_numeric check_complex
#' @keywords internal
#' @export
setMethod(
"valueOf0", "PoissonBernsteinFunction",
function(object, x, cscale = 1, ...) {
Expand Down
13 changes: 13 additions & 0 deletions R/s4-ScaledBernsteinFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ setMethod( # nocov start
}
) # nocov end

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @export
setMethod(
"valueOf0", "ScaledBernsteinFunction",
function(object, x, cscale = 1, ...) {
valueOf(object, x, cscale = cscale)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf
Expand Down
13 changes: 13 additions & 0 deletions R/s4-SumOfBernsteinFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ setMethod( # nocov start
}
) # nocov end

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf0
#'
#' @include s4-valueOf0.R
#' @export
setMethod(
"valueOf0", "SumOfBernsteinFunctions",
function(object, x, cscale = 1, ...) {
valueOf(object, x, cscale = cscale)
}
)

#' @rdname hidden_aliases
#'
#' @inheritParams valueOf
Expand Down
18 changes: 17 additions & 1 deletion R/s4-defaultMethod.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#' Default method for approximating Bernstein function differences
#'
#' @description
#' Evaluating Bernstein function differences is usually not numerically stable.
#' Consequently, various alternative approaches are used dependent on the class
#' of the Bernstein function. This method returns a String indicating the
#' default method used for the approximation.
#'
#' @param object An object deriving from the class [BernsteinFunction-class].
#'
#' @return
#' A String indicating the default method used for the approximation.
#'
#' @family Bernstein function generics
#' @importFrom methods setGeneric
#' @keywords internal
#' @export
#' @examples
#' defaultMethod(AlphaStableBernsteinFunction(alpha = 0.7))
setGeneric(
"defaultMethod",
function(object) {
Expand Down
7 changes: 2 additions & 5 deletions R/s4-valueOf.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Evaluate Bernstein Functions
#' Evaluate Bernstein Function differences
#'
#' Calculate the values for a Bernstein function and its higher-order,
#' alternating iterated forward differences, possibly scaled by a binomial
Expand All @@ -11,12 +11,9 @@
#' numerically stable. Consequently, the various alternative approaches are used
#' dependent on the class of the Bernstein function.
#'
#' @param object An object deriving from the class [BernsteinFunction-class].
#' @param x A nonnegativ numeric vector at which the iterated difference of
#' the Bernstein function is evaluated.
#' @inheritParams valueOf0
#' @param difference_order A nonnegative integer with the order of the
#' alternating iterated forward differences taken on the Bernstein function.
#' @param cscale A positive number for the *composite scaling factor*.
#' @param n,k Nonnegative numbers for the binomial factor.
#' @param ... Pass-through parameter.
#'
Expand Down
17 changes: 16 additions & 1 deletion R/s4-valueOf0.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#' Evaluate Bernstein functions
#'
#' @description
#' Calculate the values for a Bernstein function function.
#'
#' @param object An object deriving from the class [BernsteinFunction-class].
#' @param x A nonnegativ numeric vector at which the iterated difference of
#' the Bernstein function is evaluated.
#' @param cscale A positive number for the *composite scaling factor*.
#' @param ... Pass-through parameter.
#'
#' @family Bernstein function generics
#' @importFrom methods setGeneric
#' @keywords internal
#' @export
#' @examples
#' bf <- AlphaStableBernsteinFunction(alpha = 0.7)
#' valueOf0(bf, 1:5)
setGeneric(
"valueOf0",
function(object, x, cscale = 1, ...) {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

![minimal R
version](https://img.shields.io/badge/R%3E%3D-3.4.0-6666ff.svg)
![packageversion](https://img.shields.io/badge/Package%20version-0.8.3-orange.svg?style=flat-square)
![packageversion](https://img.shields.io/badge/Package%20version-0.8.8-orange.svg?style=flat-square)
[![Project Status: WIP – Initial development is in progress, but there
has not yet been a stable, usable release suitable for the
public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--04--02-yellowgreen.svg)](/commits/master)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--04--17-yellowgreen.svg)](/commits/master)
[![R build
status](https://github.com/hsloot/rmo/workflows/check-full/badge.svg)](https://github.com/hsloot/rmo/actions)
[![Codecov test
Expand Down

0 comments on commit 801723b

Please sign in to comment.