diff --git a/py/20200221_experiment_scheduling.py b/py/20200221_experiment_scheduling.py index 640c2b8..fe9e60f 100644 --- a/py/20200221_experiment_scheduling.py +++ b/py/20200221_experiment_scheduling.py @@ -1,16 +1,23 @@ #%% [markdown] -# Complex cognitive experiments require participants to perform multiple tasks across a space of time and then capture observations with different modalities. This notebook demonstrates some possible solutions for the problem of scheduling experimental tasks, and mainly concerns reformulating experiments as a resource allocation problem. +# Complex cognitive experiments require participants to perform multiple tasks across a span of limited lab time or online crowdsourcing time, hence demand flexible scheduling of tasks. +# This notebook demonstrates a possible solution for the problem of scheduling experimental tasks, and mainly concerns reformulating experiments as a resource allocation problem. +# +# Typical experiments are comprised of several session, in each session participants view a set of questionnaires, perform a test, and then respond to another set of questionnaires. This structure is repeated for each srssion throughout the experiment. -# First, we model a study with 12 sessions. Sessions consist of several surveys before and after a set of experimental tasks. We then define constraints and solve for a schedule for the given scenario. This scenario only plans the experiment for a single subject. - -# Use the following command to install dependencies: `pip install pyschedule` +# To orgnaize questionniare and tasks in a limited time, we first model a study as an ordered list of sessions (here, for example, 12 session). Sessions consist of several questionnaires before and after a set of experimental tasks. We then define constraints on sueverys and tasks (e.g., pre-task, post-task, end of study, and start of study surveys), and solve for a schedule for the given scenario. Note that his example scenario only plans the experiment for a single subject. +# +# Note: Use the following command to install dependencies: `pip install pyschedule` #%% from math import ceil -from pyschedule import Scenario, solvers, plotters, alt + +from pyschedule import Scenario, plotters, alt +from pyschedule.solvers.mip import solve +from pyschedule.plotters.matplotlib import plot + import seaborn as sns - +# 1. set theme and style sns.color_palette("colorblind") sns.set_style('white') # experiment duration in minutes @@ -18,12 +25,16 @@ game_duration = 45 n_subjects = 2 n_sessions = 12 -duration_per_question = .1666667 # minutes (~10sec) +duration_per_question = .16 # minutes (~10sec) prestudy_tasks = [ "xcit_demographics" ] +pregame_tasks = [ + +] + postgame_tasks = [ "nasa_tlx", "xcit_postgame_debrief" @@ -52,6 +63,7 @@ "ipaq_sf": 7, "maas": 15, "mfs": 12, + #"mmi_part1": 66, "mw": 8, "mwq": 5, "ncs_6": 6, @@ -76,43 +88,44 @@ sessions = s.Resources('Session', num = n_sessions) -# 2. games +def _duration(questions): + t = ceil(questions * duration_per_question) + return t + +# 3. games games = s.Tasks('Game',length=game_duration, num=n_sessions, is_group=False) games += alt(sessions) -# questionnaires +# 3. questionnaires for q in n_questions.keys(): n = n_questions.get(q, 0) - duration = ceil(n * duration_per_question) - task = s.Task(q, length= duration, delay_cost=1) - if q in poststudy_tasks: - print(q, 1) - task += sessions[-1] + task = s.Task(q, length= _duration(n), delay_cost=1) + + if q in prestudy_tasks: + task += sessions[0] # first session + elif q in poststudy_tasks: + task += sessions[-1] # last session s += games < task - elif q in prestudy_tasks: - print(q, 2) - task += sessions[0] s += task < games elif q in postgame_tasks: - print(q, 3) task += sessions s += games < task + elif q in pregame_tasks: + task += sessions + s += task < games else: - print(q, 4) task += alt(sessions) print(s.tasks) -solvers.mip.solve(s) +# 4. solve resource allocation +solve(s) + +# 5. print last computed solution print(s.solution()) -plotters.matplotlib.plot(s, fig_size=(50,5)) - -#%% -#%% [markdown] -# Complex experiments in cognitive science require participants to perform multiple tasks and capture observations with different modalities. This notebook demonstrates some possible solutions for the problem of scheduling experimental tasks. - -# First, we model a study with 12 sessions. Sessions consist of several surveys before and after a set of experimental tasks. We then define constraints and solve for a schedule for the given scenario. This scenario only plans the experiment for a single subject. +# 6. pot gantt +plot(s, fig_size=(50,5)) #%% # MPILX Scheduling