Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose possible bug in jnd computation for dichromats and fix it #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bisaloo
Copy link
Collaborator

@Bisaloo Bisaloo commented Feb 7, 2025

Bug demo:

library(pavo)

data(flowers)

canis.flowers <- vismodel(flowers, visual = "canis")
cd.flowers <- coldist(canis.flowers, n = c(1, 1))
#> Quantum catch are relative, distances may not be meaningful
#> Calculating noise-weighted Euclidean distances

jnd_x <- jnd2xyz(cd.flowers, rotate = FALSE)

# These two approaches should give the same values
dist_via_jnd <- as.matrix(dist(jnd_x, diag = TRUE, upper = TRUE))
dist_direct <- coldist2mat(cd.flowers)[["dS"]]

all.equal(
  dist_via_jnd,
  dist_direct,
  tolerance = 1e-6
)
#> [1] "Mean relative difference: 0.1121901"

dist_via_jnd[8, ]
#>     Goodenia_heterophylla       Goodenia_geniculata         Goodenia_gracilis 
#>                 4.5170525                 3.9266110                24.8100216 
#>          Xyris_operculata             Eucalyptus_sp        Faradaya_splendida 
#>                 0.6461969                 0.9980937                 4.7972590 
#>        Gaultheria_hispida    Geitonoplesium_cymosum   Euryomyrtus_ramosissima 
#>                 2.2628834                 0.0000000                 1.8853302 
#>         Genista_linifolia     Genista_monspessulana               Geranium_sp 
#>                 2.5420288                 1.0826285                 4.2308624 
#>       Glycine_clandestina  Gompholobium_ecostatum_1  Gompholobium_ecostatum_2 
#>                 1.7986383                 1.8554007                 2.5622591 
#> Gompholobium_grandiflorum     Gompholobium_huegelii     Gompholobium_virgatum 
#>                10.6122520                 1.7876028                 1.9291622 
#>        Gonocarpus_humilis    Gonocarpus_teucrioides     Hibbertia_obtusifolia 
#>                 0.1255897                 0.5628188                 3.0623861 
#>        Zieria_arborescens           Goodenia_lanata            Goodenia_ovata 
#>                 4.4429840                15.6985496                 2.7000931 
#>     Goodenia_rotundifolia       Grevillea_buxifolia   Grevillea_steiglitziana 
#>                 5.8229615                 2.8302123                10.5154479 
#>        Grevillea_oleoides       Gymnostachys_anceps             Hakea_actites 
#>                 1.8528836                19.7127205                 5.1314456 
#>    Hardenbergia_violaceae      Hibbertia_acicularis       Hibbertia_bracteata 
#>                 6.4667959                 0.6395585                 4.8124184 
#>    Hibbertia_empetrifolia      Hibbertia_procumbens        Hibbertia_linearis 
#>                 3.4538905                 0.2026285                 3.8542609
dist_direct[8, ]
#>     Goodenia_heterophylla       Goodenia_geniculata         Goodenia_gracilis 
#>                  4.517052                 12.960716                 33.844127 
#>          Xyris_operculata             Eucalyptus_sp        Faradaya_splendida 
#>                  8.387908                  8.036011                 13.831364 
#>        Gaultheria_hispida    Geitonoplesium_cymosum   Euryomyrtus_ramosissima 
#>                  6.771222                  0.000000                 10.919435 
#>         Genista_linifolia     Genista_monspessulana               Geranium_sp 
#>                 11.576134                 10.116733                  4.803243 
#>       Glycine_clandestina  Gompholobium_ecostatum_1  Gompholobium_ecostatum_2 
#>                 10.832743                  7.178704                 11.596364 
#> Gompholobium_grandiflorum     Gompholobium_huegelii     Gompholobium_virgatum 
#>                 19.646357                  7.246502                  7.104943 
#>        Gonocarpus_humilis    Gonocarpus_teucrioides     Hibbertia_obtusifolia 
#>                  9.159695                  9.596924                 12.096491 
#>        Zieria_arborescens           Goodenia_lanata            Goodenia_ovata 
#>                 13.477089                 24.732655                 11.734198 
#>     Goodenia_rotundifolia       Grevillea_buxifolia   Grevillea_steiglitziana 
#>                  3.211144                  6.203893                 19.549553 
#>        Grevillea_oleoides       Gymnostachys_anceps             Hakea_actites 
#>                 10.886989                 28.746825                  3.902659 
#>    Hardenbergia_violaceae      Hibbertia_acicularis       Hibbertia_bracteata 
#>                 15.500901                  8.394546                  4.221687 
#>    Hibbertia_empetrifolia      Hibbertia_procumbens        Hibbertia_linearis 
#>                 12.487995                  8.831477                 12.888366

Created on 2025-02-07 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant