Skip to contents

precise_func_fact stands for function factory, thus this function automatically creates distance functions which can be passed to the precise_dist dist_funcs parameter.

Usage

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

Arguments

func

A string of the function to use. Choices include "rbf", "laplace", "minkowski", "random_forest", "kodama", "kodama_knn", "kodama_pls" and "tsne".

params

A numeric vector of values as input into the algorithm determined by the func parameter.

...

Additional named settings for func = "kodama" only: M, Tcycle, metrics, landmarks, n.cores, and seed. The KODAMA seed defaults to 1234; its execution does not alter the caller's random-number state.

Value

A list of typed functions for input into the dist_funcs argument of precise_dist.

Details

While most distance functions have no second argument, some do allowing for multiple views of a dataset tweaked by the second argument of the distance function. The following describes the params argument for each possible func choice:

  • For both RBF and Laplace the params argument refers to the sigma parameter of the rbfdot/laplacedot functions.

  • For minkowski, the params argument refers to it's power.

  • For random_forest, the params argument refers to mtry; the factory returns 1 - proximity as a distance matrix.

  • For kodama, kodama_knn and kodama_pls, the params argument refers to KODAMA::KODAMA.matrix() ncomp. The old kodama_knn/kodama_pls names are retained as aliases; current KODAMA selects the backend automatically.

  • For tsne, the params argument refers to perplexity.

  • See examples below for some reasonable defaults for the params argument for different func parameter choices.

References

Muchmore, B., Muchmore P. and Alarcón-Riquelme ME. (2018). Optimal Distance Matrix Construction with PreciseDist and PreciseGraph.

Author

Brian Muchmore

Examples

test_data <- replicate(10, rnorm(100))

# Estimate sigma for "rbf" and "laplace".
sigma_est <- kernlab::sigest(test_data, frac = 1, na.action = na.omit, scaled = FALSE)

# Build 10 values between the 0.1 and 0.9 sigma estimates.
sigma_params <- seq(sigma_est[[1]], sigma_est[[3]], length.out = 10)

# Use those values as the params for rbf or laplace factories.
rbf_funcs <- precise_func_fact(
  func = "rbf",
  params = sigma_params
)

# Build 10 integer mtry values for random_forest.
rf_params <- round(seq(2, round((ncol(test_data) * 0.5), 0), length.out = 10), 0)

# Use those values as random_forest params.
rf_funcs <- precise_func_fact(
  func = "random_forest",
  params = rf_params
)

# Build 10 Minkowski p values. p = 1 is Manhattan; p = 2 is Euclidean.
minkow_params <- seq(1, 2, length.out = 10)

# Use those values as minkowski params.
minkow_funcs <- precise_func_fact(
  func = "minkowski",
  params = minkow_params
)

# Build 10 perplexity values for tsne.
tsne_params <- seq(5, 50, length.out = 10)

# Use those values as tsne params.
tsne_funcs <- precise_func_fact(
  func = "tsne",
  params = tsne_params
)

# Combine the factories for precise_dist(dist_funcs = ...).

precise_dist_input_funcs <- rbf_funcs %>%
  append(rf_funcs) %>%
  append(minkow_funcs) %>%
  append(tsne_funcs)