Split B: OG-style block order + 5 fixed location layouts + float-order randomisation
Browse filesDecouple the experimental block order from house location, like the original task:
- the Nth house ENTERED gets the Nth pair in a fixed per-ID block-order sequence (env now
tracks current_block/blocks_entered; pairs/outcomes/side/attention/float indexed by block)
- house appearance + position stay physical; positions come from 1 of 5 fixed layouts
(number % 5, counterbalanced)
- new per-block float_order (6 you-first / 6 partner-first) for the upcoming coin animation
- DATA: blockIndex is now the experienced block (0..11); added physical_place/physical_house/
float_order per trial + house_by_block/place_by_block in summary; rando log gains
layout_id/block_order/float_order/attention_blocks. CODEBOOK updated.
- verified: orders self-tests, smoke (12x20 all rated), demo playthrough + export, clean boot
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files changed (4)
- CODEBOOK.md+13-14
- experiment_structure.py+63-47
- export_csv.py+22-10
- orders.py+69-43
39 unmodified lines4041424344454647137 unmodified lines18518618718818919019119219319419519619719819920020120220320420520620739 unmodified lines| Column | Values | Meaning ||--------|--------|---------|| `blockIndex` | `0`–`11` or `practice` | Which house. Practice rows are labelled `practice` (no longer collide with main house 0). || `trialIndex` | `0`–`19` (`0`–`4` practice) | Trial number within the house. || `option_pairs` | e.g. `AC` | The two reward profiles offered in this house. || `option_left` / `option_right` | `A`–`D` | Which profile was on each side **this trial** (sides swap across trials). || `left_stim` / `right_stim` | int `0`–`25` | Chest stimulus id on each side. |137 unmodified lines## The `randomization_log.csv` (separate file, on GitLab)One **self-describing** row per participant. Everything `*_by_place` uses the **same placeslot 0–11**, so `pair_by_place[i]`, `house_by_place[i]` and `pos_by_place[i]` all describethe same house. (This is *not* the order houses were visited — that's `blocks_visited_order`in the per-participant CSV, since children roam freely.)| Column | Meaning ||--------|---------|| `pid`, `gid`, `group`, `orderID` | ID, group code (0/1), group label (control/CU), participant number || `partner_id` | Anonymous partner code shown in the instructions (cover story only; deterministic) || `A_stim`–`D_stim` | Chest stimulus id assigned to each reward profile || `A_stim_desc`–`D_stim_desc` | Readable look, e.g. `indigo peaked-lid stripes` || `pair_by_place` | Pair at each place slot, `0:CD_1:BC_…` || `house_by_place` | House (name) at each place slot, `0:pagoda_1:cottage_…` || `pos_by_place` | Grid position of each place slot, `0:(5,9)_1:(4,21)_…` || `houses_done` | Houses finished so far (updates as the session progresses) || `completed` | `1` if all 12 houses finished, else `0` || `last_saved` | Timestamp of the most recent save for this participant |Use **`next_id.py`** to read this log and get the next ID to assign per group (+ a balancecheck of how often each box was used as each profile). The design columns are fully39 unmodified lines4041424344454647484950137 unmodified lines18818919019119219319419519619719819920020120220320420520639 unmodified lines| Column | Values | Meaning ||--------|--------|---------|| `blockIndex` | `0`–`11` or `practice` | **The experienced block** (OG-style block order): block 0 = the first house entered, block 1 = the second, etc. The pair at each block is fixed per participant, **independent of where the houses sit**. || `trialIndex` | `0`–`19` (`0`–`4` practice) | Trial number within the block. || `physical_place` | `0`–`11` | Which physical house slot this block happened in. || `physical_house` | e.g. `castle` | The physical house's appearance. || `float_order` | `you-first` / `partner-first` | Which avatar's coin animates first this block (counterbalanced 6/6). || `option_pairs` | e.g. `AC` | The two reward profiles offered in this house. || `option_left` / `option_right` | `A`–`D` | Which profile was on each side **this trial** (sides swap across trials). || `left_stim` / `right_stim` | int `0`–`25` | Chest stimulus id on each side. |137 unmodified lines## The `randomization_log.csv` (separate file, on GitLab)One **self-describing** row per participant.| Column | Meaning ||--------|---------|| `pid`, `gid`, `group`, `orderID` | ID, group code (0/1), group label (control/CU), participant number || `partner_id` | Anonymous partner code shown in the instructions (cover story only; deterministic) || `layout_id` | Which of the 5 fixed house-location layouts (= `number % 5`) || `A_stim`–`D_stim` (+ `_desc`) | Chest stimulus id assigned to each reward profile + readable look || `block_order` | **The experienced sequence of pairs**, `0:CD_1:BC_…` (block 0 = first house entered). || `float_order` | You-first / partner-first per block, `0:you-first_1:partner-first_…` || `attention_blocks` | Which blocks carry the attention check, e.g. `6_8` || `house_by_place` / `pos_by_place` | Physical house appearance / grid position per place slot || `houses_done` / `completed` / `last_saved` | Progress, completion flag, last-save timestamp |Use **`next_id.py`** to read this log and get the next ID to assign per group (+ a balancecheck of how often each box was used as each profile). The design columns are fully
91 unmodified lines92939495969798991001011021031041051061071083 unmodified lines1121131141151161171181196 unmodified lines12612712812913013113213313413513613713813914014122 unmodified lines1641651661671681695 unmodified lines17517617717817918018118218318418518618713 unmodified lines2012022032042052062072082092102112122131 unmodified line2152162172182192202212222232242255 unmodified lines23123223323423523623723823924024124214 unmodified lines25725825926026126226326429 unmodified lines294295296297298299300301302303304305306307308309200 unmodified lines51051151251351451551651751851968 unmodified lines58858959059159259359410 unmodified lines60560660760860961061161261361461561661761861962062162262391 unmodified lines# ----------------------------------------------------------------------------@struct.dataclassclass EnvParams:house_pos: jax.Array # (12,2)place_pairs: jax.Array # (12,2) letters per place (in block order)pair_code: jax.Array # (12,)house_type: jax.Array # (12,) 0..12stim_map: jax.Array # (4,) letter -> stimulus id (0..23)side_schedule: jax.Array # (12,N_TRIALS)outcomes: jax.Array # (12,2,2,N_TRIALS) [place, option, recipient, trial]n_trials: jax.Arrayactive_mask: jax.Array # (12,)practice: jax.Arrayattention_places: jax.Array # (12,) 1 = this house gets a 21st 'attention check' trial@struct.dataclass3 unmodified linespartner_pos: jax.Arrayfacing: jax.Arraywalk_frame: jax.Arrayconsumed: jax.Array # (12,) boolcurrent_place: jax.Arraytrial: jax.Arrayn_trials: jax.Arraypractice: jax.Array6 unmodified lineslast_self_outcome: jax.Arraylast_other_outcome: jax.Arrayrating_cursor: jax.Arrayratings: jax.Array # (12,) -1 unrated else 0..6house_pos: jax.Array # (12,2) positions this sessionhouse_active: jax.Array # (12,) boolplace_pairs: jax.Array # (12,2) letterspair_code: jax.Array # (12,) 0..5 (option-pair identity, for data)house_type: jax.Array # (12,) 0..12 (which distinct house / room theme)stim_map: jax.Array # (4,) letter -> stimulus idside_schedule: jax.Array # (12, N_TRIALS) 0/1outcomes: jax.Array # (12,2,2,N_TRIALS) pre-baked exact outcomesattention_places: jax.Array # (12,) 1 = house with a 21st attention-check trialdef _layout(opt_letters, side_bit):22 unmodified linesfacing=jnp.int32(0), walk_frame=jnp.int32(0),consumed=~active,current_place=jnp.int32(-1),trial=jnp.int32(0),n_trials=params.n_trials,practice=params.practice,5 unmodified linesratings=jnp.full(N_PLACES, -1, jnp.int32),house_pos=params.house_pos.astype(jnp.int32),house_active=active,place_pairs=params.place_pairs.astype(jnp.int32),pair_code=params.pair_code.astype(jnp.int32),house_type=params.house_type.astype(jnp.int32),stim_map=params.stim_map.astype(jnp.int32),side_schedule=params.side_schedule.astype(jnp.int32),outcomes=params.outcomes.astype(jnp.int32),attention_places=params.attention_places.astype(jnp.int32),)return self._obs(s), s13 unmodified linesmatches = jnp.all(s.house_pos == target, axis=1) & s.house_active & (~s.consumed)entering = jnp.any(matches)place_idx = jnp.argmax(matches)opt = s.place_pairs[place_idx]left, right = _layout(opt, s.side_schedule[place_idx, 0])moved_state = s.replace(agent_pos=target, partner_pos=new_partner,facing=facing, walk_frame=new_walk)enter_state = moved_state.replace(mode=jnp.int32(M_CHOICE), current_place=place_idx, trial=jnp.int32(0),left_letter=left, right_letter=right, chosen_side=jnp.int32(-1))return _select(entering, enter_state, moved_state)1 unmodified lineis_choice = (action == A_LEFT) | (action == A_RIGHT)chosen_side = jnp.where(action == A_LEFT, jnp.int32(0), jnp.int32(1))chosen_letter = jnp.where(chosen_side == 0, s.left_letter, s.right_letter)# which option of this place's pair (0 or 1), then look up the pre-baked outcomeopt_idx = jnp.where(chosen_letter == s.place_pairs[s.current_place, 0],jnp.int32(0), jnp.int32(1))self_out = s.outcomes[s.current_place, opt_idx, 0, s.trial]other_out = s.outcomes[s.current_place, opt_idx, 1, s.trial]resolved = s.replace(mode=jnp.int32(M_OUTCOME), chosen_side=chosen_side, chosen_letter=chosen_letter,last_self_outcome=self_out, last_other_outcome=other_out,5 unmodified linesnext_trial = s.trial + 1place_done = next_trial >= s.n_trialsnt = jnp.clip(next_trial, 0, N_TRIALS - 1)opt = s.place_pairs[s.current_place]n_left, n_right = _layout(opt, s.side_schedule[s.current_place, nt])next_round = s.replace(mode=jnp.int32(M_CHOICE), trial=next_trial,left_letter=n_left, right_letter=n_right, chosen_side=jnp.int32(-1))# after the 20 trials: an attention-check house gets a 21st check; others -> ratingis_att = s.attention_places[s.current_place] > 0to_attention = s.replace(mode=jnp.int32(M_ATTENTION))to_rating = s.replace(mode=jnp.int32(M_RATING), rating_cursor=jnp.int32(RATING_MAX // 2))place_end = _select(is_att, to_attention, to_rating)14 unmodified linescursor = jnp.clip(s.rating_cursor + is_right.astype(jnp.int32) - is_left.astype(jnp.int32),0, RATING_MAX)moved = s.replace(rating_cursor=cursor)new_consumed = s.consumed.at[s.current_place].set(True)new_ratings = s.ratings.at[s.current_place].set(s.rating_cursor)confirmed = s.replace(mode=jnp.int32(M_OVERWORLD), consumed=new_consumed,ratings=new_ratings, current_place=jnp.int32(-1))new_state = _select(is_confirm, confirmed, moved)29 unmodified lines"""Turn an `orders.make_order(...)` dict into EnvParams (jnp arrays)."""return EnvParams(house_pos=jnp.asarray(order["house_pos"], jnp.int32),place_pairs=jnp.asarray(order["place_pairs"], jnp.int32),pair_code=jnp.asarray(order["pair_code"], jnp.int32),house_type=jnp.asarray(order["house_type"], jnp.int32),stim_map=jnp.asarray(order["stim_map"], jnp.int32),side_schedule=jnp.asarray(order["side_schedule"], jnp.int32),outcomes=jnp.asarray(order["outcomes"], jnp.int32),n_trials=jnp.int32(n_trials),active_mask=jnp.asarray(active_mask, jnp.int32),practice=jnp.int32(practice),attention_places=jnp.asarray(order["attention_places"], jnp.int32),)200 unmodified linesdef _render_rating(s):place_id = _i(s.current_place)cursor = _i(s.rating_cursor)sc, oc = _i(s.self_coins), _i(s.other_coins)opt = np.asarray(s.place_pairs)[place_id]stim_map = np.asarray(s.stim_map)stim_l, stim_r = int(stim_map[int(opt[0])]), int(stim_map[int(opt[1])])68 unmodified lines# ----------------------------------------------------------------------------def custom_data_fn(timestep):s = timestep.statecp = jnp.clip(s.current_place, 0, N_PLACES - 1)cl = jnp.clip(s.chosen_letter, 0, 3)ct = jnp.clip(s.trial, 0, N_TRIALS - 1)pid, gid = "", -110 unmodified linespassreturn dict(pid=pid, gid=gid,mode=s.mode, place=s.current_place, trial=s.trial, n_trials=s.n_trials,practice=s.practice, pair_code=s.pair_code[cp], house_type=s.house_type[cp],left_letter=s.left_letter, right_letter=s.right_letter,left_stim=s.stim_map[s.left_letter], right_stim=s.stim_map[s.right_letter],chosen_side=s.chosen_side, chosen_letter=s.chosen_letter,chosen_stim=s.stim_map[cl],self_outcome=s.last_self_outcome, other_outcome=s.last_other_outcome,self_coins=s.self_coins, other_coins=s.other_coins,rating=s.ratings[cp], rating_cursor=s.rating_cursor,# per-option outcomes THIS trial (for A_self/A_other ... columns), as shown (+/-100/0)opt0_letter=s.place_pairs[cp, 0], opt1_letter=s.place_pairs[cp, 1],opt0_self=s.outcomes[cp, 0, 0, ct], opt0_other=s.outcomes[cp, 0, 1, ct],opt1_self=s.outcomes[cp, 1, 0, ct], opt1_other=s.outcomes[cp, 1, 1, ct],)91 unmodified lines92939495969798991001011021031041051061071081091101113 unmodified lines1151161171181191201211221231246 unmodified lines13113213313413513613713813914014114214314414514614722 unmodified lines1701711721731741751761775 unmodified lines18318418518618718818919019119219319419519613 unmodified lines2102112122132142152162172182192202212222232242251 unmodified line2272282292302312322332342352362375 unmodified lines24324424524624724824925025125225325414 unmodified lines26927027127227327427527629 unmodified lines306307308309310311312313314315316317318319320321322200 unmodified lines52352452552652752852953053153268 unmodified lines60160260360460560660760810 unmodified lines61962062162262362462562662762862963063163263363463563663763863991 unmodified lines# ----------------------------------------------------------------------------@struct.dataclassclass EnvParams:# ---- physical (indexed by place slot 0..11): where/what the houses are ----house_pos: jax.Array # (12,2) positions (one of 5 location layouts)house_type: jax.Array # (12,) 0..12 appearance# ---- by BLOCK (entry order 0..11): the experienced condition sequence (OG-style) ----block_pairs: jax.Array # (12,2) letters per blockpair_code: jax.Array # (12,) per blockside_schedule: jax.Array # (12,N_TRIALS) per blockoutcomes: jax.Array # (12,2,2,N_TRIALS) [block, option, recipient, trial]attention_blocks: jax.Array # (12,) 1 = this block gets a 21st 'attention check' trialfloat_order: jax.Array # (12,) 0 = you-first, 1 = partner-first (per block)stim_map: jax.Array # (4,) letter -> stimulus id (0..23)n_trials: jax.Arrayactive_mask: jax.Array # (12,)practice: jax.Array@struct.dataclass3 unmodified linespartner_pos: jax.Arrayfacing: jax.Arraywalk_frame: jax.Arrayconsumed: jax.Array # (12,) bool (by physical place)current_place: jax.Array # physical house currently incurrent_block: jax.Array # which block (entry order) this house was assignedblocks_entered: jax.Array # how many houses entered so far (= next block to assign)trial: jax.Arrayn_trials: jax.Arraypractice: jax.Array6 unmodified lineslast_self_outcome: jax.Arraylast_other_outcome: jax.Arrayrating_cursor: jax.Arrayratings: jax.Array # (12,) by BLOCK; -1 unrated else 0..6house_pos: jax.Array # (12,2) positions this session (by place)house_active: jax.Array # (12,) boolhouse_type: jax.Array # (12,) by place: appearance / room themeblock_pairs: jax.Array # (12,2) letters, by block (entry order)pair_code: jax.Array # (12,) by blockstim_map: jax.Array # (4,) letter -> stimulus idside_schedule: jax.Array # (12, N_TRIALS) by blockoutcomes: jax.Array # (12,2,2,N_TRIALS) by blockattention_blocks: jax.Array # (12,) by block: 1 = 21st attention-check trialfloat_order: jax.Array # (12,) by block: 0 you-first, 1 partner-firstdef _layout(opt_letters, side_bit):22 unmodified linesfacing=jnp.int32(0), walk_frame=jnp.int32(0),consumed=~active,current_place=jnp.int32(-1),current_block=jnp.int32(-1),blocks_entered=jnp.int32(0),trial=jnp.int32(0),n_trials=params.n_trials,practice=params.practice,5 unmodified linesratings=jnp.full(N_PLACES, -1, jnp.int32),house_pos=params.house_pos.astype(jnp.int32),house_active=active,house_type=params.house_type.astype(jnp.int32),block_pairs=params.block_pairs.astype(jnp.int32),pair_code=params.pair_code.astype(jnp.int32),stim_map=params.stim_map.astype(jnp.int32),side_schedule=params.side_schedule.astype(jnp.int32),outcomes=params.outcomes.astype(jnp.int32),attention_blocks=params.attention_blocks.astype(jnp.int32),float_order=params.float_order.astype(jnp.int32),)return self._obs(s), s13 unmodified linesmatches = jnp.all(s.house_pos == target, axis=1) & s.house_active & (~s.consumed)entering = jnp.any(matches)place_idx = jnp.argmax(matches)# OG-style block order: the Nth house ENTERED gets the Nth pair in the sequenceblock = jnp.clip(s.blocks_entered, 0, N_PLACES - 1)opt = s.block_pairs[block]left, right = _layout(opt, s.side_schedule[block, 0])moved_state = s.replace(agent_pos=target, partner_pos=new_partner,facing=facing, walk_frame=new_walk)enter_state = moved_state.replace(mode=jnp.int32(M_CHOICE), current_place=place_idx, current_block=block,blocks_entered=s.blocks_entered + 1, trial=jnp.int32(0),left_letter=left, right_letter=right, chosen_side=jnp.int32(-1))return _select(entering, enter_state, moved_state)1 unmodified lineis_choice = (action == A_LEFT) | (action == A_RIGHT)chosen_side = jnp.where(action == A_LEFT, jnp.int32(0), jnp.int32(1))chosen_letter = jnp.where(chosen_side == 0, s.left_letter, s.right_letter)# which option of this block's pair (0 or 1), then look up the pre-baked outcomeopt_idx = jnp.where(chosen_letter == s.block_pairs[s.current_block, 0],jnp.int32(0), jnp.int32(1))self_out = s.outcomes[s.current_block, opt_idx, 0, s.trial]other_out = s.outcomes[s.current_block, opt_idx, 1, s.trial]resolved = s.replace(mode=jnp.int32(M_OUTCOME), chosen_side=chosen_side, chosen_letter=chosen_letter,last_self_outcome=self_out, last_other_outcome=other_out,5 unmodified linesnext_trial = s.trial + 1place_done = next_trial >= s.n_trialsnt = jnp.clip(next_trial, 0, N_TRIALS - 1)opt = s.block_pairs[s.current_block]n_left, n_right = _layout(opt, s.side_schedule[s.current_block, nt])next_round = s.replace(mode=jnp.int32(M_CHOICE), trial=next_trial,left_letter=n_left, right_letter=n_right, chosen_side=jnp.int32(-1))# after the 20 trials: an attention-check block gets a 21st check; others -> ratingis_att = s.attention_blocks[s.current_block] > 0to_attention = s.replace(mode=jnp.int32(M_ATTENTION))to_rating = s.replace(mode=jnp.int32(M_RATING), rating_cursor=jnp.int32(RATING_MAX // 2))place_end = _select(is_att, to_attention, to_rating)14 unmodified linescursor = jnp.clip(s.rating_cursor + is_right.astype(jnp.int32) - is_left.astype(jnp.int32),0, RATING_MAX)moved = s.replace(rating_cursor=cursor)new_consumed = s.consumed.at[s.current_place].set(True) # physical house donenew_ratings = s.ratings.at[s.current_block].set(s.rating_cursor) # rating by blockconfirmed = s.replace(mode=jnp.int32(M_OVERWORLD), consumed=new_consumed,ratings=new_ratings, current_place=jnp.int32(-1))new_state = _select(is_confirm, confirmed, moved)29 unmodified lines"""Turn an `orders.make_order(...)` dict into EnvParams (jnp arrays)."""return EnvParams(house_pos=jnp.asarray(order["house_pos"], jnp.int32),house_type=jnp.asarray(order["house_type"], jnp.int32),block_pairs=jnp.asarray(order["block_pairs"], jnp.int32),pair_code=jnp.asarray(order["pair_code"], jnp.int32),side_schedule=jnp.asarray(order["side_schedule"], jnp.int32),outcomes=jnp.asarray(order["outcomes"], jnp.int32),attention_blocks=jnp.asarray(order["attention_blocks"], jnp.int32),float_order=jnp.asarray(order["float_order"], jnp.int32),stim_map=jnp.asarray(order["stim_map"], jnp.int32),n_trials=jnp.int32(n_trials),active_mask=jnp.asarray(active_mask, jnp.int32),practice=jnp.int32(practice),)200 unmodified linesdef _render_rating(s):block_id = _i(s.current_block)cursor = _i(s.rating_cursor)sc, oc = _i(s.self_coins), _i(s.other_coins)opt = np.asarray(s.block_pairs)[block_id]stim_map = np.asarray(s.stim_map)stim_l, stim_r = int(stim_map[int(opt[0])]), int(stim_map[int(opt[1])])68 unmodified lines# ----------------------------------------------------------------------------def custom_data_fn(timestep):s = timestep.statecp = jnp.clip(s.current_place, 0, N_PLACES - 1) # physical housecb = jnp.clip(s.current_block, 0, N_PLACES - 1) # experimental block (entry order)cl = jnp.clip(s.chosen_letter, 0, 3)ct = jnp.clip(s.trial, 0, N_TRIALS - 1)pid, gid = "", -110 unmodified linespassreturn dict(pid=pid, gid=gid,mode=s.mode, block=s.current_block, place=s.current_place,trial=s.trial, n_trials=s.n_trials,practice=s.practice, pair_code=s.pair_code[cb], house_type=s.house_type[cp],float_order=s.float_order[cb],left_letter=s.left_letter, right_letter=s.right_letter,left_stim=s.stim_map[s.left_letter], right_stim=s.stim_map[s.right_letter],chosen_side=s.chosen_side, chosen_letter=s.chosen_letter,chosen_stim=s.stim_map[cl],self_outcome=s.last_self_outcome, other_outcome=s.last_other_outcome,self_coins=s.self_coins, other_coins=s.other_coins,rating=s.ratings[cb], rating_cursor=s.rating_cursor,# per-option outcomes THIS trial (for A_self/A_other ... columns), as shown (+/-10/0)opt0_letter=s.block_pairs[cb, 0], opt1_letter=s.block_pairs[cb, 1],opt0_self=s.outcomes[cb, 0, 0, ct], opt0_other=s.outcomes[cb, 0, 1, ct],opt1_self=s.outcomes[cb, 1, 0, ct], opt1_other=s.outcomes[cb, 1, 1, ct],)
31 unmodified lines323334353637383926 unmodified lines6667686970717244 unmodified lines11711811912012112212312412569 unmodified lines19519619719819920020120220320420521 unmodified lines22722822923023123223323428 unmodified lines2632642652662672682691 unmodified line27127227327427527627732 unmodified lines31031131231331431531631 unmodified linesCOLUMNS = ["row_type", "pid", "gid", "orderID", "practice",# ---- trial ----"blockIndex", "trialIndex", "option_pairs", "option_left", "option_right","left_stim", "left_stim_desc", "right_stim", "right_stim_desc","chosen_side", "chosen_key", "chosen_stim", "chosen_stim_desc","self_outcome", "other_outcome", "shown_self_outcome", "shown_other_outcome",26 unmodified lines"total_self", "total_partner", "money_self", "money_partner","stim_A", "stim_B", "stim_C", "stim_D","stim_A_desc", "stim_B_desc", "stim_C_desc", "stim_D_desc","house_by_place", "pos_by_place", "blocks_visited_order",]44 unmodified lineslast_main_cum = (0, 0)first_ts, last_ts = None, Nonepending_choice_time = Nonevisited = [] # order of main blocks (places) the participant enteredletter2stim = {} # observed reward-profile -> box stimulus id (ground truth)place2house = {} # observed place index -> house namebreaks = [] # (start_iso, end_iso, ms)break_open = None # start time of a break awaiting its 'end'att_total = att_passed = 069 unmodified linespc = int(d["pair_code"])ht = int(d.get("house_type", 0))practice = int(d.get("practice", 0))if practice == 0:last_main_cum = (int(d["self_coins"]), int(d["other_coins"]))if int(d["place"]) not in visited:visited.append(int(d["place"]))place2house[int(d["place"])] = HOUSE_NAMES[ht] if ht < len(HOUSE_NAMES) else htletter2stim[LETTERS[int(d["left_letter"])]] = int(d.get("left_stim", -1))letter2stim[LETTERS[int(d["right_letter"])]] = int(d.get("right_stim", -1))# per-option outcomes this trial -> A_self ... D_other (only the 2 in this pair)21 unmodified lineselse:bo = "tie"rows.append({**base, **info(d), "row_type": "trial","blockIndex": ("practice" if practice else int(d["place"])),"trialIndex": int(d["trial"]),"option_pairs": PAIR_STR.get(pc, ""),"option_left": LETTERS[int(d["left_letter"])],"option_right": LETTERS[int(d["right_letter"])],28 unmodified linesatt_total += 1att_passed += okrows.append({**base, **info(d), "row_type": "attention","attention_blockIndex": int(d["place"]),"attention_key": action,"attention_correct": ok,"attention_rt_ms": rt})1 unmodified lineelif mode == M_RATING and action == "continue":pc = int(d["pair_code"])rows.append({**base, **info(d), "row_type": "rating","rating_blockIndex": ("practice" if int(d.get("practice", 0)) else int(d["place"])),"rating_pair": PAIR_STR.get(pc, ""),"preferred_box_0to6": int(d["rating_cursor"])})32 unmodified linesif sid is not None:summ[f"stim_{letter}"] = sidsumm[f"stim_{letter}_desc"] = _desc(sid)summ["house_by_place"] = "_".join(f"{p}:{place2house[p]}" for p in sorted(place2house))# house positions aren't logged per trial, so re-derive them from the PID (best effort)if orders and pid:try:31 unmodified lines3233343536373839404126 unmodified lines6869707172737444 unmodified lines11912012112212312412512612712869 unmodified lines19819920020120220320420520620720820921021 unmodified lines23223323423523623723823924024124228 unmodified lines2712722732742752762771 unmodified line27928028128228328428532 unmodified lines31831932032132232332432532632732831 unmodified linesCOLUMNS = ["row_type", "pid", "gid", "orderID", "practice",# ---- trial ---- (blockIndex = experienced block 0..11 = OG block order; physical_* = the# house it happened in; float_order = which avatar's coin animates first)"blockIndex", "trialIndex", "physical_place", "physical_house", "float_order","option_pairs", "option_left", "option_right","left_stim", "left_stim_desc", "right_stim", "right_stim_desc","chosen_side", "chosen_key", "chosen_stim", "chosen_stim_desc","self_outcome", "other_outcome", "shown_self_outcome", "shown_other_outcome",26 unmodified lines"total_self", "total_partner", "money_self", "money_partner","stim_A", "stim_B", "stim_C", "stim_D","stim_A_desc", "stim_B_desc", "stim_C_desc", "stim_D_desc","house_by_block", "place_by_block", "house_by_place", "pos_by_place", "blocks_visited_order",]44 unmodified lineslast_main_cum = (0, 0)first_ts, last_ts = None, Nonepending_choice_time = Nonevisited = [] # physical places in entry order (= block order)letter2stim = {} # observed reward-profile -> box stimulus id (ground truth)block2house = {} # block -> physical house nameblock2place = {} # block -> physical place indexbreaks = [] # (start_iso, end_iso, ms)break_open = None # start time of a break awaiting its 'end'att_total = att_passed = 069 unmodified linespc = int(d["pair_code"])ht = int(d.get("house_type", 0))practice = int(d.get("practice", 0))blk = int(d.get("block", d.get("place", 0)))if practice == 0:last_main_cum = (int(d["self_coins"]), int(d["other_coins"]))if int(d["place"]) not in visited:visited.append(int(d["place"]))block2house[blk] = HOUSE_NAMES[ht] if ht < len(HOUSE_NAMES) else htblock2place[blk] = int(d["place"])letter2stim[LETTERS[int(d["left_letter"])]] = int(d.get("left_stim", -1))letter2stim[LETTERS[int(d["right_letter"])]] = int(d.get("right_stim", -1))# per-option outcomes this trial -> A_self ... D_other (only the 2 in this pair)21 unmodified lineselse:bo = "tie"rows.append({**base, **info(d), "row_type": "trial","blockIndex": ("practice" if practice else blk),"trialIndex": int(d["trial"]),"physical_place": int(d["place"]),"physical_house": HOUSE_NAMES[ht] if ht < len(HOUSE_NAMES) else ht,"float_order": ("you-first" if int(d.get("float_order", 0)) == 0 else "partner-first"),"option_pairs": PAIR_STR.get(pc, ""),"option_left": LETTERS[int(d["left_letter"])],"option_right": LETTERS[int(d["right_letter"])],28 unmodified linesatt_total += 1att_passed += okrows.append({**base, **info(d), "row_type": "attention","attention_blockIndex": int(d.get("block", d.get("place", 0))),"attention_key": action,"attention_correct": ok,"attention_rt_ms": rt})1 unmodified lineelif mode == M_RATING and action == "continue":pc = int(d["pair_code"])rows.append({**base, **info(d), "row_type": "rating","rating_blockIndex": ("practice" if int(d.get("practice", 0)) else int(d.get("block", d.get("place", 0)))),"rating_pair": PAIR_STR.get(pc, ""),"preferred_box_0to6": int(d["rating_cursor"])})32 unmodified linesif sid is not None:summ[f"stim_{letter}"] = sidsumm[f"stim_{letter}_desc"] = _desc(sid)# which physical house each experienced BLOCK happened insumm["house_by_block"] = "_".join(f"{b}:{block2house[b]}" for b in sorted(block2house))summ["place_by_block"] = "_".join(f"{b}:{block2place[b]}" for b in sorted(block2place))summ["house_by_place"] = "_".join(f"{block2place[b]}:{block2house[b]}" for b in sorted(block2place))# house positions aren't logged per trial, so re-derive them from the PID (best effort)if orders and pid:try:
49 unmodified lines50515253545556575859606132 unmodified lines9495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401418 unmodified lines1501511521531541551561571581591601611621631641651661671687 unmodified lines17617717817918018118218318418518618718818919019119219319419519619719819917 unmodified lines21721821922022122249 unmodified linesbreakreturn np.array(chosen, dtype=np.int32)# candidate house positions on the 25x25 world (pick & shuffle 12 per participant)CANDIDATE_POS = np.array([[3, 4], [2, 15], [5, 9], [4, 21], [9, 2], [8, 18],[6, 12], [11, 23], [16, 6], [17, 16], [21, 3], [20, 20],[13, 5], [7, 22], [22, 12], [3, 20], [19, 9], [14, 18],], dtype=np.int32)def parse_pid(pid):32 unmodified linesdef make_order(pid):"""Build the full, deterministic order for one participant ID."""group, number = parse_pid(pid)rng = np.random.default_rng(_seed(pid))# assign 4 distinct-coloured boxes (of 24) to the 4 reward-profiles (letters A,B,C,D)stim_map = _distinct_stims(rng, 4) # letter -> stimulus id# block order: shuffle the 12 places (each pair appears twice)block_order = rng.permutation(N_PLACES)place_pairs = np.array([PLACE_PAIRS[i] for i in block_order], dtype=np.int32) # (12,2) letterspair_code = np.array([PAIRS.index(tuple(PLACE_PAIRS[i])) for i in block_order], dtype=np.int32)# pair -> house: assign the 12 distinct houses to the 12 placeshouse_type = rng.permutation(N_PLACES).astype(np.int32) # (12,) distinct house ids 0..11# house positions on the mappos_idx = rng.permutation(len(CANDIDATE_POS))[:N_PLACES]house_pos = CANDIDATE_POS[pos_idx].astype(np.int32) # (12,2)# which option is on the LEFT each trial (0 => place_pairs[:,0] on left)side_schedule = rng.integers(0, 2, size=(N_PLACES, N_TRIALS)).astype(np.int32)# exact outcomes: [place, option(0/1), recipient(0 self/1 partner), trial]outcomes = np.zeros((N_PLACES, 2, 2, N_TRIALS), dtype=np.int32)for p in range(N_PLACES):for o in range(2):letter = int(place_pairs[p, o])outcomes[p, o, 0] = _exact_sequence(LETTER_SELF_GOOD[letter], rng)outcomes[p, o, 1] = _exact_sequence(LETTER_OTHER_GOOD[letter], rng)# 2 random houses get a 21st 'attention check' trial (drawn last, so it doesn't shift# the outcome stream above)attention_places = np.zeros(N_PLACES, dtype=np.int32)attention_places[rng.choice(N_PLACES, size=2, replace=False)] = 1return dict(pid=str(pid), group=group, number=number,orderID=number, stim_map=stim_map,block_order=block_order.tolist(),block_pairs_str="_".join(LETTERS[a] + LETTERS[b] for a, b in place_pairs.tolist()),place_pairs=place_pairs, pair_code=pair_code, house_type=house_type,house_pos=house_pos, side_schedule=side_schedule, outcomes=outcomes,attention_places=attention_places,)8 unmodified linesrng = np.random.default_rng(_seed(pid) ^ 0x9E3779B9) # distinct practice stream per pido["house_pos"] = o["house_pos"].copy()o["house_pos"][0] = [12, 16] # near the start tileo["place_pairs"] = o["place_pairs"].copy()o["place_pairs"][0] = [0, 1] # pair AB (A=good/good, B=good/bad)o["pair_code"] = o["pair_code"].copy()o["pair_code"][0] = 0o["house_type"] = o["house_type"].copy()o["house_type"][0] = 12 # practice-only forest huto["stim_map"] = o["stim_map"].copy()o["stim_map"][0], o["stim_map"][1] = 24, 25 # practice-only boxes (not in main pool)o["attention_places"] = np.zeros(N_PLACES, dtype=np.int32) # no attention check in practiceo["side_schedule"] = o["side_schedule"].copy()o["side_schedule"][0] = rng.integers(0, 2, size=N_TRIALS).astype(np.int32) # randomise sideso["outcomes"] = o["outcomes"].copy()for opt, letter in enumerate([0, 1]): # rebuild place-0 outcomes for ABo["outcomes"][0, opt, 0] = _exact_sequence(LETTER_SELF_GOOD[letter], rng)o["outcomes"][0, opt, 1] = _exact_sequence(LETTER_OTHER_GOOD[letter], rng)return o7 unmodified linesdef manifest_row(pid):"""One flat, self-describing row summarising a participant's randomisation.Everything indexed 'by place' uses the SAME place slot 0..11, so pair_by_place[i],house_by_place[i] and pos_by_place[i] all describe the same house. (The order aparticipant actually *visits* houses is their own free choice -> see`blocks_visited_order` in the per-participant data CSV, not here.)"""import sprites # lazy: only needed when actually loggingo = make_order(pid)sm = o["stim_map"].tolist()ht = o["house_type"].tolist()pairs = o["block_pairs_str"].split("_") # pair assigned to each place slotrow = dict(pid=o["pid"], gid=o["group"],group=GROUP_LABELS.get(o["group"], o["group"]), orderID=o["orderID"],partner_id=partner_id_for(pid))for k, L in enumerate(LETTERS): # profile -> stimulus id + readable lookrow[f"{L}_stim"] = sm[k]for k, L in enumerate(LETTERS):row[f"{L}_stim_desc"] = sprites.stim_describe(sm[k])row["pair_by_place"] = "_".join(f"{i}:{p}" for i, p in enumerate(pairs))row["house_by_place"] = "_".join(f"{i}:{HOUSE_NAMES[h] if h < len(HOUSE_NAMES) else h}" for i, h in enumerate(ht))row["pos_by_place"] = "_".join(17 unmodified lines# 4 distinct stimuli drawn from the 24-box poolsm = o["stim_map"]assert len(set(sm.tolist())) == 4 and all(0 <= x < N_STIM for x in sm)print("orders.py self-tests passed.\n")print("Sample manifest rows:")for pid in ["0001", "0002", "0003", "0004", "1001", "1002"]:49 unmodified lines505152535455565758596061626364656667686932 unmodified lines1021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551568 unmodified lines1651661671681691701711721731741751761771781791801811821837 unmodified lines19119219319419519619719819920020120220320420520620720820921021121221321421521617 unmodified lines23423523623723823924024124224324424524624724849 unmodified linesbreakreturn np.array(chosen, dtype=np.int32)# 5 FIXED house-location layouts on the 25x25 world (avoid the start tile [12,12]). The# participant's layout = number % N_LAYOUTS (counterbalanced). Locations are decoupled from# the block order: WHERE a house sits is just one of these 5 maps; WHICH condition (pair) it# holds is set by the order the participant enters houses (see make_order).N_LAYOUTS = 5_GRIDS = [([3, 8, 16, 21], [4, 12, 20]),([4, 9, 15, 22], [6, 13, 21]),([2, 9, 16, 23], [3, 11, 19]),([5, 10, 17, 22], [5, 13, 21]),([3, 10, 16, 21], [4, 14, 22]),]LOCATION_LAYOUTS = np.array([[[r, c] for r in rows for c in cols] for rows, cols in _GRIDS], dtype=np.int32) # (5,12,2)def parse_pid(pid):32 unmodified linesdef make_order(pid):"""Build the full, deterministic order for one participant ID.Like the ORIGINAL task: the BLOCK ORDER (sequence of the 12 option-pairs) is fixed perID, and the Nth house the participant *enters* receives the Nth pair — independent ofwhere the houses sit (that's set by one of 5 fixed location layouts). So `block_pairs`,`pair_code`, `side_schedule`, `outcomes`, `attention_blocks`, `float_order` are allindexed by BLOCK (0..11 = entry order); `house_type` and `house_pos` are physical."""group, number = parse_pid(pid)rng = np.random.default_rng(_seed(pid))# assign 4 distinct-coloured boxes (of 24) to the 4 reward-profiles (letters A,B,C,D)stim_map = _distinct_stims(rng, 4) # letter -> stimulus id# BLOCK ORDER: a shuffle of the 12 canonical pairs (each pair twice) = the experienced orderblock_order = rng.permutation(N_PLACES)block_pairs = np.array([PLACE_PAIRS[i] for i in block_order], dtype=np.int32) # (12,2)pair_code = np.array([PAIRS.index(tuple(PLACE_PAIRS[i])) for i in block_order], dtype=np.int32)# which option is on the LEFT each trial, per block (0 => block_pairs[:,0] on left)side_schedule = rng.integers(0, 2, size=(N_PLACES, N_TRIALS)).astype(np.int32)# exact outcomes per block: [block, option(0/1), recipient(0 self/1 partner), trial]outcomes = np.zeros((N_PLACES, 2, 2, N_TRIALS), dtype=np.int32)for b in range(N_PLACES):for o in range(2):letter = int(block_pairs[b, o])outcomes[b, o, 0] = _exact_sequence(LETTER_SELF_GOOD[letter], rng)outcomes[b, o, 1] = _exact_sequence(LETTER_OTHER_GOOD[letter], rng)# 2 random BLOCKS get a 21st 'attention check' trialattention_blocks = np.zeros(N_PLACES, dtype=np.int32)attention_blocks[rng.choice(N_PLACES, size=2, replace=False)] = 1# coin-float order per block: 6 you-first (0) + 6 partner-first (1), counterbalancedfloat_order = np.array([0] * (N_PLACES // 2) + [1] * (N_PLACES // 2), dtype=np.int32)rng.shuffle(float_order)# PHYSICAL houses: appearance (random per participant) + 1 of 5 fixed location layoutshouse_type = rng.permutation(N_PLACES).astype(np.int32) # (12,) appearance per placelayout_id = int(number % N_LAYOUTS)house_pos = LOCATION_LAYOUTS[layout_id].astype(np.int32) # (12,2) positions per placereturn dict(pid=str(pid), group=group, number=number, orderID=number, stim_map=stim_map,block_order=block_order.tolist(),block_pairs_str="_".join(LETTERS[a] + LETTERS[b] for a, b in block_pairs.tolist()),block_pairs=block_pairs, pair_code=pair_code, side_schedule=side_schedule,outcomes=outcomes, attention_blocks=attention_blocks, float_order=float_order,house_type=house_type, house_pos=house_pos, layout_id=layout_id,)8 unmodified linesrng = np.random.default_rng(_seed(pid) ^ 0x9E3779B9) # distinct practice stream per pido["house_pos"] = o["house_pos"].copy()o["house_pos"][0] = [12, 16] # near the start tileo["block_pairs"] = o["block_pairs"].copy()o["block_pairs"][0] = [0, 1] # block 0 = pair AB (A=good/good, B=good/bad)o["pair_code"] = o["pair_code"].copy()o["pair_code"][0] = 0o["house_type"] = o["house_type"].copy()o["house_type"][0] = 12 # practice-only forest huto["stim_map"] = o["stim_map"].copy()o["stim_map"][0], o["stim_map"][1] = 24, 25 # practice-only boxes (not in main pool)o["attention_blocks"] = np.zeros(N_PLACES, dtype=np.int32) # no attention check in practiceo["side_schedule"] = o["side_schedule"].copy()o["side_schedule"][0] = rng.integers(0, 2, size=N_TRIALS).astype(np.int32) # randomise sideso["outcomes"] = o["outcomes"].copy()for opt, letter in enumerate([0, 1]): # rebuild block-0 outcomes for ABo["outcomes"][0, opt, 0] = _exact_sequence(LETTER_SELF_GOOD[letter], rng)o["outcomes"][0, opt, 1] = _exact_sequence(LETTER_OTHER_GOOD[letter], rng)return o7 unmodified linesdef manifest_row(pid):"""One flat, self-describing row summarising a participant's randomisation.`block_order` is the fixed sequence of pairs the participant experiences (block 0,1,2,…),matching the original task: the Nth house entered = the Nth pair here. House appearanceand position are physical (by place slot), set by the `layout_id` location layout."""import sprites # lazy: only needed when actually loggingo = make_order(pid)sm = o["stim_map"].tolist()ht = o["house_type"].tolist()pairs = o["block_pairs_str"].split("_") # pair for each BLOCK (entry order)row = dict(pid=o["pid"], gid=o["group"],group=GROUP_LABELS.get(o["group"], o["group"]), orderID=o["orderID"],partner_id=partner_id_for(pid), layout_id=o["layout_id"])for k, L in enumerate(LETTERS): # profile -> stimulus id + readable lookrow[f"{L}_stim"] = sm[k]for k, L in enumerate(LETTERS):row[f"{L}_stim_desc"] = sprites.stim_describe(sm[k])row["block_order"] = "_".join(f"{i}:{p}" for i, p in enumerate(pairs))row["float_order"] = "_".join(f"{i}:{'you' if f == 0 else 'partner'}-first" for i, f in enumerate(o["float_order"].tolist()))row["attention_blocks"] = "_".join(str(i) for i, a in enumerate(o["attention_blocks"].tolist()) if a)row["house_by_place"] = "_".join(f"{i}:{HOUSE_NAMES[h] if h < len(HOUSE_NAMES) else h}" for i, h in enumerate(ht))row["pos_by_place"] = "_".join(17 unmodified lines# 4 distinct stimuli drawn from the 24-box poolsm = o["stim_map"]assert len(set(sm.tolist())) == 4 and all(0 <= x < N_STIM for x in sm)# block-order scheme: 6/6 float order, 2 attention blocks, valid layout, distinct positionsassert o["float_order"].sum() == 6 and len(o["float_order"]) == N_PLACESassert o["attention_blocks"].sum() == 2assert 0 <= o["layout_id"] < N_LAYOUTSassert len({tuple(p) for p in o["house_pos"].tolist()}) == N_PLACES# the 5 layouts are distinct and avoid the start tileseen = [tuple(map(tuple, L.tolist())) for L in LOCATION_LAYOUTS]assert len(set(seen)) == N_LAYOUTSassert all([12, 12] not in L.tolist() for L in LOCATION_LAYOUTS)print("orders.py self-tests passed.\n")print("Sample manifest rows:")for pid in ["0001", "0002", "0003", "0004", "1001", "1002"]: