-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
576eac4
commit dec8d98
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
|
||
# philentropy package | ||
# https://search.r-project.org/CRAN/refmans/philentropy/html/00Index.html | ||
|
||
# https://en.wikipedia.org/wiki/Bhattacharyya_distance | ||
|
||
library(philentropy) | ||
|
||
s <- seq(-3, 6, length.out = 100) | ||
x <- dnorm(s, mean = 0, sd = 1) | ||
y <- dnorm(s, mean = 1, sd = 1) | ||
z <- dnorm(s, mean = -0.1, sd = 1) | ||
|
||
plot(s, x, type = 'l', xlim = c(-3, 6)) | ||
lines(s, y, col = 2) | ||
lines(s, z, col = 3) | ||
|
||
# absolute value depends on number of elements in x, y | ||
bhattacharyya(P = x, Q = y, testNA = FALSE, unit = "log2", epsilon = 0.00001) | ||
bhattacharyya(P = x, Q = z, testNA = FALSE, unit = "log2", epsilon = 0.00001) | ||
|
||
|
||
# can we use this to describe meaningful differences between GHL probability density curves? | ||
# what about depth functions? | ||
# what about spectra? | ||
|
||
# TODO: try it out on a couple soil-related things? | ||
library(aqp) | ||
|
||
|
||
data("munsell.spectra.wide") | ||
|
||
|
||
x <- munsell.spectra.wide[, '10YR 3/3'] | ||
y <- munsell.spectra.wide[, '5YR 4/6'] | ||
|
||
# useful? | ||
bhattacharyya(P = x, Q = y, testNA = FALSE, unit = "log2", epsilon = 0.00001) | ||
|
||
|