Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Psychometric audit: how small a difference can the judge see?#
Psychophysics measures a sensory system by its psychometric function: the probability of a correct answer in a two-alternative forced choice as a function of the stimulus difference. easyiec applies the method to evaluators. Pairs of candidates are drawn so that a controlled attribute (here the brightness of a Julia set image) differs by graded amounts; the evaluator is asked which candidate has more of it, and a logistic function with lapse rate is fitted (Wichmann and Hill, 2001). The threshold — the difference at which the judge is right 75 % of the time — is the judge’s just-noticeable difference; the lapse rate measures its careless errors.
Three judges of brightness#
Mock judges that score the actual image brightness with three noise levels. With Claude, the same call measures the brightness discrimination of the model (see the last section of the gallery and the case study of the book).
import matplotlib.pyplot as plt
import easyiec as ei
from easyiec.evaluators import LLMJudge, MockJudgeClient
from easyiec.imaging import image_features
from easyiec.problems import JuliaSet
from easyiec.validation import psychometric_audit
problem = JuliaSet()
brightness = lambda img: float(image_features(img)[0]) # noqa: E731 the mock scores the rendered image
results = []
for noise in [0.01, 0.03, 0.08]:
judge = LLMJudge(MockJudgeClient(brightness, score_on="image", noise=noise, seed=1), problem, image_size=96,
debias="none")
res = psychometric_audit(judge, problem, "brightness", goal="Choose the brighter image.", n_levels=6,
per_level=12, name=f"judge noise {noise}")
results.append(res)
print(f"{res.attribute}: threshold {res.threshold75:.3f}, lapse {res.lapse:.2f}, accuracy {res.accuracy:.2f}")
ei.viz.plot_psychometric(results)
plt.show()

judge noise 0.01: threshold 0.009, lapse 0.00, accuracy 0.79
judge noise 0.03: threshold 0.014, lapse 0.03, accuracy 0.71
judge noise 0.08: threshold 0.037, lapse 0.01, accuracy 0.65
Total running time of the script: (0 minutes 17.287 seconds)