flashdiffusion 0.1.2__tar.gz → 0.2.1__tar.gz

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.
Files changed (46) hide show
  1. {flashdiffusion-0.1.2 → flashdiffusion-0.2.1}/LICENSE +1 -1
  2. flashdiffusion-0.2.1/PKG-INFO +303 -0
  3. flashdiffusion-0.2.1/README.md +274 -0
  4. flashdiffusion-0.2.1/pyproject.toml +48 -0
  5. flashdiffusion-0.2.1/src/flashdiffusion/__init__.py +13 -0
  6. flashdiffusion-0.2.1/src/flashdiffusion/bandwidth.py +273 -0
  7. flashdiffusion-0.2.1/src/flashdiffusion/dense.py +87 -0
  8. flashdiffusion-0.2.1/src/flashdiffusion/energy.py +150 -0
  9. flashdiffusion-0.2.1/src/flashdiffusion/flashdiffusion.py +272 -0
  10. flashdiffusion-0.2.1/src/flashdiffusion/heuristics.py +88 -0
  11. flashdiffusion-0.2.1/src/flashdiffusion/knn.py +111 -0
  12. flashdiffusion-0.2.1/src/flashdiffusion/mfstar.py +356 -0
  13. flashdiffusion-0.2.1/src/flashdiffusion/spectral.py +134 -0
  14. flashdiffusion-0.2.1/src/flashdiffusion.egg-info/PKG-INFO +303 -0
  15. flashdiffusion-0.2.1/src/flashdiffusion.egg-info/SOURCES.txt +19 -0
  16. flashdiffusion-0.2.1/src/flashdiffusion.egg-info/requires.txt +15 -0
  17. flashdiffusion-0.2.1/tests/test_bandwidth.py +94 -0
  18. flashdiffusion-0.2.1/tests/test_simple.py +112 -0
  19. flashdiffusion-0.1.2/PKG-INFO +0 -169
  20. flashdiffusion-0.1.2/README.md +0 -142
  21. flashdiffusion-0.1.2/pyproject.toml +0 -33
  22. flashdiffusion-0.1.2/setup.py +0 -319
  23. flashdiffusion-0.1.2/src/flashdiffusion/ROPE.py +0 -597
  24. flashdiffusion-0.1.2/src/flashdiffusion/__init__.py +0 -28
  25. flashdiffusion-0.1.2/src/flashdiffusion/cdc.py +0 -168
  26. flashdiffusion-0.1.2/src/flashdiffusion/csrc/flash_diffusion_sm120.cu +0 -328
  27. flashdiffusion-0.1.2/src/flashdiffusion/csrc/flash_diffusion_sm120X.cu +0 -312
  28. flashdiffusion-0.1.2/src/flashdiffusion/csrc/flash_diffusion_sm120_.cu +0 -204
  29. flashdiffusion-0.1.2/src/flashdiffusion/csrc/flash_diffusion_sm80.cu +0 -324
  30. flashdiffusion-0.1.2/src/flashdiffusion/csrc/flash_diffusion_sm80X.cu +0 -293
  31. flashdiffusion-0.1.2/src/flashdiffusion/csrc/flash_diffusion_sm80_.cu +0 -238
  32. flashdiffusion-0.1.2/src/flashdiffusion/dmap.py +0 -321
  33. flashdiffusion-0.1.2/src/flashdiffusion/eigensolver.py +0 -131
  34. flashdiffusion-0.1.2/src/flashdiffusion/eigensolver_gpu.py +0 -217
  35. flashdiffusion-0.1.2/src/flashdiffusion/kernel.py +0 -256
  36. flashdiffusion-0.1.2/src/flashdiffusion/kernel_cuda.py +0 -154
  37. flashdiffusion-0.1.2/src/flashdiffusion/kernel_cuda_sm120.py +0 -94
  38. flashdiffusion-0.1.2/src/flashdiffusion/kernel_jit.py +0 -160
  39. flashdiffusion-0.1.2/src/flashdiffusion/utils.py +0 -134
  40. flashdiffusion-0.1.2/src/flashdiffusion.egg-info/PKG-INFO +0 -169
  41. flashdiffusion-0.1.2/src/flashdiffusion.egg-info/SOURCES.txt +0 -27
  42. flashdiffusion-0.1.2/src/flashdiffusion.egg-info/requires.txt +0 -3
  43. flashdiffusion-0.1.2/tests/test_kernel.py +0 -102
  44. {flashdiffusion-0.1.2 → flashdiffusion-0.2.1}/setup.cfg +0 -0
  45. {flashdiffusion-0.1.2 → flashdiffusion-0.2.1}/src/flashdiffusion.egg-info/dependency_links.txt +0 -0
  46. {flashdiffusion-0.1.2 → flashdiffusion-0.2.1}/src/flashdiffusion.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Julio Candanedo
