This functions computes the distance/dissimilarity between one probability density functions and a set of probability density functions.
dist_one_many(
P,
dists,
method,
p = NULL,
testNA = TRUE,
unit = "log",
epsilon = 1e-05,
num_threads = NULL
)A vector of distance values
a numeric vector storing the first distribution.
a numeric matrix storing distributions in its rows.
a character string indicating whether the distance measure that should be computed.
power of the Minkowski distance.
a logical value indicating whether or not distributions shall be checked for NA values.
type of log function. Option are
unit = "log"
unit = "log2"
unit = "log10"
epsilon a small value to address cases in the distance computation where division by zero occurs. In
these cases, x / 0 or 0 / 0 will be replaced by epsilon. The default is epsilon = 0.00001.
However, we recommend to choose a custom epsilon value depending on the size of the input vectors,
the expected similarity between compared probability density functions and
whether or not many 0 values are present within the compared vectors.
As a rough rule of thumb we suggest that when dealing with very large
input vectors which are very similar and contain many 0 values,
the epsilon value should be set even smaller (e.g. epsilon = 0.000000001),
whereas when vector sizes are small or distributions very divergent then
higher epsilon values may also be appropriate (e.g. epsilon = 0.01).
Addressing this epsilon issue is important to avoid cases where distance metrics
return negative values which are not defined and only occur due to the
technical issues of computing x / 0 or 0 / 0 cases.
an integer specifying the number of threads to be used for parallel computations. Default is taken from the `RCPP_PARALLEL_NUM_THREADS` environment variable, or `2` if not set.
set.seed(2020-08-20)
P <- 1:10 / sum(1:10)
M <- t(replicate(100, sample(1:10, size = 10) / 55))
dist_one_many(P, M, method = "euclidean", testNA = FALSE)
Run the code above in your browser using DataLab