Experiments¶
The simulation studies behind the paper. These are entry points for reproducing results, not part of the modelling API.
Cohort simulation¶
photosvi.experiments.cohort.CohortSpec
dataclass
¶
CohortSpec(n_animals=8, design='crossed', mu_drug=(0.2, 1.1, 1.39), sigma_animal=0.25, sigma_cell=0.1, beta0_mean=-2.85, sigma_b0=0.22, sigma_b0_session=0.2, sigma_y=0.1062, mu_a=1.7666, sigma_a=0.212, fs=25, T=60000, inj_t=15000, inj_jitter=1500, tonic_b=-0.3406, tonic_peak=(0.4618802153517006, 3.939445759311477, 3.209953463886826), tonic_k_rise=(0.006, 0.005, 0.014), tonic_k_decay=(0.002, 0.0009, 0.0028), tonic_drift=-7.92, ou_sd=0.0, ou_tau=0.7, ar_rho=0.0, ar_coeffs=None, kernel_length=125, kernel=(lambda: dict(family='biphasic', k_rise_fast=20.0, k_decay_fast=9.0, k_rise_slow=8.0, k_decay_slow=3.5))())
The generative truth for one simulated cohort.
mu_drug is on the log-rate-ratio axis: mu_drug[d] is the mean log ratio of
post- to pre-injection event rate under drug d. The estimand of the study is the
contrast mu_drug[OPIOID2] - mu_drug[OPIOID1]; mu_drug[SALINE] is the
handling response the vehicle sessions control for.
tonic_peak_s ¶
tonic_peak_s(d)
Bateman peak time for drug d, in seconds after injection.
Source code in src/photosvi/experiments/cohort.py
164 165 166 167 | |
indices ¶
indices()
(animal, drug) per session, for whichever design this spec names.
The two designs are the extremes an experimenter actually chooses between, and they differ in what the opioid-versus-opioid contrast is:
crossed-- every animal receives every drug. The contrast is within-animal, so the animal effect enters both of its terms and cancels, exactly as it does in a paired test. What is left governing the width is the animal x drug interaction.uncrossed-- every animal receives vehicle and exactly one opioid, alternating which. The contrast is now between-animal: nothing cancels, and the between-animal spread enters it directly. It is also the design in which each animal x drug cell holds a single session, so the interaction and a session residual are the same partition and only one of them can be identified --_detect_levelsis what decides that, from the indices.
Both are generated at the same number of RECORDINGS, which is the thing an experiment pays for: 8 animals x 3 sessions and 12 animals x 2 sessions are both 24. Comparing them at equal animal counts instead would confound the design with the sample size and answer a question nobody is asking.
Source code in src/photosvi/experiments/cohort.py
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
photosvi.experiments.cohort.spec_from_config ¶
spec_from_config(cfg, delta)
Build the cohort truth from the study config and one effect size.
The single definition of the simulated truth. Both arms of the comparison call this; duplicating the construction in each worker is how two arms end up quietly fitting different data while every test still passes, and the resulting comparison would be meaningless in a way nothing downstream could detect.
delta places the second opioid above the first on the log-rate axis, so
delta = 0 is the null: both drugs active, indistinguishable from each other.
Two conditions instead of three when the config omits mu_opioid1, which is the
design the recordings actually have: a vehicle arm and a treated arm, with delta the
difference between them. The three-drug form is kept because the shipped study uses it
and its tonic and effect vectors are indexed by drug; a config that names mu_opioid1
gets exactly the cohorts it always did.
Source code in src/photosvi/experiments/cohort.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
photosvi.experiments.cohort.simulate_cohort ¶
simulate_cohort(spec, seed)
Generate one cohort. Deterministic in (spec, seed).
Returns y [S, T] plus the indices, the injection bins and the per-session
truth: the coefficients actually drawn, and the count MLE of beta_inj from the
realized onsets -- which is the best any method could do on that recording, and
therefore the right reference for a per-session estimate.
Source code in src/photosvi/experiments/cohort.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |