Replies: 1 comment 1 reply
-
Hi @Alinaedr, hmm, what an interesting problem! There's definitely a few different approaches you could take to this, and I don't know which is easiest or most intuitive for you. Maybe someone else will chime in with a better approach to this. One option I can think of is to do something kind of similar to the suggestion I made here and here, which is to (1) use the custom sampling function to randomly select a subset of trials to present, (2) remove the selected trials from the trial array (so that they can't be selected again on subsequent repetitions), and (3) repeat this whole timeline/sampling procedure as many times as necessary. The trick in your case is that you need to have a separate copy of the trial info arrays that track the remaining trials during the task, because the sampling function needs to return the indices of the selected trials in the original (unmodified) timeline_variables array. And here the custom sampling function is really just doing the same basic sampling as the sampling without replacement option for timeline variables, except that the custom function also allows us to keep track of the remaining trials. So I think you could do this (disclaimer: I haven't tested this so not sure if it works!): // create separate global copies of the trial info arrays that track the remaining trials in each
var test_trial_info_remaining_trials = test_trial_info;
var test_control_trial_info_remaining_trials = test_control_trial_info;
var test_trial_telepathy_info_remaining_trials = test_trial_telepathy_info;
var totalProcedure = [
{
timeline: [baseline_target, target],
timeline_variables: test_trial_info,
sample: {
type: 'custom',
fn: function(t) {
// randomly select two trials from the 'remaining trials' version of the timeline_variables array
var sampled_trials = jsPsych.randomization.sampleWithoutReplacement(test_trial_info_remaining_trials, 2);
// remove the selected trials from the 'remaining trials' array, so that they're not selected again
var t_1 = test_trial_info_remaining_trials.indexOf(sampled_trials[0]);
var t_2 = test_trial_info_remaining_trials.indexOf(sampled_trials[1]);
test_trial_info_remaining_trials.splice(t_1, 1);
test_trial_info_remaining_trials.splice(t_2, 1);
// return an array containing the indices of the two trials in the *original* timeline_variables array (test_trial_info)
var index1 = test_trial_info.indexOf(sampled_trials[0]);
var index2 = test_trial_info.indexOf(sampled_trials[1]);
return [index1,index2];
}
}
},
{
timeline: [baseline_control, control, target_control],
timeline_variables: test_control_trial_info,
sample: {
// same as above, but using the test_control_trial_info and test_control_trial_info_remaining_trials arrays
}
},
{
timeline: [baseline_target_telepathy, target_telepathy],
timeline_variables: test_trial_telepathy_info,
sample: {
// same as above, but using the test_trial_telepathy_info and test_trial_telepathy_info_remaining_trials arrays
}
}
]; Then, to repeat this whole var totalProcedureNode = {
timeline: totalProcedure,
repetitions: 10
}; Or you could loop over the var totalProcedureLoop = {
timeline: totalProcedure,
loop_function: function(data) {
if (test_trial_info_remaining_trials.length >= 2 && test_control_trial_info_remaining_trials.length >= 3 && test_trial_telepathy_info_remaining_trials.length >= 2) {
// if the remaining trials arrays contain at least as many trials as you need to sample on each run, then repeat the loop
return true;
} else {
// otherwise stop the loop
return false;
}
}
}; Does solution this work for you? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following nested timelines:
I need these nested timelines to be randomized every time each one of them is run, e.g., first [baseline_target, target] is run once (which means two trials - out of many possible trials from this timeline - are run), then [baseline_control, control, target_control] is run once (three trials are run), then [baseline_target_telepathy, target_telepathy] is run once (two trials run), etc., until all the trials from each timeline are run.
I tried to implement it with the following code:
But what it does is that it randomizes the whole timelines, so first all the trials from one timeline (say, [baseline_target, target]) are run, then all the trials from the second one and then all the trials from the third one, and this is not what I want (see above). How could I randomize the trials in the way I want?
Any help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions