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