Do an adaptive track staircase with MHW procedure#

This shows how to make and use an adaptive track with the modified Hughson-Westlake (MHW) procedure using expyfun.stimuli.TrackerMHW.

Adaptive track of model human (true threshold is 115)
tracker_identify:                       {"tracker_id": "139796629064960-1732030354210959", "tracker_type": "TrackerMHW"}
tracker_139796629064960-1732030354210959_init:{"callback": null, "base_step": 5, "factor_down": 2, "factor_up_nr": 4, "start_value": 80, "x_min": 0, "x_max": 120, "n_up_stop": 2, "repeat_limit": "reversals"}
tracker_139796629064960-1732030354210959_respond:False
tracker_139796629064960-1732030354210959_respond:False
tracker_139796629064960-1732030354210959_respond:True
tracker_139796629064960-1732030354210959_respond:False
tracker_139796629064960-1732030354210959_respond:True
tracker_139796629064960-1732030354210959_respond:False
tracker_139796629064960-1732030354210959_respond:False
/home/circleci/project/expyfun/stimuli/_tracker.py:1332: UserWarning: Tracker 139796629064960-1732030354210959 exceeded x_min or x_max bounds 1 times.
  warnings.warn(
tracker_139796629064960-1732030354210959_stop:{"responses": [0, 0, 1, 0, 1, 0, 0, 1], "reversals": [0, 0, 1, 2, 3, 4, 0, 5], "x": [80.0, 100.0, 120.0, 110.0, 115.0, 105.0, 110.0, 115.0], "threshold": 115, "n_correct_levels": {"0": 0, "5": 0, "10": 0, "15": 0, "20": 0, "25": 0, "30": 0, "35": 0, "40": 0, "45": 0, "50": 0, "55": 0, "60": 0, "65": 0, "70": 0, "75": 0, "80": 0, "85": 0, "90": 0, "95": 0, "100": 0, "105": 0, "110": 0, "115": 2, "120": 1}}

import numpy as np

from expyfun.analyze import sigmoid
from expyfun.stimuli import TrackerMHW


# Make a callback function that prints to the console, rather than log file
def callback(event_type, value=None, timestamp=None):
    print((str(event_type) + ":").ljust(40) + str(value))


# Define parameters for modeled human subject (sigmoid probability)
true_thresh = 115
slope = 0.8
chance = 0.08  # if you don't hear it, you don't respond

# Make a tracker that uses the weighted up-down procedure to find 75%
tr = TrackerMHW(callback, 0, 120, base_step=5, start_value=80)

# Initialize human state
rng = np.random.RandomState(1)

# Do the task until the tracker stops
while not tr.stopped:
    tr.respond(
        rng.rand() < sigmoid(tr.x_current - true_thresh, lower=chance, slope=slope)
    )

# Plot the results
fig, ax, lines = tr.plot()
lines += tr.plot_thresh()

ax.set_title(f"Adaptive track of model human (true threshold is {true_thresh})")

Total running time of the script: (0 minutes 0.098 seconds)

Gallery generated by Sphinx-Gallery