Skip to contents

Returns a named list of measure functions differing only in one backend parameter, for the dist_funcs argument of precise_dist(). Each function carries the type its backend produces, so the resulting rows are typed rather than NA.

Usage

precise_func_fact(func = "rbf", params, ...)

Arguments

func

One of "rbf", "laplace", "minkowski", "random_forest", "kodama", "kodama_knn", "kodama_pls", or "tsne".

params

A numeric vector of parameter values, one function per value.

...

Additional named settings, accepted only by the KODAMA factories.

Value

A named list of functions to pass to the dist_funcs argument of precise_dist().

Parameter mapping by factory

  • rbf and laplace build kernlab kernels, and params is the sigma of kernlab::rbfdot() or kernlab::laplacedot(). Both return an affinity.

  • minkowski calls proxy::dist(), and params is the power. It returns a distance.

  • random_forest calls randomForest with ntree = 1501, nodesize = 1, and oob.prox = FALSE, and params is mtry. It returns 1 - proximity as a distance with a zero diagonal.

  • kodama calls KODAMA::KODAMA.matrix(), and params is ncomp. It returns a distance and requires the optional KODAMA package. kodama_knn and kodama_pls are accepted names for the same factory.

  • tsne runs mmtsne::x2p() at each params value as the perplexity and passes the result to mmtsne::p2sp(). It returns an affinity, which has no automatic distance conversion.

Each element is named <func>_<param>, and those names become the display keys of the precise_dist() result.

KODAMA control arguments

... is accepted only by the KODAMA factories, which pass M, Tcycle, metrics, landmarks, n.cores, and seed to the backend. Any other name is an error. metrics accepts "euclidean" or "manhattan", and seed defaults to 1234. The adapter suppresses the backend's progress output and restores the session random-number state on exit.

References

Karatzoglou A, Smola A, Hornik K, Zeileis A (2004). kernlab: an S4 package for kernel methods in R. Journal of Statistical Software, 11(9), 1–20. doi:10.18637/jss.v011.i09 .

Liaw A, Wiener M (2002). Classification and regression by randomForest. R News, 2(3), 18–22.

Cacciatore S, Luchinat C, Tenori L (2014). Knowledge discovery by accuracy maximization. Proceedings of the National Academy of Sciences, 111(14), 5117–5122. doi:10.1073/pnas.1220873111 .

See also

precise_dist() to run the family, and precise_dist_list() for the measures that are already registered.

Author

Brian Muchmore

Examples

data(data_cell_cycle, package = "PreciseDist")

cells <- c(1:4, 60:63, 118:121)
cell_cycle <- as.matrix(data_cell_cycle[cells, 2:41])
rownames(cell_cycle) <- paste0(data_cell_cycle$Cell_cycle[cells], "_", cells)

minkowski_family <- precise_func_fact(
  func = "minkowski",
  params = c(0.5, 0.75, 1, 1.5)
)
names(minkowski_family)
#> [1] "minkowski_0.5"  "minkowski_0.75" "minkowski_1"    "minkowski_1.5" 

# Factory names become the display keys, and the rows are typed.
swept <- precise_dist(
  cell_cycle,
  dist_funcs = minkowski_family,
  verbose = FALSE
)
swept[, c("distance", "metric", "type")]
#> # A tibble: 4 × 3
#>   distance       metric type    
#>   <chr>          <chr>  <chr>   
#> 1 minkowski_0.5  NA     distance
#> 2 minkowski_0.75 NA     distance
#> 3 minkowski_1    NA     distance
#> 4 minkowski_1.5  NA     distance