Download survey_apps/main_study/verify_randomization.js from sciminds/same-words-different-judgements: direct link, hf CLI and curl.
- Browser
- Download file 6.41 kB
-
https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/verify_randomization.js
- Command line
-
hf download hf://datasets/sciminds/same-words-different-judgements/survey_apps/main_study/verify_randomization.js
-
curl -L -o verify_randomization.js https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/verify_randomization.js
6.41 kB
| // Simulation script to verify deterministic assignment logic | |
| const TRIALS_PER_PARTICIPANT = 20; | |
| const TOTAL_TRIALS = 100; // Adjust to match your survey_data.json length | |
| const NUM_BLOCKS = Math.ceil(TOTAL_TRIALS / TRIALS_PER_PARTICIPANT); | |
| const NUM_PARTICIPANTS = 100; // Simulate 100 participants | |
| console.log("=== RANDOMIZATION VERIFICATION ===\n"); | |
| console.log(`Total Trials: ${TOTAL_TRIALS}`); | |
| console.log(`Trials per Participant: ${TRIALS_PER_PARTICIPANT}`); | |
| console.log(`Number of Blocks: ${NUM_BLOCKS}`); | |
| console.log(`Simulating ${NUM_PARTICIPANTS} participants\n`); | |
| // Track assignments | |
| const participants = []; | |
| const trialCoverage = {}; // trialId -> { text: { order_1_2: count, order_2_1: count }, audio: {...} } | |
| // Initialize trial coverage tracking | |
| for (let trialId = 0; trialId < TOTAL_TRIALS; trialId++) { | |
| trialCoverage[trialId] = { | |
| text: { order_1_2: 0, order_2_1: 0 }, | |
| audio: { order_1_2: 0, order_2_1: 0 } | |
| }; | |
| } | |
| // Simulate participant assignments | |
| for (let participantNumber = 0; participantNumber < NUM_PARTICIPANTS; participantNumber++) { | |
| // 1. Assign modality (deterministic) | |
| const modality = participantNumber % 2 === 0 ? "text" : "audio"; | |
| // 2. Assign block (round-robin) | |
| const blockIndex = participantNumber % NUM_BLOCKS; | |
| // 3. Assign order (deterministic) | |
| const orderFlip = Math.floor(participantNumber / 2) % 2; | |
| const order = orderFlip === 0 ? [1, 2] : [2, 1]; | |
| const orderKey = order[0] === 1 ? "order_1_2" : "order_2_1"; | |
| // 4. Get trials for this block | |
| const startIdx = blockIndex * TRIALS_PER_PARTICIPANT; | |
| const endIdx = Math.min(startIdx + TRIALS_PER_PARTICIPANT, TOTAL_TRIALS); | |
| let blockTrials = []; | |
| for (let i = startIdx; i < endIdx; i++) { | |
| blockTrials.push(i); | |
| } | |
| // If last block has fewer than 20 trials, wrap around | |
| if (blockTrials.length < TRIALS_PER_PARTICIPANT) { | |
| const needed = TRIALS_PER_PARTICIPANT - blockTrials.length; | |
| for (let i = 0; i < needed; i++) { | |
| blockTrials.push(i); | |
| } | |
| } | |
| // Record this participant | |
| participants.push({ | |
| participantNumber, | |
| modality, | |
| blockIndex, | |
| order, | |
| trialIds: blockTrials | |
| }); | |
| // Update trial coverage | |
| blockTrials.forEach(trialId => { | |
| trialCoverage[trialId][modality][orderKey]++; | |
| }); | |
| } | |
| // === VERIFICATION RESULTS === | |
| console.log("=== MODALITY DISTRIBUTION ==="); | |
| const modalityCounts = { text: 0, audio: 0 }; | |
| participants.forEach(p => modalityCounts[p.modality]++); | |
| console.log(`Text: ${modalityCounts.text} participants (${(modalityCounts.text/NUM_PARTICIPANTS*100).toFixed(1)}%)`); | |
| console.log(`Audio: ${modalityCounts.audio} participants (${(modalityCounts.audio/NUM_PARTICIPANTS*100).toFixed(1)}%)`); | |
| console.log(`✓ Expected: 50/50 split\n`); | |
| console.log("=== BLOCK DISTRIBUTION ==="); | |
| const blockCounts = {}; | |
| for (let i = 0; i < NUM_BLOCKS; i++) { | |
| blockCounts[i] = { text: 0, audio: 0 }; | |
| } | |
| participants.forEach(p => { | |
| blockCounts[p.blockIndex][p.modality]++; | |
| }); | |
| console.log("Block | Text | Audio | Total"); | |
| console.log("------|------|-------|------"); | |
| for (let i = 0; i < NUM_BLOCKS; i++) { | |
| const text = blockCounts[i].text; | |
| const audio = blockCounts[i].audio; | |
| const total = text + audio; | |
| console.log(` ${i} | ${text.toString().padStart(2)} | ${audio.toString().padStart(2)} | ${total.toString().padStart(2)}`); | |
| } | |
| console.log(`✓ Expected: Each block gets equal text/audio participants\n`); | |
| console.log("=== ORDER DISTRIBUTION (OVERALL) ==="); | |
| const orderCounts = { | |
| text: { order_1_2: 0, order_2_1: 0 }, | |
| audio: { order_1_2: 0, order_2_1: 0 } | |
| }; | |
| participants.forEach(p => { | |
| const orderKey = p.order[0] === 1 ? "order_1_2" : "order_2_1"; | |
| orderCounts[p.modality][orderKey]++; | |
| }); | |
| console.log(`Text - [1,2]: ${orderCounts.text.order_1_2} participants, [2,1]: ${orderCounts.text.order_2_1} participants`); | |
| console.log(`Audio - [1,2]: ${orderCounts.audio.order_1_2} participants, [2,1]: ${orderCounts.audio.order_2_1} participants`); | |
| console.log(`✓ Expected: 50/50 split within each modality\n`); | |
| console.log("=== TRIAL COVERAGE ANALYSIS ==="); | |
| let perfectCoverage = true; | |
| const coverageIssues = []; | |
| for (let trialId = 0; trialId < TOTAL_TRIALS; trialId++) { | |
| const coverage = trialCoverage[trialId]; | |
| const textTotal = coverage.text.order_1_2 + coverage.text.order_2_1; | |
| const audioTotal = coverage.audio.order_1_2 + coverage.audio.order_2_1; | |
| const expectedPerModality = NUM_PARTICIPANTS / NUM_BLOCKS / 2; // 100 / 5 / 2 = 10 | |
| const expectedPerOrder = expectedPerModality / 2; // 10 / 2 = 5 | |
| if (textTotal !== expectedPerModality || audioTotal !== expectedPerModality || | |
| coverage.text.order_1_2 !== expectedPerOrder || coverage.text.order_2_1 !== expectedPerOrder || | |
| coverage.audio.order_1_2 !== expectedPerOrder || coverage.audio.order_2_1 !== expectedPerOrder) { | |
| perfectCoverage = false; | |
| coverageIssues.push({ | |
| trialId, | |
| text: `${coverage.text.order_1_2}+${coverage.text.order_2_1}=${textTotal}`, | |
| audio: `${coverage.audio.order_1_2}+${coverage.audio.order_2_1}=${audioTotal}` | |
| }); | |
| } | |
| } | |
| if (perfectCoverage) { | |
| console.log(`✓ Perfect coverage! All ${TOTAL_TRIALS} trials have:`); | |
| console.log(` - 10 text ratings (5 with [1,2], 5 with [2,1])`); | |
| console.log(` - 10 audio ratings (5 with [1,2], 5 with [2,1])`); | |
| } else { | |
| console.log(`✗ Coverage issues found for ${coverageIssues.length} trials:`); | |
| console.log("\nTrial | Text ([1,2]+[2,1]=Total) | Audio ([1,2]+[2,1]=Total)"); | |
| console.log("------|---------------------------|---------------------------"); | |
| coverageIssues.slice(0, 10).forEach(issue => { | |
| console.log(`${issue.trialId.toString().padStart(5)} | ${issue.text.padEnd(25)} | ${issue.audio}`); | |
| }); | |
| if (coverageIssues.length > 10) { | |
| console.log(`... and ${coverageIssues.length - 10} more`); | |
| } | |
| } | |
| console.log("\n=== SAMPLE PARTICIPANT ASSIGNMENTS ==="); | |
| console.log("P# | Modality | Block | Order | First 5 Trial IDs"); | |
| console.log("---|----------|-------|--------|------------------"); | |
| [0, 1, 2, 3, 10, 11, 20, 21, 50, 51].forEach(pNum => { | |
| const p = participants[pNum]; | |
| const orderStr = `[${p.order.join(',')}]`; | |
| const trialsStr = p.trialIds.slice(0, 5).join(','); | |
| console.log(`${p.participantNumber.toString().padStart(2)} | ${p.modality.padEnd(8)} | ${p.blockIndex.toString().padStart(5)} | ${orderStr.padEnd(6)} | ${trialsStr}`); | |
| }); | |
| console.log("\n=== VERIFICATION COMPLETE ==="); | |