Anisotropic Model
scripts/PyMC_Pytensor_noise_v_main_varsig_aniso.py
Samples the scalar Lorentz-violation magnitude \(B_0\) and the 3-vector \(\vec{B}\) using a custom log-likelihood for transverse velocity data. The critical velocity \(w_c\) varies per observation depending on the sky direction \(\hat{n}\).
Usage
python scripts/PyMC_Pytensor_noise_v_main_varsig_aniso.py
When using simulated data, the script calls regenerate_data() at startup to produce a fresh generated_sources.csv before sampling.
Configuration
All settings are at the top of the file. Adjust before each run.
| Variable | Default | Description |
|---|---|---|
DATASET |
"generated_sources.csv" |
Input CSV. Set to "mojave_cleaned.csv" for real data. |
N_VAL |
20 |
Integration resolution for likelihood summation. Higher = more accurate, slower. |
ENABLE_STRIP_TOP_10_PERCENT |
False |
Remove top 10% highest-velocity sources before sampling. |
DRAWS |
1000 |
Number of posterior draws per chain. |
TUNE |
1000 |
Number of tuning (burn-in) samples per chain. |
TARGET_ACCEPT |
0.93 |
NUTS target acceptance rate. |
CHAINS |
4 |
Number of independent chains. |
CORES |
4 |
Number of CPU cores for parallel sampling. |
INIT_METHOD |
"jitter+adapt_diag" |
PyMC initialization method. |
RANDOM_SEED |
42 |
Fixed seed for reproducibility. Set to None for production. |
!!! note "PyTensor compiler"
The line pytensor.config.cxx = "/usr/bin/clang++" is hardcoded for a specific machine. Comment it out or adjust for your system.
Model Structure
Priors
- \(B_0\) (
Bº):HalfNormal(sigma=3)— scalar LV magnitude, non-negative. - \(\vec{B}\) (
B_vec): Reparameterized to enforce \(\|\vec{B}\| < 1\):b_raw ~ Normal(0, 1, shape=3)— unconstrained direction vector.- \(\hat{u} = \texttt{b\_raw} / \|\texttt{b\_raw}\|\) — normalized to a unit vector.
- \(\rho \sim \text{Beta}(2, 2)\) — radial magnitude in \([0, 1)\).
- \(\vec{B} = \rho \cdot \hat{u}\).
Derived quantities
The per-observation inverse critical velocity \(w_c\) comes from the positive root of:
where \(B_n = \hat{n} \cdot \vec{B}\) is the projection of \(\vec{B}\) onto the source direction. The solution used is:
Likelihood
The observed-velocity probability for each source is computed by numerical integration over a Gaussian measurement kernel:
where \(C_v(v)\) is the cumulative distribution function of the underlying velocity distribution, evaluated piecewise depending on whether \(w_c < 1\) (fast-light regime) or \(w_c \geq 1\) (slow-light regime).
!!! warning "Current limitation" Only the fast-light case (\(w_c < 1\)) is implemented in the anisotropic code. The slow-light branch is not yet incorporated.
The total log-likelihood is \(\sum_i \log \mathcal{P}_{\mathrm{obs}}(v_{t,i})\).
Outputs
| Output | Description |
|---|---|
| Trace plot | Saved to scripts/trace.png. Shows MCMC chains for \(B_0\) and \(\vec{B}\) components. |
| Mollweide map | Sky projection of sources with \(v_t > 1\), colored by observed speed. |
| Pair plot | KDE joint posterior of \(B_0\) and \(\vec{B}\) with divergence markers. |
| Posterior plot | Marginal posterior densities with HDI intervals. |
| Console summary | ArviZ summary table with quartiles and sampler diagnostics (divergences, max tree depth). |
API Reference
PyMC_Pytensor_noise_v_main_varsig_aniso.loglike(vt_stack, wc, n_val=N_VAL)
Custom PyMC log-likelihood for transverse velocities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vt_stack
|
TensorVariable
|
A 2-column array where:
- index 0 contains observed transverse velocities |
required |
wc
|
TensorVariable
|
Inverse of the true velocity derived from Bº, B_vec, and n_hat. |
required |
n_val
|
int
|
Integration resolution for the likelihood. |
N_VAL
|
Returns:
| Type | Description |
|---|---|
TensorVariable
|
The summed log-likelihood of all observations. |
Notes
- Uses clipping to avoid log(0) situations.
This function is passed to pm.CustomDist and must therefore return
a scalar log-probability for the entire dataset.
Source code in scripts/PyMC_Pytensor_noise_v_main_varsig_aniso.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
PyMC_Pytensor_noise_v_main_varsig_aniso.main()
Run the full anisotropy analysis workflow.
Steps
- Regenerate or load observational data (vt, sigma, n_hat).
- Clean NaNs and optionally remove top-percentile velocity outliers.
- Construct a PyMC model:
- Bº ~ HalfNormal
- B_vec defined via a normalized reparameterization of raw vector
- wc expression from model geometry
- Custom vt likelihood using
loglike - Sample the posterior using NUTS with configured tuning settings.
- Print summaries and diagnostics.
- Produce optional Mollweide sky maps and posterior trace plots.
Source code in scripts/PyMC_Pytensor_noise_v_main_varsig_aniso.py
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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 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 350 351 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 | |