Compute fuzzy neighborhood similarity between two categorical rasters
Source:R/fuzzy_similarity.R
calc_fuzzy_similarity.RdCalculates fuzzy similarity indices between two categorical rasters using a moving window approach with optional exponential decay. This allows for spatial tolerance when comparing maps, recognizing that perfect pixel-by-pixel match may be too strict for spatial models.
Usage
calc_fuzzy_similarity(
map1,
map2,
window_size = 11L,
use_exp_decay = TRUE,
decay_divisor = 2,
ignore_na = TRUE
)Arguments
- map1
SpatRaster, first categorical map
- map2
SpatRaster, second categorical map
- window_size
Integer, size of moving window (must be odd). Default 11.
- use_exp_decay
Logical, use exponential decay function? Default TRUE.
- decay_divisor
Numeric, attenuation factor for exponential decay. Default 2.
- ignore_na
Logical, ignore NA values in similarity calculation? Default TRUE.
Value
List with:
sim1: SpatRaster showing similarity from map1 to map2
sim2: SpatRaster showing similarity from map2 to map1
mean_sim1: Mean similarity from map1 to map2
mean_sim2: Mean similarity from map2 to map1
min_similarity: Minimum of the two mean similarities
Details
The fuzzy similarity is based on Hagen (2003) and uses the concept of fuzziness of location. For each cell, a fuzzy neighborhood vector is computed that represents the membership of each category within a specified window, weighted by distance. The similarity between two maps is then computed as the intersection of their fuzzy vectors.
The exponential decay function is: exp(-d / decay_divisor) where d is the Euclidean distance from the center cell.