我在运行我在 JavaScript 库 jsPsych 中编写的代码时遇到问题。该代码使用了我为我正在设计的实验而创建的自定义插件。我的插件“image-button-response-with-name”与“image-button-response”插件相同,只是它还包含一个名为“name”的参数,我可以在其中输入一个字符串来识别试验有问题。
这是我在代码中尝试做的事情:
在我的实验中,有 10 种不同食物的图像。对于 10 种食物中的每一种,都有两个图像。因此,总共有 20 张图像。这 20 张图像分为由“名称”参数(沙拉、梨等)标识的 10 个类别。
受试者以 1 - 6 的等级对每个图像进行评分(计算机将其理解为 0 - 5 的响应等级)。
计算机从评分试验中收集数据,并识别使用同一类别图像的试验。换句话说,计算机会识别出 10 组试验:沙拉试验、梨试验等。
对于每个试验类别,计算机汇总试验的响应。例如,如果受试者在第一次沙拉试验中选择“1”,在第二次沙拉试验中选择“3”,那么计算机将计算沙拉试验的总和为 4。
对于前 5 个试验类别,计算机检索与每个类别关联的图像,如果类别总和为 5 或更少,则将这些图像分配给 imagesNatural,如果类别总和大于 5,则将这些图像分配给 imagesHealthy。
对于接下来的 5 个试验类别,计算机检索与每个类别关联的图像,如果类别总和为 5 或更少,则将这些图像分配给 imagesHealthy,如果类别总和大于 5,则将这些图像分配给 imagesNatural。
现在 imagesNatural 中应该有 10 个图像,imagesHealthy 中应该有 10 个图像。每个图像类别应仅出现在 1 个数组中(例如,两个沙拉图像都应出现在 imagesNatural 中)。
对象开始一个名为“测试”的新时间线,他们只对 imagesNatural 中的图像进行评分。这是我的代码:
//set-up var finalTimeline = []; var preload = { type: 'preload', images: ['Images/small_salad.jpeg', 'Images/small_pear.jpeg', 'Images/small_lollipop.jpeg', 'Images/small_grapes.jpeg', 'Images/small_cotton_candy.jpeg', 'Images/small_cookie.jpeg', 'Images/small_carrot.jpeg', 'Images/small_cake.jpeg', 'Images/small_brownie.jpeg', 'Images/small_apple.jpeg', 'Images/large_salad.jpeg', 'Images/large_pear.jpeg', 'Images/large_lollipop.jpeg', 'Images/large_grapes.jpeg', 'Images/large_cotton_candy.jpeg', 'Images/large_cookie.jpeg', 'Images/large_carrot.jpeg', 'Images/large_cake.jpeg', 'Images/large_brownie.jpeg', 'Images/large_apple.jpeg'] }; finalTimeline.push(preload); var welcome = { type: 'html-keyboard-response', stimulus: "Welcome to the experiment! Press any key to begin." }; finalTimeline.push(welcome); var instructionsGeneral = { type: 'instructions', pages: ['blah blah blah. A general overview of the experiment.'], show_clickable_nav: true }; finalTimeline.push(instructionsGeneral); //Liking Rating Task - Set 1 var instructionsLiking_1 = { type: 'instructions', pages: ['blah blah blah. Instructions for the Liking Rating Task.'], show_clickable_nav: true }; finalTimeline.push(instructionsLiking_1); var likingScale = [ "1 (Strongly Dislike)", "2", "3", "4", "5", "6 (Strongly Like)" ]; var likingRatingTask_1 = { timeline: [ { type: 'image-button-response-with-name', stimulus: jsPsych.timelineVariable('food'), choices: likingScale, prompt: "I would like to eat this food right now, in its presented quantity.", render_on_canvas: true, save_trial_parameters: { name: true } } ], timeline_variables: [ {food: "Images/small_salad.jpeg", name: 'salad'}, {food: "Images/small_pear.jpeg", name:'pear'}, {food: "Images/small_lollipop.jpeg", name:'lollipop'}, {food: "Images/small_grapes.jpeg", name:'grapes'}, {food: "Images/small_cotton_candy.jpeg", name:'cotton candy'}, {food: "Images/small_cookie.jpeg", name:'cookie'}, {food: "Images/small_carrot.jpeg", name:'carrot'}, {food: "Images/small_cake.jpeg", name:'cake'}, {food: "Images/small_brownie.jpeg", name:'brownie'}, {food: "Images/small_apple.jpeg", name:'apple'}, {food: "Images/large_salad.jpeg", name:'salad'}, {food: "Images/large_pear.jpeg", name:'pear'}, {food: "Images/large_lollipop.jpeg", name:'lollipop'}, {food: "Images/large_grapes.jpeg", name:'grapes'}, {food: "Images/large_cotton_candy.jpeg", name:'cotton candy'}, {food: "Images/large_cookie.jpeg", name:'cookie'}, {food: "Images/large_carrot.jpeg", name:'carrot'}, {food: "Images/large_cake.jpeg", name:'cake'}, {food: "Images/large_brownie.jpeg", name:'brownie'}, {food: "Images/large_apple.jpeg", name:'apple'} ], randomize_order: true }; finalTimeline.push(likingRatingTask_1); //condition assignment imageNames = ["'salad'", "'pear'", "'lollipop'", "'grapes'", "'cotton candy'", "'cookie'", "'carrot'", "'cake'", "'brownie'"]; imagesNatural_almost = []; imagesHealthy_almost = []; imagesNatural = []; imagesHealthy = []; function conditionAssignment(imageNames, imagesNatural_almost, imagesHealthy_almost, imagesNatural, imagesHealthy) { var imageNames_shuffled = jsPsych.randomization.shuffle(imageNames); for (let i = 0; i <= 4; i++) { var trialsSum_1 = jsPsych.data.get().filter({name: imageNames_shuffled[i]}).select('response').sum(); if (trialsSum_1 <= 5) { imagesNatural_almost.push(''+ jsPsych.data.get().filter({name: imageNames_shuffled[i]}).select('stimulus').values ); } else { imagesHealthy_almost.push(''+ jsPsych.data.get().filter({name: imageNames_shuffled[i]}).select('stimulus').values ); } }; for (let i = 5; i <=9; i++) { var trialsSum_2 = jsPsych.data.get().filter({name: imageNames_shuffled[i]}).select('response').sum(); if (trialsSum_2 <= 5) { imagesHealthy_almost.push('' + jsPsych.data.get().filter({name: imageNames_shuffled[i]}).select('stimulus').values ); } else { imagesNatural_almost.push('' + jsPsych.data.get().filter({name: imageNames_shuffled[i]}).select('stimulus').values ); } }; for (let i = 0; i < imagesNatural_almost.length; i++) { imagesNatural.push( {food: imagesNatural_almost[i]} ); }; for (let i = 0; i < imagesHealthy_almost.length; i++) { imagesHealthy.push( {food: imagesHealthy_almost[i]} ); } }; var selectStimuli_1 = { type: 'html-keyboard-response', stimulus: "Just a moment...", choices: jsPsych.NO_KEYS, trial_duration: 1000, on_load: conditionAssignment(imageNames, imagesNatural_almost, imagesHealthy_almost, imagesNatural, imagesHealthy) }; finalTimeline.push(selectStimuli_1); //test var test = { timeline: [ { type: 'image-button-response-with-name', stimulus: jsPsych.timelineVariable('food'), choices: likingScale, prompt: "I would like to eat this food right now, in its presented quantity.", render_on_canvas: true } ], timeline_variables: imagesNatural, randomize_order: true }; finalTimeline.push(test); //initiate experiment jsPsych.init({ timeline: finalTimeline, override_safe_mode: true, on_finish: function() { jsPsych.data.displayData(); } });
此代码不起作用。当我的计算机进入“测试”时间线时,它运行 5 次试验而不是所需的 10 次。此外,它在试验期间不显示任何图像。这让我觉得我的 imagesNatural 数组包含来自 imageNames_shuffled 数组的项目,而不是我的图像的路径。不幸的是,我不知道如何修复我的代码,以便使 imagesNatural 数组包含我的图像的路径。
如果有人对我如何修复我的代码有任何建议,请您在这里分享吗?