-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_condition.js
More file actions
203 lines (191 loc) · 7.87 KB
/
make_condition.js
File metadata and controls
203 lines (191 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
function make_condition(cond_list, jitter, target_coord, n_block, stim_dir, position_idx) {
// prepare the base cell coord
var cell_coord = [];
for(y=-12; y<=12; y++){
for(x=-12; x<=12; x++){
cell_coord.push(x+"_"+y);
}
};
// ***** 1-D feature ***** //
var oneDim_ftr = [];
for(i=0; i<cond_list.length; i++){
// target_coord
if(cond_list[i].target_ox==0){
var target = [];
var target_path = [];
}else{
var target = target_coord;
var target_path = stim_dir+('000000'+cell_coord.indexOf(target)).slice(-6)+'.webp';
}
// get foil coords
var distance = Math.round(Math.sqrt(cond_list[i].dist*cond_list[i].dist/2));
var nt1 = distance*cond_list[i].direction;
var nt_coords = [];
for(ss in _.range(cond_list[i].set_size)){
if(cond_list[i].dimension==-1){
var nt = (nt1+_.sample(jitter,1)[0])+'_'+(nt1+_.sample(jitter,1)[0]);
}else{
var nt = (nt1+_.sample(jitter,1)[0])+'_'+(nt1*-1+_.sample(jitter,1)[0]);
}
nt_coords.push(nt);
}
nt_coords= nt_coords.slice(0,cond_list[i].set_size-cond_list[i].target_ox);
oneDim_ftr.push({
type:'oneDim-feature',
set_size: cond_list[i].set_size,
stim_position: _.sample(position_idx, cond_list[i].set_size),
target_ox: cond_list[i].target_ox,
dimension: cond_list[i].dimension,
direction: cond_list[i].direction,
target: target,
target_path: target_path,
nts: nt_coords,
nt_path: _.map(nt_coords, function(x){
var y=stim_dir+('000000'+cell_coord.indexOf(x)).slice(-6)+'.webp';
return y;})
})
}
// ***** 2-D feature ***** //
var twoDim_ftr = [];
for(i=0; i<cond_list.length; i++){
// target_coord
if(cond_list[i].target_ox==0){
var target = [];
var target_path = [];
}else{
var target = target_coord;
var target_path = stim_dir+('000000'+cell_coord.indexOf(target)).slice(-6)+'.webp';
}
// get foil coords
var distance = Math.round(Math.sqrt(cond_list[i].dist*cond_list[i].dist/2));
var nt1 = [distance*cond_list[i].direction, distance];
var nt2 = [distance*cond_list[i].direction, distance*-1];
var nt_coords = [];
for(ss in _.range(Math.ceil(cond_list[i].set_size/2))){
if(cond_list[i].dimension==-1){
var nt1_coord = (nt1[0]+_.sample(jitter,1)[0])+'_'+(nt1[1]+_.sample(jitter,1)[0]);
var nt2_coord = (nt2[0]+_.sample(jitter,1)[0])+'_'+(nt2[1]+_.sample(jitter,1)[0]);
}else{
var nt1_coord = (nt1[1]+_.sample(jitter,1)[0])+'_'+(nt1[0]+_.sample(jitter,1)[0]);
var nt2_coord = (nt2[1]+_.sample(jitter,1)[0])+'_'+(nt2[0]+_.sample(jitter,1)[0]);
}
nt_coords.push(nt1_coord);
nt_coords.push(nt2_coord);
}
nt_coords= nt_coords.slice(0,cond_list[i].set_size-cond_list[i].target_ox);
twoDim_ftr.push({
type:'twoDim-feature',
set_size: cond_list[i].set_size,
stim_position: _.sample(position_idx, cond_list[i].set_size),
target_ox: cond_list[i].target_ox,
dimension: cond_list[i].dimension,
direction: cond_list[i].direction,
target: target,
target_path: target_path,
nts: nt_coords,
nt_path: _.map(nt_coords, function(x){
var y=stim_dir+('000000'+cell_coord.indexOf(x)).slice(-6)+'.webp';
return y;})
})
}
// ***** 2-D conjunction ***** //
var twoDim_cnj = [];
for(i=0; i<cond_list.length; i++){
// target_coord
if(cond_list[i].target_ox==0){
var target = [];
var target_path = [];
}else{
var target = target_coord;
var target_path = stim_dir+('000000'+cell_coord.indexOf(target)).slice(-6)+'.webp';
}
// get foil coords
var distance = cond_list[i].dist;
if(cond_list[i].dimension==1){
nt1 = [distance*cond_list[i].direction, 0]
nt2 = [0, distance*cond_list[i].direction*-1]
}else{
nt1 = [distance*cond_list[i].direction, 0]
nt2 = [0, distance*cond_list[i].direction]
}
var nt_coords = [];
for(ss in _.range(Math.ceil(cond_list[i].set_size/2))){
nt1_coord = (nt1[0]+_.sample(jitter,1)[0])+'_'+(nt1[1]+_.sample(jitter,1)[0])
nt2_coord = (nt2[0]+_.sample(jitter,1)[0])+'_'+(nt2[1]+_.sample(jitter,1)[0])
nt_coords.push(nt1_coord);
nt_coords.push(nt2_coord);
}
nt_coords= nt_coords.slice(0,cond_list[i].set_size-cond_list[i].target_ox);
twoDim_cnj.push({
type:'twoDim-conjunction',
set_size: cond_list[i].set_size,
stim_position: _.sample(position_idx, cond_list[i].set_size),
target_ox: cond_list[i].target_ox,
dimension: cond_list[i].dimension,
direction: cond_list[i].direction,
target: target,
target_path: target_path,
nts: nt_coords,
nt_path: _.map(nt_coords, function(x){
var y=stim_dir+('000000'+cell_coord.indexOf(x)).slice(-6)+'.webp';
return y;})
})
}
// ***** 2-D diagonal ***** //
var twoDim_dgn = [];
for(i=0; i<cond_list.length; i++){
// target_coord
if(cond_list[i].target_ox==0){
var target = [];
var target_path = [];
}else{
var target = target_coord;
var target_path = stim_dir+('000000'+cell_coord.indexOf(target)).slice(-6)+'.webp';
}
// get foil coords
var distance = Math.round(Math.sqrt(cond_list[i].dist*cond_list[i].dist/2));
var nt1=distance*cond_list[i].direction;
var nt2=distance*cond_list[i].direction*-1;
var nt_coords = [];
for(ss in _.range(Math.ceil(cond_list[i].set_size/2))){
if(cond_list[i].dimension==1){
nt1_coord = (nt1+_.sample(jitter,1)[0])+'_'+(nt1+_.sample(jitter,1)[0]);
nt2_coord = (nt2+_.sample(jitter,1)[0])+'_'+(nt2+_.sample(jitter,1)[0]);
}else{
nt1_coord = (nt1+_.sample(jitter,1)[0])+'_'+(nt1*-1+_.sample(jitter,1)[0]);
nt2_coord = (nt2+_.sample(jitter,1)[0])+'_'+(nt2*-1+_.sample(jitter,1)[0]);
}
nt_coords.push(nt1_coord);
nt_coords.push(nt2_coord);
}
nt_coords= nt_coords.slice(0,cond_list[i].set_size-cond_list[i].target_ox);
twoDim_dgn.push({
type:'twoDim-diagnoal',
set_size: cond_list[i].set_size,
stim_position: _.sample(position_idx, cond_list[i].set_size),
target_ox: cond_list[i].target_ox,
dimension: cond_list[i].dimension,
direction: cond_list[i].direction,
target: target,
target_path: target_path,
nts: nt_coords,
nt_path: _.map(nt_coords, function(x){
var y=stim_dir+('000000'+cell_coord.indexOf(x)).slice(-6)+'.webp';
return y;})
})
}
// merge all
var exp_cond = [];
exp_cond.push(oneDim_ftr)
exp_cond.push(twoDim_ftr)
exp_cond.push(twoDim_cnj)
exp_cond.push(twoDim_dgn)
exp_cond = _.flatten(exp_cond)
exp_cond = _.shuffle(exp_cond);
var b_len = exp_cond.length/n_block;
var condition = [];
for(b=0; b<n_block; b++){
condition.push(exp_cond.slice(b_len*b, b_len*(b+1)));
};
return condition;
}