-
Notifications
You must be signed in to change notification settings - Fork 21
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
MRG: Tracker dealer example #310
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9182025
typo in tracker
maddycapp27 ac020ba
add example
maddycapp27 baf8e0b
parameter fix convergence
maddycapp27 a40640c
file in correct place
maddycapp27 bdb0e28
tracker staircase odd thing
maddycapp27 a116cee
small errors
maddycapp27 cee996f
fix ticks and subplot
maddycapp27 8867210
random seed
maddycapp27 e98a7f2
function def need more whitespace
maddycapp27 47f029f
disambiguate rng
maddycapp27 73cf303
more explainy
maddycapp27 d1e7d6d
typo and permissions
maddycapp27 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
====================== | ||
Tracker Dealer Example | ||
====================== | ||
|
||
This file shows how to interleave multiple Tracker objects using | ||
:class:`expyfun.stimuli.TrackerDealer`. | ||
|
||
In this case, a modeled human subject generates two curves (one for each trial | ||
type: 1 & 2). | ||
|
||
@author: maddycapp27 | ||
""" | ||
|
||
import numpy as np | ||
from expyfun.stimuli import TrackerUD, TrackerDealer | ||
from expyfun.analyze import sigmoid | ||
import matplotlib.pyplot as plt | ||
|
||
# define parameters of modeled subject (using sigmoid probability) | ||
true_thresh = [30, 40] # true thresholds for trial types 1 and 2 | ||
slope = 0.1 | ||
chance = 0.5 | ||
|
||
############################################################################## | ||
# Defining Tracker Parameters | ||
# --------------------------- | ||
# In this example, the tracker parameters are exactly the same for each | ||
# instance of the up-down adaptive tracker. These are defined such that the | ||
# step sizes vary for both up v. down (the up step size is larger by a factor | ||
# of 3) and based on the number of reversals (the first element in each | ||
# list is the step size until the number of reversals dictacted by the second | ||
# element in change_criteria have occured (i.e. the up step size will be 9 | ||
# until 5 reversals have occured, then the up step size will be 3.)) | ||
up = 1 | ||
down = 1 | ||
step_size_up = [9, 3] | ||
step_size_down = [3, 1] | ||
stop_criterion = 30 | ||
stop_rule = 'reversals' | ||
start_value = 45 | ||
change_criteria = [0, 5] | ||
change_rule = 'reversals' | ||
x_min = 0 | ||
x_max = 90 | ||
|
||
|
||
# callback function that prints to console | ||
def callback(event_type, value=None, timestamp=None): | ||
print((str(event_type) + ':').ljust(40) + str(value)) | ||
|
||
|
||
# parameters for the tracker dealer | ||
max_lag = 2 | ||
rng_dealer = np.random.RandomState(3) # random seed for selecting trial type | ||
|
||
############################################################################## | ||
# Initializing and Running Trackers | ||
# --------------------------------- | ||
# The two trackers in this example use all of the same parameters and then are | ||
# passed into the dealer. After the dealer is created, the type of each trial | ||
# (returned as an index of the array of individual trackers) and trial level | ||
# for that trial can be acquired. | ||
|
||
# initialize two tracker objects--one for each trial type | ||
tr_UD = [TrackerUD(callback, up, down, step_size_up, step_size_down, | ||
stop_criterion, stop_rule, start_value, | ||
change_criteria, change_rule, x_min, x_max) for i in [0, 1]] | ||
|
||
# initialize TrackerDealer object | ||
tr = TrackerDealer(tr_UD, max_lag, rng_dealer) | ||
|
||
# Initialize human state | ||
rng_human = np.random.RandomState(1) # random seed for modeled subject | ||
|
||
while not tr.stopped: | ||
# Get information of which trial type is next and what the level is at | ||
# that time from TrackerDealer | ||
ss, level = tr.get_trial() | ||
ss = sum(ss) | ||
tr_UD[ss].respond(rng_human.rand() < sigmoid(level - true_thresh[ss], | ||
lower=chance, slope=slope)) | ||
|
||
############################################################################## | ||
# Plotting the Results | ||
# --------------------------- | ||
axes = plt.subplots(2, 1)[1] | ||
for i in [0, 1]: | ||
fig, ax, lines = tr[i].plot(ax=axes[i]) | ||
lines += tr[i].plot_thresh(4, ax=ax) | ||
|
||
lines[0].set_label('Trials') | ||
lines[1].set_label('Reversals') | ||
lines[2].set_label('Estimated threshold') | ||
|
||
ax.legend(loc='best') | ||
ax.set_title('Adaptive track of model human trial type {} (true threshold ' | ||
'is {})'.format(i + 1, true_thresh[i])) | ||
fig.tight_layout() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI if you want you can make pretty sections in the output like this:
https://github.com/mne-tools/mne-python/blob/master/tutorials/plot_artifacts_correction_filtering.py#L49
that render like this:
https://mne-tools.github.io/dev/auto_tutorials/plot_artifacts_correction_filtering.html#removing-power-line-noise-with-notch-filtering
might be overkill in this example but it's something to consider when writing pedagogical examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll definitely keep that in mind for the future! For this example, I agree that it's not very necessary though.