I need to calculate the Bhattacharyya distance (or better said the Bhatt. separability index) for unburned and burned area samples extracted from both prefire and postfire MODIS surface reflectance products.
I haven't found any foss "tool" that will do this for me. So I am trying to code it in R. #================================================== # Calculate bhattacharayya distance in R # define new function dBh <- function(PRE, POST){ # column-wise mean and cov for PRE m.pre <- colMeans(PRE) c.pre <- cov(PRE) # column-wise mean and cov for POST m.post <- colMeans(POST) c.post <- cov(POST) # mean difference and its transpose matrix m.diff <- as.matrix(m.pre - m.post) m.diff.t <- t(m.diff) # halfsum of covariances C <- (c.pre + c.post)/2 # the index index <- 0.125 * m.diff.t %*% C %*% m.diff + 0.5 * log10( det(C)/sqrt( det(c.pre)*det(c.post))) # print result index } #=================================================== I am trying to use the code on two matrices with the following structure: # rows are the total number of pixels sampled # columns correspond to MODIS bands 1, 2, 5, 6 and 7 > str(pre.bs6) int [1:371, 1:5] 986 986 1086 1094 1094 1217 1217 1258 1391 1475 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:5] "prefire.band1" "prefire.band2" "prefire.band5" "prefire.band6" ... > str(post.bs6) int [1:371, 1:5] 1007 1175 1007 1039 1146 1077 1078 1280 1249 1218 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:5] "postfire.band1" "postfire.band2" "postfire.band5" "postfire.band6" ... My problem is that (a) I have coded it falsely or (b) I don't understand "how to use the result given that the above instructions are correct. The result is *too* big, thus it will probably ground the Bhattacharayya coefficient to 0. I expect that prefire samples against postfire samples [ given the very good (or good) discrimination ability of those two "classes" in MODIS bands 2, 5, (6 and 7) ] will return some "great" Bhattacharayya coefficient. Or am I wrong? Any instructions on how to get it done? Thanks, Nikos --- [1] http://en.wikipedia.org/wiki/Bhattacharyya_coefficient [2] http://en.wikipedia.org/wiki/Bhattacharya_coefficient _______________________________________________ grass-stats mailing list grass-stats@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-stats