seriation (version 1.3.2)

criterion_methods: Registry for Criterion Methods

Description

A registry to manage methods to calculate a criterion value given data and a permutation.

Usage

list_criterion_methods(kind)
get_criterion_method(kind, name)
set_criterion_method(kind, name, fun, description = NULL, merit = NA, ...)

## deprecated show_criterion_methods(kind)

Arguments

kind

the data type the method works on. For example, "dist", "matrix" or "array".

name

a short name for the method used to refer to the method in the function criterion().

fun

a function containing the method's code.

description

a description of the method. For example, a long name.

merit

a boolean indicating if the criterion measure is a merit (TRUE) or a loss (FALSE) measure.

...

further information that is stored for the method in the registry.

Details

All methods below are convenience methods for the registry named registry_criterion.

list_criterion_method() lists all available methods for a given data type (kind). The result is a vector of character strings with the short names of the methods. If kind is missing, then a list of methods is returned.

get_criterion_method() returns information (including the implementing function) about a given method in form of an object of class "criterion_method".

With set_criterion_method() new criterion methods can be added by the user. The implementing function (fun) needs to have the formal arguments x, order, ..., where x is the data object, order is an object of class permutation_vector and ... can contain additional information for the method passed on from criterion(). The implementation has to return the criterion value as a scalar.

Examples

Run this code
# NOT RUN {
## the registry
registry_criterion

# List all criterion calculation methods by type
list_criterion_methods()

# List methods for matrix
list_criterion_methods("matrix")

get_criterion_method("dist", "AR_d")

# Define a new method (sum of the diagonal elements)

## 1. implement a function to calculate the measure
criterion_method_matrix_foo <- function(x, order, ...) {
if(!is.null(order)) x <- permute(x,order)
    sum(diag(x))
}

## 2. Register new method
set_criterion_method("matrix", "DiagSum", criterion_method_matrix_foo,
    description = "Calculated the sum of all diagonal entries", merit = FALSE)

list_criterion_methods("matrix")
get_criterion_method("matrix", "DiagSum")

## 3. use all criterion methods (including the new one)
criterion(matrix(1:9, ncol = 3))
# }

Run the code above in your browser using DataLab