Skip to content

Commit

Permalink
Merge pull request #1 from computational-psychology/dev_metrics
Browse files Browse the repository at this point in the history
Adds Moulden's 1990 definition of SAMLG and SAWLG contrast metrics, fixes bug in checkerboard factory
  • Loading branch information
guillermoaguilar committed Sep 24, 2020
2 parents bebddec + 239e114 commit 2d135d1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 49 additions & 1 deletion src/contrast_metrics.py
Expand Up @@ -122,6 +122,53 @@ def SAMLG(arr, mask=None, mode="unique"):
return SAM(np.log(arr), mask, mode)


def SAMLG_Moulden(arr, mask=None, mode="complete", return_pair_contrasts=False):
"""
Space-Average Log Michelson contrast of all pairs of values in arr.
This formula comes from Moulden, Kingdom, Gatley 1990.
Different than SAMLG, which uses formula in Robilotto 2002
"""

n = len(arr)

c, pair_contrasts = _SAM_or_SAW('SAM', arr, mask, mode, return_pair_contrasts=True)

# current ATF has identical values, resolution problem! I had to remove
# equal values manually
#pair_contrasts = np.array(pair_contrasts)
#pair_contrasts = pair_contrasts[pair_contrasts!=0]
# not needed anymore as I'm taking analytical ATFs

pair_contrasts = np.log(pair_contrasts)
contrast = 2 * np.sum(pair_contrasts) / (n * n)

return contrast


def SAWLG_Moulden(arr, mask=None, mode="complete", return_pair_contrasts=False):
"""
Space-Average Log Whittle contrast of all pairs of values in arr.
This formula comes from Moulden, Kingdom, Gatley 1990.
Different than SAWLG, which uses formula in Robilotto 2002
"""

n = len(arr)

c, pair_contrasts = _SAM_or_SAW('SAW', arr, mask, mode, return_pair_contrasts=True)

# current ATF has identical values, resolution problem! I had to remove
# equal values manually
#pair_contrasts = np.array(pair_contrasts)
#pair_contrasts = pair_contrasts[pair_contrasts!=0]
# not needed anymore as I'm taking analytical ATFs

pair_contrasts = np.log(pair_contrasts)
contrast = 2 * np.sum(pair_contrasts) / (n * n)

return contrast

def SDMC(arr, mask=None, mode="unique"):
"""
Standard deviation of Michelson contrasts between the values in arr.
Expand Down Expand Up @@ -236,6 +283,7 @@ def alpha_c(plain, medium):
return c_medium / c_plain


##### TODO complete docstrings
def alpha_metelli(plain, medium):
"""
ratio of luminance ranges
Expand All @@ -246,7 +294,7 @@ def alpha_metelli(plain, medium):
q = medium.min()
return np.around((p - q) / (a - b), decimals=2)


##### TODO complete docstrings
def alpha_c_minmax(plain, medium):
"""
ratio of luminance ranges adjusted by additional offset term
Expand Down
2 changes: 1 addition & 1 deletion src/transparency/checkerboard_factory.py
Expand Up @@ -75,7 +75,7 @@ def find_checkerboard(self, n_checks, reflectances=None, sample_repeat=9,
reflectances = [0.06, 0.11, 0.19, 0.31, 0.46, 0.63, 0.82, 1.05, 1.29, 1.50, 1.67, 1.95, 2.22]

if len(reflectances) * sample_repeat < total_checks:
sample_repeat = np.ceil(total_checks / len(reflectances))
sample_repeat = int(np.ceil(total_checks / len(reflectances)))
warnings.warn('Given value for sample_repeat was too small and has been changed to %d.' % sample_repeat)

# repeated concatenation of reflectances / multiset of values the cells will be sampled from without replacing
Expand Down

0 comments on commit 2d135d1

Please sign in to comment.