hyunjimoon / SBC

https://hyunjimoon.github.io/SBC
Other
47 stars 3 forks source link

quantile metric #7

Open hyunjimoon opened 3 years ago

hyunjimoon commented 3 years ago

Wholistic measure on quantile, a summary statistics for ecdf needeed.

hyunjimoon commented 2 years ago

Comparing Cumulative Jensen-Shannon divergence with original wasserstein and max_diff. The following shows the outputs are different:

> bin_count = c(1,2,3,4,4,3,2,1)
> wasserstein(bin_count)
[1] 0.3297305
> x <- c(1,2,3,4,4,3,2,1)
> y <- rep(1/length(x), length(x))
> y
[1] 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
> cjs_dist(x, y,rep(1/length(x), length(x)), rep(1/length(y), length(y)))
      cjs 
0.4414096 

code for wasserstein was:

wasserstein <- function(bin_count){ #x, y,
  bins <- length(bin_count)
  unif <- rep(1/bins, bins)
  M <- sum(bin_count)
  tempf <- Vectorize(function(i)  abs(bin_count[i]/M  - unif[i]))
  val <- integrate(tempf,1,bins, rel.tol=.Machine$double.eps^.05)$value
  return(val)
}