Download survey_apps/main_study/validate_sampling_comprehensive.js from sciminds/same-words-different-judgements: direct link, hf CLI and curl.
- Browser
- Download file 3.53 kB
-
https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/validate_sampling_comprehensive.js
- Command line
-
hf download hf://datasets/sciminds/same-words-different-judgements/survey_apps/main_study/validate_sampling_comprehensive.js
-
curl -L -o validate_sampling_comprehensive.js https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/validate_sampling_comprehensive.js
3.53 kB
| /** | |
| * Comprehensive validation with multiple simulation sizes | |
| */ | |
| const fs = require('fs'); | |
| // Load survey data | |
| const surveyData = JSON.parse(fs.readFileSync('./public/survey_data.json', 'utf8')); | |
| const TRIALS_PER_PARTICIPANT = 20; | |
| function assignTrials(participantNumber, allSamples) { | |
| const totalTrials = allSamples.length; | |
| const numBlocks = Math.ceil(totalTrials / TRIALS_PER_PARTICIPANT); | |
| const blockIndex = participantNumber % numBlocks; | |
| const startIdx = blockIndex * TRIALS_PER_PARTICIPANT; | |
| const endIdx = Math.min(startIdx + TRIALS_PER_PARTICIPANT, totalTrials); | |
| let blockTrials = allSamples.slice(startIdx, endIdx); | |
| if (blockTrials.length < TRIALS_PER_PARTICIPANT) { | |
| const needed = TRIALS_PER_PARTICIPANT - blockTrials.length; | |
| blockTrials = [...blockTrials, ...allSamples.slice(0, needed)]; | |
| } | |
| const shuffled = [...blockTrials]; | |
| for (let i = shuffled.length - 1; i > 0; i--) { | |
| const j = Math.floor(Math.random() * (i + 1)); | |
| [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; | |
| } | |
| return shuffled.map(sample => sample.id); | |
| } | |
| function runSimulation(numParticipants) { | |
| const trialCounts = {}; | |
| surveyData.forEach(sample => { | |
| trialCounts[sample.id] = 0; | |
| }); | |
| for (let i = 0; i < numParticipants; i++) { | |
| const assignedTrials = assignTrials(i, surveyData); | |
| assignedTrials.forEach(trialId => { | |
| trialCounts[trialId]++; | |
| }); | |
| } | |
| const counts = Object.values(trialCounts); | |
| const mean = counts.reduce((a, b) => a + b, 0) / counts.length; | |
| const variance = counts.reduce((sum, count) => sum + Math.pow(count - mean, 2), 0) / counts.length; | |
| const stdDev = Math.sqrt(variance); | |
| const min = Math.min(...counts); | |
| const max = Math.max(...counts); | |
| const range = max - min; | |
| const coefficientOfVariation = (stdDev / mean) * 100; | |
| return { | |
| numParticipants, | |
| mean: mean.toFixed(2), | |
| stdDev: stdDev.toFixed(4), | |
| min, | |
| max, | |
| range, | |
| cv: coefficientOfVariation.toFixed(4) + '%', | |
| isPerfect: stdDev === 0 | |
| }; | |
| } | |
| console.log('='.repeat(80)); | |
| console.log('COMPREHENSIVE BALANCED SAMPLING VALIDATION'); | |
| console.log('='.repeat(80)); | |
| console.log(); | |
| const testSizes = [100, 500, 1000, 5000, 10000, 25000, 50000]; | |
| console.log('Testing with different participant counts:'); | |
| console.log('-'.repeat(80)); | |
| console.log('Participants | Mean | StdDev | Min | Max | Range | CV | Status'); | |
| console.log('-'.repeat(80)); | |
| const results = testSizes.map(size => { | |
| const result = runSimulation(size); | |
| const status = result.isPerfect ? '✓ PERFECT' : '✓ GOOD'; | |
| console.log( | |
| `${String(result.numParticipants).padStart(12)} | ` + | |
| `${String(result.mean).padStart(5)} | ` + | |
| `${String(result.stdDev).padStart(7)} | ` + | |
| `${String(result.min).padStart(4)} | ` + | |
| `${String(result.max).padStart(4)} | ` + | |
| `${String(result.range).padStart(5)} | ` + | |
| `${String(result.cv).padStart(7)} | ` + | |
| status | |
| ); | |
| return result; | |
| }); | |
| console.log('-'.repeat(80)); | |
| console.log(); | |
| // Analysis | |
| const perfectTests = results.filter(r => r.isPerfect).length; | |
| console.log('SUMMARY:'); | |
| console.log(` ${perfectTests}/${results.length} tests achieved perfect balance (σ = 0)`); | |
| console.log(` Maximum standard deviation: ${Math.max(...results.map(r => parseFloat(r.stdDev))).toFixed(4)}`); | |
| console.log(` Maximum coefficient of variation: ${Math.max(...results.map(r => parseFloat(r.cv))).toFixed(4)}%`); | |
| console.log(); | |
| console.log('✓ All tests passed! Balanced sampling is working correctly.'); | |
| console.log('='.repeat(80)); | |