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 = NA_real_,
  testNA = TRUE,
  unit = "log",
  epsilon = 1e-05
)

Arguments

P

a numeric vector storing the first distribution.

dists

a numeric matrix storing distributions in its rows.

method

a character string indicating whether the distance measure that should be computed.

p

power of the Minkowski distance.

testNA

a logical value indicating whether or not distributions shall be checked for NA values.

unit

type of log function. Option are

  • unit = "log"

  • unit = "log2"

  • unit = "log10"

epsilon

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.

Value

A vector of distance values

Examples

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)
#>   [1] 0.25324342 0.25324342 0.27212054 0.20409040 0.21203461 0.20082475
#>   [7] 0.26095818 0.29090909 0.18362736 0.20082475 0.14083576 0.26347958
#>  [13] 0.25193466 0.19582417 0.20889319 0.21046976 0.20730462 0.17439387
#>  [19] 0.15212000 0.25712974 0.22998383 0.21818182 0.27812834 0.22416051
#>  [25] 0.27693720 0.26597707 0.27090299 0.28284271 0.23141676 0.26721706
#>  [31] 0.27574093 0.19917184 0.22268089 0.22416051 0.25968831 0.18895100
#>  [37] 0.22854191 0.21203461 0.21513017 0.25712974 0.25712974 0.14083576
#>  [43] 0.26222191 0.24663018 0.21818182 0.27574093 0.26222191 0.24663018
#>  [49] 0.22563043 0.23845231 0.19917184 0.25193466 0.21358800 0.21513017
#>  [55] 0.25324342 0.17814471 0.14993111 0.26095818 0.22998383 0.21818182
#>  [61] 0.19412870 0.23141676 0.24663018 0.21818182 0.23566330 0.21358800
#>  [67] 0.29653648 0.21513017 0.18895100 0.23425634 0.25454545 0.23983465
#>  [73] 0.22998383 0.26967994 0.07272727 0.19917184 0.23706191 0.27212054
#>  [79] 0.24120908 0.19750510 0.27931439 0.19412870 0.28747979 0.28167152
#>  [85] 0.19582417 0.19750510 0.17248787 0.29317301 0.26347958 0.28632756
#>  [91] 0.20246416 0.25061907 0.26347958 0.23706191 0.27333266 0.27812834
#>  [97] 0.16057747 0.28977050 0.23425634 0.21969174