gamma-wadati 0.1.0.dev1__py3-none-any.whl

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.
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: gamma-wadati
3
+ Version: 0.1.0.dev1
4
+ Summary: Earthquake phase association and location as a Bayesian Gaussian mixture on the Wadati transform
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: numpy
8
+ Requires-Dist: scipy
9
+ Requires-Dist: scikit-learn>=1.9
10
+
11
+ # Wadati BGMM: joint phase association and 3D location
12
+
13
+ Earthquake phase **association** and **location** solved together as a
14
+ (Bayesian) Gaussian Mixture Model, in the spirit of GaMMA but using the
15
+ **Wadati transform**. For every station that picks both P and S of an event we
16
+ form
17
+
18
+ ```
19
+ M = (t_P + t_S)/2 = t0 + p·r D = (t_S − t_P)/2 = q·r
20
+ ```
21
+
22
+ which are linear in source distance `r`. The transform decouples origin time
23
+ from location: because `α = p/q`, the quantity `u = M − α·D = t0` for any true
24
+ pick, *independent of location*. Origin time is therefore estimated location-free
25
+ (a weighted mean), and the hypocenter follows from distance trilateration
26
+ `r ≈ β·D`. This breaks the usual depth/origin-time tradeoff and makes full 3-D
27
+ `(x, y, z)` location tractable.
28
+
29
+ The one structural change to a textbook GMM: each component's mean is **not** a
30
+ free parameter but the Wadati forward prediction `μ_nk = (t0_k + p·r_nk,
31
+ q·r_nk)` of event `k`'s `(t0, x, y, z)` at station `n`. Everything else
32
+ (responsibilities, covariance, DP weights, Wishart prior) is standard.
33
+ See [`formulation.md`](formulation.md) for the full derivation.
34
+
35
+ ## Layout
36
+
37
+ ```
38
+ src/wadati/_gaussian_mixture.py vendored sklearn GaussianMixture, edited
39
+ src/wadati/_bayesian_mixture.py vendored sklearn BayesianGaussianMixture, edited
40
+ src/wadati/_base.py vendored sklearn EM/VB loop (unchanged)
41
+ src/wadati/forward.py velocity model, predict_mean, estimate_t0, locate
42
+ src/wadati/windowing.py t0 pre-clustering into time windows
43
+ synthetic.py 3-case 3D catalog generator (+ ~20% false picks)
44
+ pipeline.py window -> BGMM -> post-hoc filter -> metrics
45
+ plots.py Wadati M-D, map, depth section, timeline
46
+ formulation.md derivation
47
+ mixture/ pristine sklearn 1.9.0 sources (diff reference)
48
+ ```
49
+
50
+ The mixture models are vendored from scikit-learn 1.9.0 and committed unmodified
51
+ first, so `git log -p src/wadati/_gaussian_mixture.py` shows exactly the
52
+ algorithm change against upstream.
53
+
54
+ ## Run
55
+
56
+ ```bash
57
+ PYTHONPATH=src python3 synthetic.py # print the synthetic catalog
58
+ PYTHONPATH=src python3 plots.py # figures/catalog_overview.png (truth)
59
+ PYTHONPATH=src python3 -m wadati.windowing # show the t0 windows
60
+ PYTHONPATH=src python3 pipeline.py # end-to-end metrics + figures/results_overview.png
61
+ ```
62
+
63
+ Requires `numpy`, `scipy`, `scikit-learn` (1.9.x), `matplotlib`.
64
+
65
+ ## Three test cases
66
+
67
+ The synthetic catalog merges, with absolute time offsets, three configurations
68
+ that stress different parts of the problem:
69
+
70
+ | Case | Setup | What it tests |
71
+ |---|---|---|
72
+ | 1 | same `t0`, different locations | spatial separation (M, D carry only distance, so association is pure trilateration) |
73
+ | 2 | same location, different `t0` | temporal separation via `u = M − αD` |
74
+ | 3 | both close (~3 s, ~5 km) | the hardest case (still identifiable) |
75
+
76
+ ## Initialization
77
+
78
+ Two strategies, selected by the sklearn-style `init_params` (they differ only in
79
+ whether the init also fixes the source parameters; both feed the same EM/VB loop):
80
+
81
+ ```python
82
+ BayesianGaussianMixture(init_params="smallest_d", n_init=1, ...) # deterministic (default)
83
+ BayesianGaussianMixture(init_params="kmeans", n_init=20, ...) # random, restart-selected
84
+ ```
85
+
86
+ The default, `"smallest_d"`, seeds components deterministically from **candidate
87
+ event locations**, not from picks. Within each t0 group, picks are scanned in
88
+ order of increasing `D`
89
+ (= q·distance): a small `D` means the station is near the source, so its
90
+ location is the best epicenter proxy. The smallest-`D` picks (spatially
91
+ de-duplicated so several same-t0 events each get a seed) become the initial
92
+ events `(t0 = group mean of u, location = that station)`, and these are used
93
+ **directly** as the starting hypocenters; the first trilateration runs in the
94
+ first M-step. No randomness is involved, so `n_init = 1` suffices.
95
+
96
+ A controlled comparison (6 random catalogs, 20% false picks) shows why this is
97
+ the right default:
98
+
99
+ | initialization | `n_init=1` | `n_init=20` |
100
+ |---|---|---|
101
+ | k-means on (t0, station x, y) | ~0.8 (seed-dependent) | 0.95 |
102
+ | smallest-D candidate locations (deterministic) | **0.91** (reproducible) | 0.91 (restarts are no-ops) |
103
+
104
+ No single initialization exceeds ~0.91: the likelihood is multimodal and the
105
+ jump to ~0.95 comes from restart *selection by ELBO*, not from init quality.
106
+ The deterministic init matches the best single shot while being reproducible and
107
+ restart-free.
108
+
109
+ ## Results
110
+
111
+ Across 6 random catalogs (8 events, ~20% false picks), deterministic
112
+ `n_init = 1`: mean association ARI ≈ **0.91**, median origin-time error ≈ 0.16 s,
113
+ epicenter ≈ 0.6 km, depth ≈ 1.8 km, no spurious events. Case 1 (same t0,
114
+ different location) and Case 2 (different t0, same location) recover cleanly with
115
+ the Dirichlet process pruning the event count automatically.
116
+
117
+ Case 3 (close in both, ~3 s and ~5 km) is the hardest but **identifiable**:
118
+ exhaustive enumeration of all partitions confirms the true labeling is the
119
+ maximum-likelihood one (gap = 0, under both free and fixed covariance). The
120
+ remaining pipeline misses on Case 3 are EM local optima, not fundamental
121
+ ambiguity, and randomized restarts (`n_init = 20`) raise the mean ARI to ≈ 0.95.
122
+ (Pushing the separation down to ~2 s crosses an identifiability threshold: two
123
+ events that close produce too few, too noisy picks to distinguish, and the ML
124
+ partition then overfits the source parameters to noise — the true labeling is no
125
+ longer the maximum-likelihood one.)
126
+
127
+ ## Phase weights
128
+
129
+ Each pick carries a quality weight `w_n ∈ [0,1]` (e.g. a picker's confidence).
130
+ Following GaMMA, the weight enters the **likelihood** (`log P += log w_n` in the
131
+ E-step), not the M-step. Added to every component, it cancels in the
132
+ responsibility normalization, so it **never changes the geometric fit** — it
133
+ only lowers a poor pick's marginal score. This is the right choice for an
134
+ *uncalibrated* ML confidence: putting `w` on `P` (a constant offset) is immune to
135
+ its absolute scale, whereas putting `w` on `log P` (observation-weighting) would
136
+ shrink effective counts and make the Dirichlet process prune real events. The
137
+ pipeline consumes the quality signal post-hoc: a pick is kept only if
138
+ `max_k γ_nk · w_n ≥ min_resp` (fit confidence × quality) and its Mahalanobis
139
+ residual is small, and each event is relocated from its kept picks weighted by
140
+ `w_n`.
141
+
142
+ False picks are otherwise handled post-hoc: drop picks that fail the gate above,
143
+ then refit each event's hypocenter from its own kept picks. Because depth is well
144
+ constrained by the Wadati distance `r = β·D` (each pick fixes the source-station
145
+ distance), depth errors trace to association mistakes, not to depth being
146
+ unresolvable. A dedicated uniform noise component in the mixture (GaMMA's dummy
147
+ component, the principled home for `w` as `P(real)` once calibrated) is left for
148
+ future work.
@@ -0,0 +1,11 @@
1
+ wadati/__init__.py,sha256=p9YFzIJKxqm-God3TnPKkhyAZe7ExBoZnZRSxPOPUsg,454
2
+ wadati/_base.py,sha256=XQqHUmCPS-thJ2O3P9mFhqQ0RvzZVSK9eRoPWJ797nE,21162
3
+ wadati/_bayesian_mixture.py,sha256=4-IGMgIFJkdR8yj-sz24_Po4xer3MXrveURIcZQApeI,36150
4
+ wadati/_gaussian_mixture.py,sha256=CGmqU9iHWtszv2nD-DIDBSUGHQ67Iy94SNis7g1XGTQ,43134
5
+ wadati/forward.py,sha256=ea1QoO9Q7vCgThc0j4UC7_iTVkcUK4Sbg0AXC8BUYZA,6155
6
+ wadati/pairing.py,sha256=vli7csg3ESdg4oPddequVR3V_3qH_G28bsM0gm4frf0,4940
7
+ wadati/windowing.py,sha256=o6r_nfDn4VI2h47dawUXFBdxgBRo96ucESbTcNEARf4,9346
8
+ gamma_wadati-0.1.0.dev1.dist-info/METADATA,sha256=wBVyR4vSxHPKPMAP2qnolaf1V7M44U6HKGZfqlUyRJc,7311
9
+ gamma_wadati-0.1.0.dev1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
10
+ gamma_wadati-0.1.0.dev1.dist-info/top_level.txt,sha256=XUkM9LKegbOHT3UBvGTgKSM01ryKIkzCbBhK4cBwnkA,7
11
+ gamma_wadati-0.1.0.dev1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ wadati
wadati/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ """Wadati (M, D) mixture models for joint phase association and 3D location.
2
+
3
+ Vendored from scikit-learn 1.9.0 ``sklearn.mixture`` and modified so each
4
+ mixture component's mean is the Wadati forward prediction of an event's
5
+ ``(t0, x, y, z)`` at each station, rather than a free parameter.
6
+ """
7
+
8
+ from ._bayesian_mixture import BayesianGaussianMixture
9
+ from ._gaussian_mixture import GaussianMixture
10
+
11
+ __all__ = ["GaussianMixture", "BayesianGaussianMixture"]