用约束对列表进行混洗

用约束对列表进行混洗

本文介绍了用约束对列表进行混洗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

准备一个新的心理物理实验,我有48次原始刺激显示了4次(4种情况),进行了192次试验.尝试随机化实验过程中的演示顺序,我需要最大化相同原始刺激的4个显示之间的距离.

Preparing a new psychophysical experiment,I have 48 original stimuli displayed 4 times (4 conditions), resulting in 192 trials.Trying to randomize the order of presentation during the experiment,I need to maximize the distance between the 4 display of the same original stimuli.

请考虑:

Table[{j, i}, {j, Range[48]}, {i, Range[4]}]

j是原始刺激数,i是条件

Where j is the original stimuli number and i the condition

输出样本:

 {{1, 1}, {1, 2}, {1, 3}, {1, 4},
  {2, 1}, {2, 2}, {2, 3}, {2, 4},
  ...
  {47, 1}, {47, 2}, {47, 3},{47, 4},
  {48, 1}, {48, 2}, {48, 3}, {48, 4}}

我该如何调整这192个项目的显示顺序,以使相同项目之间相对于原始刺激数j的距离最大化?

How could I shuffle the order of presentation of those 192 items, maximizing the distance between identical items with regard to j, the original stimuli number?

推荐答案

您必须在随机性与原始刺激之间最大距离约束之间取得折衷.将刺激分为48个刺激的4个相同系列(非随机表示)时,可以获得最大距离.在这种情况下,每个原始刺激的距离固定为48.

You have to have a compromise between randomness and your constraint of maximum distance between original stimuli. A maximum distance is obtained when you arrange the stimuli in 4 identical series of 48 stimuli (a non-random presentation). The distance is fixed at 48 for every original stimulus in that case.

如果您随机分配192对,则原始刺激之间的平均距离平均为38.6,最小和最大可能分别为1和144:

If you distribute the 192 pairs totally random the average distance between the original stimuli is 38.6 on average, with minimum and maximum possible distances of 1 and 144 respectively:

t = Flatten[Table[i, {4}, {i, 48}]];

{Mean[#], StandardDeviation[#]} &@
Table[
  rs = RandomSample[t, 192];
    Mean[Mean[Differences[Flatten[Position[rs, #]]]] & /@ Range[48]] //
   N, {10000}
]

(* ==> {38.60370417, 1.397151004} *)

您可以进行其他操作.首先将48个刺激物分成2组,每组24个(1-24 [I区]和25-48 [II区]).然后生成I和II的随机排列(p):p(I)p(II)p(I)p(II)p(I)p(II)p(I)p(II).

You can do it differently. First split the 48 stimuli in 2 blocks of 24 (1-24 [block I] and 25-48 [block II]). Then generate random permutations (p) of I and II: p(I)p(II)p(I)p(II)p(I)p(II)p(I)p(II).

现在平均距离变为:

{Mean[#], StandardDeviation[#]} &@
Table[
  rs =
    Join[RandomSample[Range[24]], RandomSample[Range[25, 48]],
         RandomSample[Range[24]], RandomSample[Range[25, 48]],
         RandomSample[Range[24]], RandomSample[Range[25, 48]],
         RandomSample[Range[24]], RandomSample[Range[25, 48]]
    ];
  Mean[Mean[Differences[Flatten[Position[rs, #]]]] & /@ Range[48]] //N, {10000}]

(* ==> {48., 0.} *)

因此,我们现在有更多随机表示,而平均距离仍然是48(最小距离现在是24,最大距离是47).注意标准偏差为0.作为练习,我将向您证明为什么必须这样做.

So we now have a much more random presentation while the average distance is still 48 (minimum distance now is 24 and maximum distance is 47). Note the standard deviation of 0. As an exercise I'll leave the proof of why that must be so to you.

更新1
我将刺激分为两组,分别是1-24和25-48.我建议您在开始分成两组之前,对每个主题使用新的随机初始安排.这将在主题上引入一些额外的平衡.

Update 1
I've arranged the stimuli in two groups here, 1-24 and 25-48. I suggest you use a new random initial arrangement for each subject, before you start breaking up into two groups. This will introduce a bit of extra balancing over subjects.

更新2
现在,刺激条件组合生成的代码:

Update 2
And now, the code for the stimulus-condition combo generation:

首先,随机化所有刺激的条件:

First, randomize condition over all stimuli:

m = MapThread[
       List,
       {
         Table[Range[48], {4}],
         Table[RandomSample[{1, 2, 3, 4}], {48}]\[Transpose]
       }, 2
    ]

然后,分成24个一组,将它们洗牌,然后排列为一个列表:

Then, break up in groups of 24, shuffle those, and arrange as one list:

Flatten[RandomSample /@ Partition[Flatten[m, 1], 24], 1]

要随机化每个主题的顺序(如我在上面的更新1中所建议的那样),在第一部分中需要进行一些小的更改:

To randomize the order for each subject (as I suggested above in update 1) a small change is necessary in the first part:

initialArrangement = RandomSample[Range[48]];
m =
 MapThread[
    List,
    {
       Table[initialArrangement, {4}],
       Table[RandomSample[{1, 2, 3, 4}], {48}]\[Transpose]
    }, 2
 ]

请注意,将第一行(RandomSample[Range[48]])放在Table内确实是错误的!

Please note that it would be really wrong to put the first line (RandomSample[Range[48]]) inside the Table!

在这里,Wizard先生使用的是表示法标记的版本,以表明我确实在尝试;-)

For Mr.Wizard here the infix notation version to show I'm really trying ;-)

m~Set~MapThread[List, (Range[48]~Table~{4}~
    List~((RandomSample[{1, 2, 3, 4}]~Table~ {48})\[Transpose])), 2]

第二部分:

(RandomSample /@ m~Flatten~1~Partition~24)~Flatten~1

第一部分的变体,如上:

The variation of the first part, like above:

initialArrangement~Set~RandomSample[Range[48]];
m~Set~MapThread[List, (initialArrangement~Table~{4}~
    List~((RandomSample[{1, 2, 3, 4}]~Table~ {48})\[Transpose])), 2]

顺便说一句,忘了第二部分的括号,尽管看起来很相似,但输出是完全错误的.

BTW Forget the parenthesis in the second part and the output, though looking similar, will be completely wrong.

这篇关于用约束对列表进行混洗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 15:33