@adriansteffan/reactive 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +13 -1
- package/README.md +184 -5
- package/dist/{mod-Bb_FAy0j.js → mod-DRCLdWzq.js} +31177 -14827
- package/dist/mod.d.ts +40 -1
- package/dist/reactive.es.js +36 -29
- package/dist/reactive.umd.js +10202 -55
- package/dist/style.css +1 -1
- package/dist/{web-DmsP-pmx.js → web-CWqttxrD.js} +1 -1
- package/dist/{web-BfWhpr9p.js → web-N9H86cSP.js} +1 -1
- package/package.json +8 -1
- package/src/components/canvasblock.tsx +4 -3
- package/src/components/plaininput.tsx +2 -1
- package/src/components/quest.tsx +8 -7
- package/src/components/randomdotkinetogram.tsx +3 -2
- package/src/components/text.tsx +2 -1
- package/src/components/upload.tsx +2 -1
- package/src/mod.tsx +2 -0
- package/src/utils/array.ts +4 -2
- package/src/utils/distributions.test.ts +209 -0
- package/src/utils/distributions.ts +191 -0
- package/src/utils/simulation.ts +9 -4
- package/template/simulate.ts +24 -4
- package/template/src/Experiment.tsx +7 -9
package/template/simulate.ts
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import { orchestrateSimulation, simulateParticipant, setBackendUrl } from '@adriansteffan/reactive';
|
|
2
|
-
import { experiment, simulationConfig } from './src/Experiment';
|
|
1
|
+
import { orchestrateSimulation, simulateParticipant, setBackendUrl, seedDistributions } from '@adriansteffan/reactive';
|
|
3
2
|
|
|
4
3
|
// Each simulated participant runs as a separate subprocess to get fresh module-level
|
|
5
4
|
// randomization (e.g., group assignment). The orchestrator spawns workers that re-run
|
|
6
5
|
// this script with _REACTIVE_WORKER_INDEX set.
|
|
6
|
+
//
|
|
7
|
+
// Experiment.tsx is imported dynamically so that seeding happens before module-level
|
|
8
|
+
// code runs. If participants is a factory function, it is called with the base seed
|
|
9
|
+
// for deterministic generation, then re-seeded per-worker for the simulation.
|
|
7
10
|
if (process.env._REACTIVE_WORKER_INDEX) {
|
|
8
11
|
const index = parseInt(process.env._REACTIVE_WORKER_INDEX);
|
|
9
|
-
const
|
|
10
|
-
|
|
12
|
+
const seed = process.env._REACTIVE_SIMULATION_SEED;
|
|
13
|
+
if (seed) seedDistributions(parseInt(seed) + index);
|
|
11
14
|
setBackendUrl(process.env._REACTIVE_BACKEND_URL!);
|
|
15
|
+
|
|
16
|
+
const { experiment, simulationConfig } = await import('./src/Experiment');
|
|
17
|
+
const participants = simulationConfig.participants;
|
|
18
|
+
|
|
19
|
+
let participant;
|
|
20
|
+
if (typeof participants === 'function') {
|
|
21
|
+
if (seed) seedDistributions(parseInt(seed));
|
|
22
|
+
const allParticipants = participants();
|
|
23
|
+
if (seed) seedDistributions(parseInt(seed) + index);
|
|
24
|
+
participant = allParticipants[index];
|
|
25
|
+
} else if (Array.isArray(participants)) {
|
|
26
|
+
participant = participants[index];
|
|
27
|
+
} else {
|
|
28
|
+
participant = participants.generator(index);
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
await simulateParticipant(experiment, participant);
|
|
13
32
|
} else {
|
|
33
|
+
const { simulationConfig } = await import('./src/Experiment');
|
|
14
34
|
await orchestrateSimulation(simulationConfig, import.meta.filename);
|
|
15
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { useState, useRef } from 'react';
|
|
3
|
-
import { ExperimentRunner, BaseComponentProps, ExperimentConfig, registerSimulation, registerFlattener } from '@adriansteffan/reactive';
|
|
3
|
+
import { ExperimentRunner, BaseComponentProps, ExperimentConfig, registerSimulation, registerFlattener, sampleParticipants } from '@adriansteffan/reactive';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const config: ExperimentConfig = { showProgressBar: true };
|
|
@@ -165,13 +165,11 @@ export default function Experiment() {
|
|
|
165
165
|
|
|
166
166
|
// --- Simulation config ---
|
|
167
167
|
// Define how simulated participants are generated.
|
|
168
|
-
//
|
|
168
|
+
// Use a factory function for participants: the framework seeds it with the base seed,
|
|
169
|
+
// so every worker generates the same participant list regardless of its per-worker seed.
|
|
169
170
|
export const simulationConfig = {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}),
|
|
175
|
-
count: 10,
|
|
176
|
-
},
|
|
171
|
+
seed: 42,
|
|
172
|
+
participants: () => sampleParticipants('sobol', 10, {
|
|
173
|
+
needForCognition: { distribution: 'normal', mean: 3.5, sd: 0.8 },
|
|
174
|
+
}).map((p, i) => ({ ...p, id: i, nickname: `participant_${i}` })),
|
|
177
175
|
};
|