3
+ Copyright (c) 2026 Sparse Trace LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,303 @@
1
+ Metadata-Version: 2.4
2
+ Name: flashdiffusion
3
+ Version: 0.2.1
4
+ Summary: Matrix-free bandwidth optimization and diffusion geometry on the GPU
5
+ Author: Sparse Trace LLC
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/sparsetrace/FlashDiffusion
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Environment :: GPU :: NVIDIA CUDA :: 12
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
13
+ Requires-Python: <3.14,>=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: xgemm<0.4,>=0.3
17
+ Requires-Dist: jax
18
+ Requires-Dist: numpy
19
+ Requires-Dist: scipy
20
+ Provides-Extra: cuda12
21
+ Requires-Dist: jax[cuda12]; extra == "cuda12"
22
+ Requires-Dist: cupy-cuda12x<15,>=14; extra == "cuda12"
23
+ Requires-Dist: cuvs-cu12; extra == "cuda12"
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest; extra == "test"
26
+ Provides-Extra: examples
27
+ Requires-Dist: matplotlib; extra == "examples"
28
+ Dynamic: license-file
29
+
30
+ # Optimizing Diffusion-Map Bandwidth Using Dirichlet Energy
31
+
32
+ [![arXiv](https://img.shields.io/badge/arXiv-2609.38198-b31b1b.svg)](https://arxiv.org/pdf/2609.38198)
33
+
34
+ ## 1. Motivation
35
+
36
+ - **Problem:** Diffusion Maps (DMAP) use a Gaussian kernel, with a bandwidth parameter $\beta$ controlling the geometric scale of the resulting diffusion operator.
37
+
38
+ - Let $X\in\mathbb R^{N\times D}$ denote $N$ samples in ambient dimension $D$, and define the squared-distance matrix $\mathcal H\in\mathbb R^{N\times N}$.
39
+
40
+ $$
41
+ \boxed{\mathsf{K}_\beta=\exp(-\beta\mathcal H)}
42
+ $$
43
+
44
+ Here the exponential is understood elementwise.
45
+
46
+ - **Goal:** Choose $\beta$ such that the discrete diffusion operator approximates the intrinsic Laplace–Beltrami operator $-\Delta_{\mathcal M}$, recovering as many authentic manifold harmonics as possible.
47
+
48
+ - There are two undesirable limits:
49
+ - **$\beta\to0$:** $\mathsf{K}_\beta\to\mathbf1\mathbf1^\top$. The kernel becomes nearly rank one and loses local geometric information.
50
+ - **$\beta\to\infty$:** $\mathsf{K}_\beta\to\mathsf I$ for distinct samples. The diffusion graph disconnects and no longer resolves spatial variation.
51
+
52
+ - **Motivating idea:** Between these limits, there should be a regime in which the discrete operator approximates continuum geometry.
53
+
54
+ - Can we identify that regime **without diagonalizing the operator for every candidate $\beta$?**
55
+
56
+ ## 2. Diffusion Maps and Dirichlet energy
57
+
58
+ - Use Coifman–Lafon normalization with $\alpha=1$. Define the raw degrees $\rho$, their reciprocals $q$, and the normalized affinity $\mathsf W$:
59
+
60
+ $$
61
+ \rho=\mathsf K\mathbf1,\qquad q=\rho^{\odot(-1)},\qquad\mathsf W=\mathrm{diag}(q)\mathsf K\mathrm{diag}(q).
62
+ $$
63
+
64
+ - Introduce the normalized degrees and the symmetric DMAP operator:
65
+
66
+ $$
67
+ d=\mathsf W\mathbf1,\qquad P=\mathrm{diag}(d)^{-1/2}\mathsf W\mathrm{diag}(d)^{-1/2}.
68
+ $$
69
+
70
+ - The equivalent row-stochastic Markov operator is $\mathsf R=\mathrm{diag}(d)^{-1}\mathsf W$, with stationary distribution $\pi=d/Z$, where $Z=\mathbf1^\top d$.
71
+
72
+ - The discrete Dirichlet energy of a function $f\in\mathbb R^N$ can be written directly in terms of the symmetric operator $P$:
73
+
74
+ $$
75
+ \boxed{\mathcal E_\beta(f)=\frac{1}{Z}f^\top\mathrm{diag}(d)^{1/2}(\mathsf I-P)\mathrm{diag}(d)^{1/2}f.}
76
+ $$
77
+
78
+ - The Gaussian bandwidth convention gives the rescaled Dirichlet form
79
+
80
+ $$
81
+ \boxed{\mathscr E_\beta(f)=4\beta\mathcal E_\beta(f).}
82
+ $$
83
+
84
+ - Under appropriate geometric and sampling assumptions, the local-kernel limit satisfies
85
+
86
+ $$
87
+ 4\beta(\mathsf I-\mathsf R)\longrightarrow-\Delta_{\mathcal M}.
88
+ $$
89
+
90
+ - Consequently, the rescaled discrete Dirichlet energy approaches the continuum Dirichlet energy:
91
+
92
+ $$
93
+ \mathscr E_\beta(f)\longrightarrow\int_{\mathcal M}\|\nabla_{\mathcal M}f\|^2\,d\mu.
94
+ $$
95
+
96
+ - **Key observation:** In a geometric consistency regime, this rescaled energy should become approximately independent of $\beta$.
97
+
98
+ ## 3. Using ambient coordinate functions
99
+
100
+ - Rather than choosing arbitrary probe functions, use the ambient embedding coordinates $X$ themselves.
101
+
102
+ - Sum the Dirichlet energies over all $D$ coordinate functions. In matrix notation,
103
+
104
+ $$
105
+ \boxed{\mathscr E_\beta(X)=\frac{4\beta}{Z}\mathrm{tr}\left[X^\top\mathrm{diag}(d)^{1/2}(\mathsf I-P)\mathrm{diag}(d)^{1/2}X\right].}
106
+ $$
107
+
108
+ - This expression simplifies to a single weighted squared-distance moment:
109
+
110
+ $$
111
+ \boxed{\mathscr E_\beta(X)=\frac{2\beta}{Z}\langle\mathsf W,\mathcal H\rangle_F.}
112
+ $$
113
+
114
+ Here $\langle\cdot,\cdot\rangle_F$ is the Frobenius inner product.
115
+
116
+ - **Geometric significance:** For an isometric embedding $X:\mathcal M\to\mathbb R^D$ of an intrinsic $d$-dimensional manifold,
117
+
118
+ $$
119
+ \boxed{\mathrm{tr}\left[(\nabla_{\mathcal M}X)^\top(\nabla_{\mathcal M}X)\right]=d.}
120
+ $$
121
+
122
+ - Therefore, in the ideal continuum regime with normalized volume measure,
123
+
124
+ $$
125
+ \boxed{\mathscr E_\beta(X)\approx d.}
126
+ $$
127
+
128
+ - For a noiseless two-dimensional Swiss roll, this suggests an energy plateau near $d=2$.
129
+
130
+ - **Interpretation:** We are measuring the average squared displacement of the diffusion process, rescaled by its diffusion time. The intrinsic dimension provides a natural geometric reference value.
131
+
132
+ ## 4. The bandwidth dependence
133
+
134
+ - **Broad-kernel limit:** As $\beta\to0$, the rescaled energy vanishes:
135
+
136
+ $$
137
+ \mathscr E_\beta(X)\sim4\beta\,\mathrm{tr}[\mathrm{Cov}(X)]\longrightarrow0.
138
+ $$
139
+
140
+ - **Intermediate regime:** The energy can approach the intrinsic dimension, potentially developing a plateau or a broad maximum.
141
+
142
+ - **Narrow-kernel limit:** At fixed finite $N$, keeping the diagonal of $\mathsf K$,
143
+
144
+ $$
145
+ \mathscr E_\beta(X)\longrightarrow0,\qquad\beta\to\infty.
146
+ $$
147
+
148
+ - The energy is therefore nonnegative and vanishes at both extremes. For nontrivial finite data, at least one interior maximum exists.
149
+
150
+ - This motivates an initial bandwidth-selection objective.
151
+
152
+ ## 5. Proposed optimization
153
+
154
+ - **First trial:** Select the bandwidth maximizing the coordinate Dirichlet energy:
155
+
156
+ $$
157
+ \boxed{\beta^\star=\arg\max_{\beta>0}\mathscr E_\beta(X).}
158
+ $$
159
+
160
+ - This objective uses only the input data and the Gaussian kernel, without computing eigenvectors.
161
+
162
+ - A related, potentially more geometrically faithful criterion is to identify a stable region satisfying
163
+
164
+ $$
165
+ \mathscr E_\beta(X)\approx d,\qquad\frac{d\mathscr E_\beta(X)}{d\log\beta}\approx0.
166
+ $$
167
+
168
+ - An important distinction: **maximizing the energy and identifying a geometric plateau are not necessarily equivalent.**
169
+
170
+ - For now, investigate the energy maximum as a simple, computationally inexpensive candidate.
171
+
172
+ ## 6. Exact gradient with respect to bandwidth
173
+
174
+ - Define the two scalar kernel moments
175
+
176
+ $$
177
+ Z=\mathbf1^\top\mathsf W\mathbf1,\qquad T=\langle\mathsf W,\mathcal H\rangle_F.
178
+ $$
179
+
180
+ - Our objective becomes
181
+
182
+ $$
183
+ \boxed{\mathscr E_\beta(X)=2\beta\frac{T}{Z}.}
184
+ $$
185
+
186
+ - Optimize in logarithmic bandwidth $u=\log\beta$, ensuring $\beta>0$.
187
+
188
+ - Denoting differentiation with respect to $u$ by a dot, the Gaussian kernel has the exact derivative
189
+
190
+ $$
191
+ \boxed{\dot{\mathsf K}=-\beta(\mathcal H\odot\mathsf K).}
192
+ $$
193
+
194
+ - Since $q=(\mathsf K\mathbf1)^{\odot(-1)}$, its derivative and the derivative of $\mathsf W$ follow analytically:
195
+
196
+ $$
197
+ \dot q=-q^{\odot2}\odot(\dot{\mathsf K}\mathbf1).
198
+ $$
199
+
200
+ $$
201
+ \dot{\mathsf W}=\mathrm{diag}(\dot q)\mathsf K\mathrm{diag}(q)+\mathrm{diag}(q)\dot{\mathsf K}\mathrm{diag}(q)+\mathrm{diag}(q)\mathsf K\mathrm{diag}(\dot q).
202
+ $$
203
+
204
+ - Hence,
205
+
206
+ $$
207
+ \dot Z=\mathbf1^\top\dot{\mathsf W}\mathbf1,\qquad\dot T=\langle\dot{\mathsf W},\mathcal H\rangle_F.
208
+ $$
209
+
210
+ - The exact gradient is
211
+
212
+ $$
213
+ \boxed{\frac{d\mathscr E_\beta}{du}=\frac{2\beta}{Z}\left(T+\dot T-\frac{T\dot Z}{Z}\right).}
214
+ $$
215
+
216
+ - **Important:** This is an analytical derivative, not an approximation from finite differences. No differentiation through an eigensolver is necessary.
217
+
218
+ ## 7. Matrix-free algorithm
219
+
220
+ - Neither $\mathcal H$, $\mathsf K$, $\mathsf W$, nor $P$ needs to be stored as an $N\times N$ matrix.
221
+
222
+ - **Pass 1 — Kernel degrees:** Compute tiles of $\mathcal H$ and $\mathsf K$, accumulating $\rho=\mathsf K\mathbf1$ and $\dot\rho=\dot{\mathsf K}\mathbf1$.
223
+
224
+ - **Pass 2 — Energy moments:** Recompute tiles and accumulate $Z$, $T$, $\dot Z$, and $\dot T$ using the previously determined normalization.
225
+
226
+ - Both passes have the same tiling pattern as matrix-free RBF matvec operations.
227
+
228
+ - For one bandwidth, computational complexity is $O(N^2D)$ with memory $O(N+B^2)$, where $B$ is the tile size.
229
+
230
+ - A whole logarithmic ladder of $M$ bandwidth values can be evaluated in two tiled sweeps, sharing each distance calculation across the bandwidths.
231
+
232
+ - This requires $O(N^2D+MN^2)$ arithmetic and $O(MN+B^2)$ auxiliary memory.
233
+
234
+ - The resulting one-dimensional optimization can use gradient ascent, Newton's method, or bracketed root finding.
235
+
236
+ - **Computational advantage:** Bandwidth selection uses kernel reductions instead of repeated Lanczos diagonalizations.
237
+
238
+ ## 8. First numerical experiment
239
+
240
+ - **Dataset:** A noiseless two-dimensional Swiss roll embedded isometrically in $\mathbb R^3$.
241
+
242
+ - **Sampling:** Begin with approximately $N=2000$ samples.
243
+
244
+ - **Normalization:** Coifman–Lafon $\alpha=1$.
245
+
246
+ - **Step 1:** Evaluate $\mathscr E_\beta(X)$ and its exact gradient over a logarithmic $\beta$-grid.
247
+
248
+ - **Step 2:** Identify energy maxima, geometric plateaus, and possible finite-sample disconnection regimes.
249
+
250
+ - **Step 3:** Independently compute approximately 30–60 leading DMAP harmonics at selected bandwidths.
251
+
252
+ - **Step 4:** Compare these with the known intrinsic Laplace–Beltrami harmonics of the Swiss roll.
253
+
254
+ - **Step 5:** Determine whether the bandwidth maximizing the Dirichlet energy also maximizes the number of correctly recovered harmonics.
255
+
256
+ - Later, repeat the experiment for different sample sizes, sampling densities, noise levels, and manifold geometries.
257
+
258
+ ## 9. Limitations and future directions
259
+
260
+ - The coordinate Dirichlet energy measures how the discrete operator acts on the ambient coordinate functions, rather than directly testing every eigenfunction.
261
+
262
+ - Even when $\mathscr E_\beta(X)\approx d$, higher-frequency harmonics may still be poorly resolved.
263
+
264
+ - Therefore, the proposed objective is currently a **geometrically motivated heuristic**, not a proven optimal bandwidth criterion.
265
+
266
+ - One natural extension is a matrix-valued Dirichlet observable:
267
+
268
+ $$
269
+ \boxed{G_\beta=\frac{2\beta}{Z}X^\top\left[\mathrm{diag}(d)-\mathsf W\right]X.}
270
+ $$
271
+
272
+ Its trace reproduces the scalar energy:
273
+
274
+ $$
275
+ \boxed{\mathrm{tr}(G_\beta)=\mathscr E_\beta(X).}
276
+ $$
277
+
278
+ - This matrix may reveal anisotropy, effective dimension, or geometric distortions that the scalar trace misses.
279
+
280
+ - Other extensions could incorporate smooth probe functions, spectral projectors, or higher-frequency Dirichlet consistency.
281
+
282
+ ## 10. Main research question
283
+
284
+ - Can a simple scalar functional of the kernel predict the bandwidth at which the discrete diffusion operator best approximates the intrinsic Laplace–Beltrami spectrum?
285
+
286
+ - The first proposed answer is to use the maximum of the rescaled coordinate Dirichlet energy.
287
+
288
+ - **The computational part is straightforward:** The energy and exact gradient can be evaluated matrix-free, without any eigendecomposition.
289
+
290
+ - **The scientific question remains open:** Does this maximum reliably select the bandwidth that resolves the greatest number of authentic manifold harmonics?
291
+
292
+ **Main takeaway:** We propose using the rescaled coordinate Dirichlet energy as an inexpensive, differentiable, geometric bandwidth-selection criterion for Diffusion Maps. The initial experiment is designed to test whether its maximum predicts accurate manifold-harmonic recovery, before introducing more sophisticated spectral criteria.
293
+
294
+
295
+ ### Full-kernel BEBN operator API and HF model checkpoints
296
+
297
+ `DMAP(X, β=..., α=0.0)` provides the matrix-free Markov action `T_β @ f`,
298
+ `T_β.gamma(f, g)`, and optional `T_β.solve(k=...)`. The facade uses canonical
299
+ `β` and `τ` attributes with ASCII aliases. `solve(β="auto")` deliberately
300
+ refits β; a fixed `β` otherwise skips fitting. Large modes can be checkpointed
301
+ locally or explicitly pushed to a Hugging Face **model** repository via
302
+ `HF_MODEL` and the environment variable `HF_TOKEN`; input datasets remain
303
+ separate. See `src/flashdiffusion/DMAP_API.md` for examples and cautions.
@@ -0,0 +1,274 @@
1
+ # Optimizing Diffusion-Map Bandwidth Using Dirichlet Energy
2
+
3
+ [![arXiv](https://img.shields.io/badge/arXiv-2609.38198-b31b1b.svg)](https://arxiv.org/pdf/2609.38198)
4
+
5
+ ## 1. Motivation
6
+
7
+ - **Problem:** Diffusion Maps (DMAP) use a Gaussian kernel, with a bandwidth parameter $\beta$ controlling the geometric scale of the resulting diffusion operator.
8
+
9
+ - Let $X\in\mathbb R^{N\times D}$ denote $N$ samples in ambient dimension $D$, and define the squared-distance matrix $\mathcal H\in\mathbb R^{N\times N}$.
10
+
11
+ $$
12
+ \boxed{\mathsf{K}_\beta=\exp(-\beta\mathcal H)}
13
+ $$
14
+
15
+ Here the exponential is understood elementwise.
16
+
17
+ - **Goal:** Choose $\beta$ such that the discrete diffusion operator approximates the intrinsic Laplace–Beltrami operator $-\Delta_{\mathcal M}$, recovering as many authentic manifold harmonics as possible.
18
+
19
+ - There are two undesirable limits:
20
+ - **$\beta\to0$:** $\mathsf{K}_\beta\to\mathbf1\mathbf1^\top$. The kernel becomes nearly rank one and loses local geometric information.
21
+ - **$\beta\to\infty$:** $\mathsf{K}_\beta\to\mathsf I$ for distinct samples. The diffusion graph disconnects and no longer resolves spatial variation.
22
+
23
+ - **Motivating idea:** Between these limits, there should be a regime in which the discrete operator approximates continuum geometry.
24
+
25
+ - Can we identify that regime **without diagonalizing the operator for every candidate $\beta$?**
26
+
27
+ ## 2. Diffusion Maps and Dirichlet energy
28
+
29
+ - Use Coifman–Lafon normalization with $\alpha=1$. Define the raw degrees $\rho$, their reciprocals $q$, and the normalized affinity $\mathsf W$:
30
+
31
+ $$
32
+ \rho=\mathsf K\mathbf1,\qquad q=\rho^{\odot(-1)},\qquad\mathsf W=\mathrm{diag}(q)\mathsf K\mathrm{diag}(q).
33
+ $$
34
+
35
+ - Introduce the normalized degrees and the symmetric DMAP operator:
36
+
37
+ $$
38
+ d=\mathsf W\mathbf1,\qquad P=\mathrm{diag}(d)^{-1/2}\mathsf W\mathrm{diag}(d)^{-1/2}.
39
+ $$
40
+
41
+ - The equivalent row-stochastic Markov operator is $\mathsf R=\mathrm{diag}(d)^{-1}\mathsf W$, with stationary distribution $\pi=d/Z$, where $Z=\mathbf1^\top d$.
42
+
43
+ - The discrete Dirichlet energy of a function $f\in\mathbb R^N$ can be written directly in terms of the symmetric operator $P$:
44
+
45
+ $$
46
+ \boxed{\mathcal E_\beta(f)=\frac{1}{Z}f^\top\mathrm{diag}(d)^{1/2}(\mathsf I-P)\mathrm{diag}(d)^{1/2}f.}
47
+ $$
48
+
49
+ - The Gaussian bandwidth convention gives the rescaled Dirichlet form
50
+
51
+ $$
52
+ \boxed{\mathscr E_\beta(f)=4\beta\mathcal E_\beta(f).}
53
+ $$
54
+
55
+ - Under appropriate geometric and sampling assumptions, the local-kernel limit satisfies
56
+
57
+ $$
58
+ 4\beta(\mathsf I-\mathsf R)\longrightarrow-\Delta_{\mathcal M}.
59
+ $$
60
+
61
+ - Consequently, the rescaled discrete Dirichlet energy approaches the continuum Dirichlet energy:
62
+
63
+ $$
64
+ \mathscr E_\beta(f)\longrightarrow\int_{\mathcal M}\|\nabla_{\mathcal M}f\|^2\,d\mu.
65
+ $$
66
+
67
+ - **Key observation:** In a geometric consistency regime, this rescaled energy should become approximately independent of $\beta$.
68
+
69
+ ## 3. Using ambient coordinate functions
70
+
71
+ - Rather than choosing arbitrary probe functions, use the ambient embedding coordinates $X$ themselves.
72
+
73
+ - Sum the Dirichlet energies over all $D$ coordinate functions. In matrix notation,
74
+
75
+ $$
76
+ \boxed{\mathscr E_\beta(X)=\frac{4\beta}{Z}\mathrm{tr}\left[X^\top\mathrm{diag}(d)^{1/2}(\mathsf I-P)\mathrm{diag}(d)^{1/2}X\right].}
77
+ $$
78
+
79
+ - This expression simplifies to a single weighted squared-distance moment:
80
+
81
+ $$
82
+ \boxed{\mathscr E_\beta(X)=\frac{2\beta}{Z}\langle\mathsf W,\mathcal H\rangle_F.}
83
+ $$
84
+
85
+ Here $\langle\cdot,\cdot\rangle_F$ is the Frobenius inner product.
86
+
87
+ - **Geometric significance:** For an isometric embedding $X:\mathcal M\to\mathbb R^D$ of an intrinsic $d$-dimensional manifold,
88
+
89
+ $$
90
+ \boxed{\mathrm{tr}\left[(\nabla_{\mathcal M}X)^\top(\nabla_{\mathcal M}X)\right]=d.}
91
+ $$
92
+
93
+ - Therefore, in the ideal continuum regime with normalized volume measure,
94
+
95
+ $$
96
+ \boxed{\mathscr E_\beta(X)\approx d.}
97
+ $$
98
+
99
+ - For a noiseless two-dimensional Swiss roll, this suggests an energy plateau near $d=2$.
100
+
101
+ - **Interpretation:** We are measuring the average squared displacement of the diffusion process, rescaled by its diffusion time. The intrinsic dimension provides a natural geometric reference value.
102
+
103
+ ## 4. The bandwidth dependence
104
+
105
+ - **Broad-kernel limit:** As $\beta\to0$, the rescaled energy vanishes:
106
+
107
+ $$
108
+ \mathscr E_\beta(X)\sim4\beta\,\mathrm{tr}[\mathrm{Cov}(X)]\longrightarrow0.
109
+ $$
110
+
111
+ - **Intermediate regime:** The energy can approach the intrinsic dimension, potentially developing a plateau or a broad maximum.
112
+
113
+ - **Narrow-kernel limit:** At fixed finite $N$, keeping the diagonal of $\mathsf K$,
114
+
115
+ $$
116
+ \mathscr E_\beta(X)\longrightarrow0,\qquad\beta\to\infty.
117
+ $$
118
+
119
+ - The energy is therefore nonnegative and vanishes at both extremes. For nontrivial finite data, at least one interior maximum exists.
120
+
121
+ - This motivates an initial bandwidth-selection objective.
122
+
123
+ ## 5. Proposed optimization
124
+
125
+ - **First trial:** Select the bandwidth maximizing the coordinate Dirichlet energy:
126
+
127
+ $$
128
+ \boxed{\beta^\star=\arg\max_{\beta>0}\mathscr E_\beta(X).}
129
+ $$
130
+
131
+ - This objective uses only the input data and the Gaussian kernel, without computing eigenvectors.
132
+
133
+ - A related, potentially more geometrically faithful criterion is to identify a stable region satisfying
134
+
135
+ $$
136
+ \mathscr E_\beta(X)\approx d,\qquad\frac{d\mathscr E_\beta(X)}{d\log\beta}\approx0.
137
+ $$
138
+
139
+ - An important distinction: **maximizing the energy and identifying a geometric plateau are not necessarily equivalent.**
140
+
141
+ - For now, investigate the energy maximum as a simple, computationally inexpensive candidate.
142
+
143
+ ## 6. Exact gradient with respect to bandwidth
144
+
145
+ - Define the two scalar kernel moments
146
+
147
+ $$
148
+ Z=\mathbf1^\top\mathsf W\mathbf1,\qquad T=\langle\mathsf W,\mathcal H\rangle_F.
149
+ $$
150
+
151
+ - Our objective becomes
152
+
153
+ $$
154
+ \boxed{\mathscr E_\beta(X)=2\beta\frac{T}{Z}.}
155
+ $$
156
+
157
+ - Optimize in logarithmic bandwidth $u=\log\beta$, ensuring $\beta>0$.
158
+
159
+ - Denoting differentiation with respect to $u$ by a dot, the Gaussian kernel has the exact derivative
160
+
161
+ $$
162
+ \boxed{\dot{\mathsf K}=-\beta(\mathcal H\odot\mathsf K).}
163
+ $$
164
+
165
+ - Since $q=(\mathsf K\mathbf1)^{\odot(-1)}$, its derivative and the derivative of $\mathsf W$ follow analytically:
166
+
167
+ $$
168
+ \dot q=-q^{\odot2}\odot(\dot{\mathsf K}\mathbf1).
169
+ $$
170
+
171
+ $$
172
+ \dot{\mathsf W}=\mathrm{diag}(\dot q)\mathsf K\mathrm{diag}(q)+\mathrm{diag}(q)\dot{\mathsf K}\mathrm{diag}(q)+\mathrm{diag}(q)\mathsf K\mathrm{diag}(\dot q).
173
+ $$
174
+
175
+ - Hence,
176
+
177
+ $$
178
+ \dot Z=\mathbf1^\top\dot{\mathsf W}\mathbf1,\qquad\dot T=\langle\dot{\mathsf W},\mathcal H\rangle_F.
179
+ $$
180
+
181
+ - The exact gradient is
182
+
183
+ $$
184
+ \boxed{\frac{d\mathscr E_\beta}{du}=\frac{2\beta}{Z}\left(T+\dot T-\frac{T\dot Z}{Z}\right).}
185
+ $$
186
+
187
+ - **Important:** This is an analytical derivative, not an approximation from finite differences. No differentiation through an eigensolver is necessary.
188
+
189
+ ## 7. Matrix-free algorithm
190
+
191
+ - Neither $\mathcal H$, $\mathsf K$, $\mathsf W$, nor $P$ needs to be stored as an $N\times N$ matrix.
192
+
193
+ - **Pass 1 — Kernel degrees:** Compute tiles of $\mathcal H$ and $\mathsf K$, accumulating $\rho=\mathsf K\mathbf1$ and $\dot\rho=\dot{\mathsf K}\mathbf1$.
194
+
195
+ - **Pass 2 — Energy moments:** Recompute tiles and accumulate $Z$, $T$, $\dot Z$, and $\dot T$ using the previously determined normalization.
196
+
197
+ - Both passes have the same tiling pattern as matrix-free RBF matvec operations.
198
+
199
+ - For one bandwidth, computational complexity is $O(N^2D)$ with memory $O(N+B^2)$, where $B$ is the tile size.
200
+
201
+ - A whole logarithmic ladder of $M$ bandwidth values can be evaluated in two tiled sweeps, sharing each distance calculation across the bandwidths.
202
+
203
+ - This requires $O(N^2D+MN^2)$ arithmetic and $O(MN+B^2)$ auxiliary memory.
204
+
205
+ - The resulting one-dimensional optimization can use gradient ascent, Newton's method, or bracketed root finding.
206
+
207
+ - **Computational advantage:** Bandwidth selection uses kernel reductions instead of repeated Lanczos diagonalizations.
208
+
209
+ ## 8. First numerical experiment
210
+
211
+ - **Dataset:** A noiseless two-dimensional Swiss roll embedded isometrically in $\mathbb R^3$.
212
+
213
+ - **Sampling:** Begin with approximately $N=2000$ samples.
214
+
215
+ - **Normalization:** Coifman–Lafon $\alpha=1$.
216
+
217
+ - **Step 1:** Evaluate $\mathscr E_\beta(X)$ and its exact gradient over a logarithmic $\beta$-grid.
218
+
219
+ - **Step 2:** Identify energy maxima, geometric plateaus, and possible finite-sample disconnection regimes.
220
+
221
+ - **Step 3:** Independently compute approximately 30–60 leading DMAP harmonics at selected bandwidths.
222
+
223
+ - **Step 4:** Compare these with the known intrinsic Laplace–Beltrami harmonics of the Swiss roll.
224
+
225
+ - **Step 5:** Determine whether the bandwidth maximizing the Dirichlet energy also maximizes the number of correctly recovered harmonics.
226
+
227
+ - Later, repeat the experiment for different sample sizes, sampling densities, noise levels, and manifold geometries.
228
+
229
+ ## 9. Limitations and future directions
230
+
231
+ - The coordinate Dirichlet energy measures how the discrete operator acts on the ambient coordinate functions, rather than directly testing every eigenfunction.
232
+
233
+ - Even when $\mathscr E_\beta(X)\approx d$, higher-frequency harmonics may still be poorly resolved.
234
+
235
+ - Therefore, the proposed objective is currently a **geometrically motivated heuristic**, not a proven optimal bandwidth criterion.
236
+
237
+ - One natural extension is a matrix-valued Dirichlet observable:
238
+
239
+ $$
240
+ \boxed{G_\beta=\frac{2\beta}{Z}X^\top\left[\mathrm{diag}(d)-\mathsf W\right]X.}
241
+ $$
242
+
243
+ Its trace reproduces the scalar energy:
244
+
245
+ $$
246
+ \boxed{\mathrm{tr}(G_\beta)=\mathscr E_\beta(X).}
247
+ $$
248
+
249
+ - This matrix may reveal anisotropy, effective dimension, or geometric distortions that the scalar trace misses.
250
+
251
+ - Other extensions could incorporate smooth probe functions, spectral projectors, or higher-frequency Dirichlet consistency.
252
+
253
+ ## 10. Main research question
254
+
255
+ - Can a simple scalar functional of the kernel predict the bandwidth at which the discrete diffusion operator best approximates the intrinsic Laplace–Beltrami spectrum?
256
+
257
+ - The first proposed answer is to use the maximum of the rescaled coordinate Dirichlet energy.
258
+
259
+ - **The computational part is straightforward:** The energy and exact gradient can be evaluated matrix-free, without any eigendecomposition.
260
+
261
+ - **The scientific question remains open:** Does this maximum reliably select the bandwidth that resolves the greatest number of authentic manifold harmonics?
262
+
263
+ **Main takeaway:** We propose using the rescaled coordinate Dirichlet energy as an inexpensive, differentiable, geometric bandwidth-selection criterion for Diffusion Maps. The initial experiment is designed to test whether its maximum predicts accurate manifold-harmonic recovery, before introducing more sophisticated spectral criteria.
264
+
265
+
266
+ ### Full-kernel BEBN operator API and HF model checkpoints
267
+
268
+ `DMAP(X, β=..., α=0.0)` provides the matrix-free Markov action `T_β @ f`,
269
+ `T_β.gamma(f, g)`, and optional `T_β.solve(k=...)`. The facade uses canonical
270
+ `β` and `τ` attributes with ASCII aliases. `solve(β="auto")` deliberately
271
+ refits β; a fixed `β` otherwise skips fitting. Large modes can be checkpointed
272
+ locally or explicitly pushed to a Hugging Face **model** repository via
273
+ `HF_MODEL` and the environment variable `HF_TOKEN`; input datasets remain
274
+ separate. See `src/flashdiffusion/DMAP_API.md` for examples and cautions.
@@ -0,0 +1,48 @@
1
+ # pyproject.toml
2
+ [build-system]
3
+ requires = ["setuptools>=68", "wheel"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ name = "flashdiffusion"
8
+ version = "0.2.1"
9
+ description = "Matrix-free bandwidth optimization and diffusion geometry on the GPU"
10
+ readme = "README.md"
11
+ requires-python = ">=3.11,<3.14"
12
+ license = {text = "MIT"}
13
+ authors = [
14
+ {name = "Sparse Trace LLC"}
15
+ ]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Environment :: GPU :: NVIDIA CUDA :: 12",
20
+ "Intended Audience :: Science/Research",
21
+ "Topic :: Scientific/Engineering :: Mathematics",
22
+ ]
23
+
24
+ dependencies = [
25
+ "xgemm>=0.3,<0.4",
26
+ "jax",
27
+ "numpy",
28
+ "scipy",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ cuda12 = [
33
+ "jax[cuda12]",
34
+ "cupy-cuda12x>=14,<15",
35
+ "cuvs-cu12",
36
+ ]
37
+ test = ["pytest"]
38
+ examples = ["matplotlib"]
39
+
40
+ [project.urls]
41
+ Repository = "https://github.com/sparsetrace/FlashDiffusion"
42
+
43
+ [tool.setuptools]
44
+ package-dir = {"" = "src"}
45
+ packages = ["flashdiffusion"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
@@ -0,0 +1,13 @@
1
+ # src/flashdiffusion/__init__.py
2
+ """Matrix-free diffusion geometry: bandwidth, spectrum, and calculus."""
3
+ from importlib.metadata import version
4
+ from .energy import energy, energy_jet, Jet
5
+ from .bandwidth import (METHODS, BandwidthResult, StationaryPoint, select_bandwidth,
6
+ select_bandwidth_berry_harlim, select_bandwidth_median)
7
+ from .mfstar import select_bandwidth_ladder, select_bandwidth_mfstar
8
+ from .flashdiffusion import FlashDiffusion
9
+
10
+ __version__ = version('flashdiffusion')
11
+ __all__ = ['FlashDiffusion', 'energy', 'energy_jet', 'Jet', 'METHODS', 'BandwidthResult',
12
+ 'StationaryPoint', 'select_bandwidth', 'select_bandwidth_ladder',
13
+ 'select_bandwidth_mfstar', 'select_bandwidth_berry_harlim', 'select_bandwidth_median']