powered by
This function calculates the Jensen Shannon Divergence for the rows or columns of a numeric matrix or for two numeric vectors.
CalcJSDivergence(x, y = NULL, by_rows = TRUE)
If x is a matrix, this returns an square and symmetric matrix. The i,j entries correspond to the Hellinger Distance between the rows of x
x
(or the columns of x if by_rows = FALSE). If x and y
by_rows = FALSE
y
are vectors, this returns a numeric scalar whose value is the Hellinger Distance between x and y.
A numeric matrix or numeric vector
A numeric vector. y must be specified if x is a numeric vector.
Logical. If x is a matrix, should distances be calculated by rows?
x <- rchisq(n = 100, df = 8) y <- x^2 CalcJSDivergence(x = x, y = y) mymat <- rbind(x, y) CalcJSDivergence(x = mymat)
Run the code above in your browser using DataLab