Streaming Algorithms for Gaussian Kernel Density Statistics
Qin Zhang
Abstract
Motivated by data produced by generative systems, [LZ26b] formulates similarity-aware statistics via a weighted similarity graph, replacing equality with similarity in classical frequency-based statistics. Although this framework captures semantic relationships between nonidentical items, under general similarity functions even coarse one-pass approximation can require linear space. We therefore ask whether the geometric structure present in natural vector similarities can overcome this barrier. We answer this question affirmatively for the Gaussian kernel. For fixed-dimensional Euclidean vector streams, we study similarity-aware analogues of classical frequency statistics, including the number of distinct elements and frequency moments, through the diversity index and Gaussian density moments. We give one-pass sublinear-space approximation algorithms that exploit the geometric and analytic properties of the Gaussian kernel, and complement them with lower bounds. Our results show that geometric structure can fundamentally change the streaming complexity of similarity-aware statistical analysis.
1 Introduction
Frequency is meaningful only after specifying when two items should count as the same. Classical frequency-based statistics make this choice using exact equality: the frequency of an item is the number of dataset items identical to it. Equivalently, each dataset item contributes either zero or one, according to the equality indicator. For data produced by modern generative systems, however, exact equality is often too rigid. Two texts or images may be distinct as data objects while expressing the same concept or content, and their similarity may be real-valued rather than binary. For frequency-based statistical analysis of such data, it is therefore natural to replace equality with similarity, allowing each dataset item to contribute according to its similarity to the item of interest.
Formally, let S=(s1,…,sn)∈Un be a dataset, and let sim:U×U→[0,1] be a symmetric similarity function satisfying sim(x,x)=1. We define the similarity-aware frequency, or weighted degree, of si by
Di=j∈[n]∑sim(si,sj).
Equivalently, the dataset induces a complete weighted similarity graph with a self-loop at every vertex. The vertices are the input items, and the edge weights are their pairwise similarities. The quantity Di is the weighted degree of vertex i.
Exact equality is recovered as the special case sim(x,y)=1[x=y]. Thus, the degree moments Mp=∑i∈[n]Dip generalize the classical frequency moments Fp+1=∑a:fa>0fap+1, where fa is the number of occurrences of item a in the dataset. The reciprocal-degree sum M−1=∑i∈[n]Di−1 similarly provides a similarity-aware analogue of the number of distinct elements.
We study the computation of these statistics in the standard data stream model [FM85, AMS99]. The items arrive sequentially, and the algorithm must use a small amount of memory to compute a function of the input stream. The similarity graph is not presented explicitly: only its vertices (the items) arrive in the stream, and an edge weight can be obtained only by evaluating sim(⋅,⋅) on two items currently stored in memory. Consequently, the algorithm can neither store the entire dataset nor explicitly construct the similarity graph. It must instead estimate global statistics of the implicit graph using a compact streaming sketch.
The study of streaming statistics under general similarity functions was initiated in [LZ26b]. This generality comes at a significant cost: for general similarities, any one-pass constant-factor approximation to M−1 requires Ω(n) bits of space, and analogous linear-space lower bounds hold for Mp ( p≥1) [LZ26b]. Thus, unlike their classical frequency-based counterparts, similarity-aware statistics under general similarity functions do not admit sublinear-space one-pass algorithms. This raises the question of whether structure in a specific, natural similarity function can overcome the barrier. Our answer is affirmative for the Gaussian kernel: in fixed dimension, we give one-pass sublinear-space algorithms by exploiting analytic and geometric structure specific to the Gaussian kernel.
Recent work [Zha26] gave a complementary affirmative answer for cosine similarity, where low-rank Gram structure leads to one-pass algorithms whose space depends primarily on the representation dimension rather than on the stream length. Our results show that low-rank algebraic structure is not the only mechanism that can overcome the general-similarity barriers: the spatial decay and Euclidean geometry of the Gaussian kernel provide a different route to sublinear space.
Gaussian kernel similarity and density statistics. Let d be a fixed dimension, and let P=(p1,…,pn) be a stream of n points in Rd. For a bandwidth parameter σ>0, the Gaussian kernel is
Kσ(x,y):=exp(−2σ2∥x−y∥22).
The (unnormalized) Gaussian kernel density of a stream point pi is defined as DiKσ:=∑j∈[n]Kσ(pi,pj). Because each point has unit similarity to itself, 1≤DiKσ≤n.
We study three fundamental statistics.
• Diversity index: M−1Kσ(P):=∑i∈[n](DiKσ)−1. To be consistent with prior work [LZ26b], we denote M−1Kσ by DIKσ. Intuitively, the diversity index discounts multiplicity and measures the effective number of distinct regions represented by the stream.
First density moment: M1Kσ(P):=∑i∈[n]DiKσ. This quantity can be viewed as a soft self-similarity join size. It measures the total amount of pairwise similarity in the stream.
• Higher density moments: MpKσ(P):=∑i∈[n](DiKσ)p for a fixed integer p>1. Higher density moments place greater weight on dense regions.
When the kernel is clear from context, we omit the superscript Kσ and write the corresponding statistics simply as Di, DI (or M−1), M1, and Mp.
Conventions. We consider insertion-only streams and treat the dimension d as a fixed constant. When considering the higher moments Mp, we assume that p > 1 is a fixed integer.
For our upper bounds, space is measured in words; each coordinate of an input point and each scalar quantity occupies one word; hence a point in Rd occupies O(d)=O(1) words. We assume access to independent random reals and truly random hash functions. These idealizations can be removed using finite-precision discretization and sufficiently independent hash families, with the resulting errors absorbed into the approximation and failure-probability budgets. Our lower bounds are measured in bits.
For a nonnegative quantity X, we call X a (1+ϵ,δ)-approximation to X if (1−ϵ)X≤X≤(1+ϵ)X with probability at least 1−δ, and, for α≥1, an α-approximation if X/α≤X≤αX; we use the former for relative-error guarantees and the latter for constant-factor or coarser ones. We drop δ when it is clear from context, and call an algorithm δ-error if it succeeds with probability at least 1−δ. We assume 0<ϵ<1/2 throughout, without loss of generality: for ϵ≥1/2 one may run the algorithm with parameter 1/2, at only a constant-factor cost in space.
We omit floor and ceiling operators when they do not affect the asymptotic complexity, and, unless otherwise specified, log denotes log2. Constants hidden in Od(⋅) may depend on d, while those hidden in Op,d(⋅) may depend on both p and d.
Our results. In this paper, we give the following results.
Diversity index. We give a one-pass algorithm that outputs a (1+ϵ,δ)-approximation to DI(P) using Od(ϵ−2d−4logO(d)ϵδn) words of space; see Theorem 2.1. For fixed d, ϵ, and δ, the dependence on the stream length is only polylogarithmic. We complement this upper bound by establishing an Ωd(logd/2n)-bit space lower bound for one-pass (1.01,1/3)-approximation to DI(P); see Theorem 2.11.
First density moment. We give a one-pass streaming algorithm that outputs a (1+ϵ,δ)-approximation to M1(P) using O(ϵ−2logδ1) words of space; see Theorem 3.1. We complement this upper bound by a lower bound: there is an absolute constant c0>0 such that, for every fixed γ>0 and every n−1/2+γ≤ϵ≤c0, any one-pass 1/3-error algorithm that (1+ϵ)-approximates M1(P) requires Ω(ϵ−2logn) bits of space; see Theorem 3.7.
Higher density moments. For every fixed integer p>1, we give a one-pass streaming algorithm that outputs a (1+ϵ,δ)-approximation to Mp(P) using Op,d(ϵ−2n1−1/(p+1)logn⋅logδ1) words of space; see Theorem 4.1. We complement this upper bound by a lower bound stating that, for every Cpn−1/(p+1)≤ϵ≤1/20 where Cp is a sufficiently large constant, any one-pass 1/3-error algorithm that (1+ϵ)-approximates Mp(P) requires Ωp(ϵ−2n1−2/(p+1)/logn) bits of space; see Theorem 4.8.
Table 1 gives a comparison between general similarity functions and the Gaussian kernel. The comparison shows that geometric structure changes the landscape of one-pass space complexity.
1.1 Related Work
Classical streaming statistics. Distinct elements (F0) and frequency moments (Fp) are central problems in data stream algorithms (e.g., [FM85, AMS99, BJK+02, KNW10]; see [Mut05] for a survey). As noted above, under the equality kernel, the diversity index, first density moment, and p-th density moment reduce to F0,F2, and Fp+1, respectively. Under the Gaussian kernel, however, similarity varies smoothly with distance, so the corresponding density statistics depend on the full geometric density structure of the point set rather than on discrete frequency classes.
Near-duplicate streams and general similarities. Prior work on streaming data with near-duplicates has studied robust distinct elements and distinct sampling in low-dimensional Euclidean or structured metric
Problem
General similarity functions
Gaussian kernel (this paper)
Diversity index Dl
An O(1)-approximation requires Ω(n) bits in one pass [LZ26b].
One-pass (1+ϵ)-approximation using Od(ϵ−2d−4logO(d)(n/ϵ)) words.
First density moment M1
An O(1)-approximation requires Ω(n) bits in one pass [LZ26b].
One-pass (1+ϵ)-approximation using O(ϵ−2) words.
p-th density moment, Mp (p>1)
An O(n(p−1)/2)-approximation requires Ω(n) bits in one pass [LZ26b].
One-pass (1+ϵ)-approximation using Op,d(ϵ−2n1−1/(p+1)logn) words.
Table 1: Streaming complexity for general similarity functions versus the Gaussian kernel. The Gaussian bounds assume a fixed dimension d. The success probability is set to 0.99 throughout.
spaces [CZ16, CZ18, Zha25, LZ26a]. These works mainly consider settings in which the data are well-shaped and the induced threshold similarity graph is close to a disjoint union of cliques. More recent work [LZ26b] studied statistics of an implicit similarity graph under general similarity function. Closest to ours is [Zha26], which considered cosine similarity and obtained one-pass algorithms whose space depends primarily on the representation dimension, exploiting the low-rank Gram structure of normalized vectors. Our work specializes this framework to the Gaussian kernel and investigates how its analytic and geometric structure changes the one-pass streaming complexity.
Kernel sums and density estimation. Kernel density estimation and kernel-sum approximation are fundamental tools in machine learning, computational geometry, and databases. A major line of work develops compact coresets that approximate the kernel density uniformly over all query points. Phillips and Tai established near-optimal coreset bounds for broad classes of positive-definite kernels, and Tai subsequently obtained an optimal-size coreset for Gaussian KDE in fixed dimension [PT20, Tai22]. Charikar et al. developed high-dimensional data structures for relative-error KDE based on density-constrained near-neighbor search [CKNS20], while Coleman and Shrivastava designed sketches for pointwise KDE queries [CS20]. These works approximate kernel-density queries, either uniformly or at specified query points. In contrast, we directly estimate global aggregates of the kernel densities evaluated at the streamed data points.
Similarity-sensitive diversity measures. The diversity index is closely related to similarity-sensitive diversity measures. Let u be the uniform distribution on P, and let Zij=Kσ(pi,pj). The order-zero diversity of Leinster and Cobbold satisfies 0DZ(u)=∑i∈[n](Zu)iui=∑i∈[n]Di1=Dl(P), so our diversity index is precisely their order-zero similarity-sensitive diversity [LC12]. Under the equality kernel, this quantity reduces to the distinct elements F0. For a symmetric Boolean similarity function, it becomes the Caro–Wei quantity ∑v1/(deg(v)+1) [Car79, Wei81]. The latter has been studied in edge-arrival and explicit vertex-arrival graph streams [CDK18].1 In contrast, our graph is an implicit complete weighted graph induced by a stream of points through the Gaussian kernel.
1In the explicit vertex-arrival graph stream model, vertices arrive one by one along with their set of incident edges to previously arrived vertices.
2 Diversity Index
In this section, we give a one-pass upper bound and a dimension-dependent bit-space lower bound for the diversity index.
Theorem 2.1. There is a one-pass streaming algorithm that, given a stream P=(p1,…,pn) of n points in Rd for a fixed dimension d, outputs a (1+ϵ,δ)-approximation to DI(P). The algorithm uses Od(ϵ−2d−4logO(d)ϵδn) words of space.
Algorithmic overview. We first discretize Rd by a sufficiently fine grid. For an occupied cell g with center zg, let Dg=∑j∈[n]Kσ(zg,pj) and let ng be the number of stream points in g. The grid resolution ensures that Dg=(1±O(ϵ))Di for every pi∈g, reducing the problem to estimating DIΔ(P):=∑g∈Goccng/Dg. To estimate the reciprocal 1/Dg, we use an exponential lower envelope. If E1,…,En are independent unit-rate exponential random variables, then minj∈[n]Ej/Kσ(zg,pj) is exponential with rate Dg and has expectation 1/Dg. Truncating these envelopes makes every stream update local.
We call a grid cell active if its center lies within the truncation radius of some stream point; these are precisely the cells that can receive a nonnegligible local update. The key to our analysis is a geometric packing lemma showing that the number of active cells is at most β⋅DI(P), where β=Od(ϵ−dlog2dϵδn). We can therefore subsample active cells and combine independent estimates using a median-of-means procedure, leading to the bound in Theorem 2.1.
For ease of presentation, we assume that the stream length n is known in advance. This assumption is not essential: it suffices to know any polynomial upper bound N≥n, which can be used in place of n in all algorithm parameters without changing the stated asymptotic space bound, since n appears only through logarithmic factors.
2.1 Grid and Cell Densities
We begin with some geometric properties of the Gaussian kernel. Let Γ:=CΓlog(ϵδn) for a sufficiently large constant CΓ=CΓ(d). Let Δ:=CΔΓϵσ, where CΔ=CΔ(d) is another sufficiently large constant. We impose the fixed axis-aligned grid
G:={gk:k∈Zd},wheregk:=Δ(k+[0,1)d).
Thus, each cell gk has side length Δ and center zgk:=Δ(k+211). We identify each cell gk with its index k∈Zd whenever the cell is used as a key for hashing or sampling.
Let ρ:=dΔ be the diameter of each cell. For each cell g, let Pg:={i:pi∈g} be the set of indices of points contained in g, and let ng:=∣Pg∣ be the number of points in g. Let Gocc:={g:ng>0} be the set of occupied cells. For each cell g, define its cell-center Gaussian density by
Dg:=j∈[n]∑Kσ(zg,pj).
The following lemma relates the density at a point to the density at the center of its grid cell. Intuitively, it shows that, when the grid is sufficiently fine, the cell-center density provides a good approximation to the density of every point in the cell.
Lemma 2.2. For CΔ sufficiently large, for every occupied cell g and every i∈Pg, (1−20ϵ)Di≤Dg≤(1+20ϵ)Di. Consequently, if we define DIΔ(P):=∑g∈GoccDgng, then DIΔ(P)=(1±10ϵ)DI(P).
Proof. Fix i∈Pg. Then ∥zg−pi∥2≤ρ. Define R0:=σ2ln(ϵ40n).
With CΔ large enough, 2ρ(R0+ρ)+ρ2 is at most cΔϵσ2 for a sufficiently small absolute constant cΔ. For such a j, compare the two Gaussian terms by taking their ratio:
where the last step uses Di≥1 and ϵ<1/2. This proves the first claim.
For the second claim, the first claim implies that for every i∈Pg, Dg1=(1±10ϵ)Di1, where we again use ϵ<1/2. Summing over all occupied cells gives
We shall also use the following immediate consequences.
Lemma 2.3. If a cell g is occupied, then Dg≥ng/2. Moreover, if i∈Pg, then Di≤2Dg.
Proof. For the first claim, since g is occupied, every point pi∈Pg satisfies ∥zg−pi∥2≤ρ. Hence
Dg≥i∈Pg∑Kσ(zg,pi)≥exp(−2σ2ρ2)ng≥21ng,
where the last inequality follows from the choice of the grid diameter ρ.
For the second claim, Lemma 2.2 gives Dg≥(1−ϵ/20)Di≥Di/2 for every i∈Pg. Therefore, Di≤2Dg.
2.2 A Packing Bound for Active Cells
For the Gaussian kernel, it suffices to consider only cells within a logarithmic radius of a stream point, because contributions from all remaining cells are negligible.
Definition 2.4 (Active cell set). Let R∗:=σΓ, and define the active cell set as
A:={g∈G:dist(zg,P)≤R∗},
where dist(zg,P)=minp∈P∥zg−p∥2.
The following lemma bounds the number of active cells in terms of DI(P). This bound is the key structural fact underlying both the algorithm and its analysis.
Lemma 2.5 (Active-cell packing). Let β=Cβϵ−dΓ2d for a sufficiently large constant Cβ=Cβ(d). We have ∣A∣≤β⋅DI(P).
Proof. Partition Rd into axis-aligned boxes of side length R∗, and let B be the set of boxes containing at least one input point. For a box b∈B, let nb be its number of points. Identifying boxes with their integer grid indices, define the neighboring-box set
N(b):={b′∈B:∥b−b′∥∞≤1},andnN(b):=b′∈N(b)∑nb′.
The number of boxes in N(b) is at most 3d.
If pi∈b, then points outside N(b) are at distance at least R∗ from pi. Hence, their total contribution to Di is at most n⋅exp(−2σ2(R∗)2)=ne−Γ/2≤1 for a large enough constant CΓ. Therefore, Di≤nN(b)+1≤2nN(b). Thus
DI(P)≥21b∈B∑nN(b)nb.(1)
Call an occupied box b good if every occupied neighboring box b′∈N(b) satisfies nb′≤2nb, and bad otherwise. Let Bgood⊆B denote the set of good boxes. If b is good, then nN(b)≤2⋅3dnb, so nb/nN(b)≥1/(2⋅3d). Restricting the sum in (1) to good boxes gives
Every bad box has a neighboring occupied box with more than twice its occupancy. Iterating this step, the occupancies double at each move, so the chain reaches a good box after at most log2n moves. Hence every occupied box lies within ℓ∞ box-distance O(logn) of a good box. Therefore, ∣B∣≤Od(logdn⋅∣Bgood∣). Combining this with (2) gives
∣B∣≤Od(logdn⋅DI(P)).(3)
Now pass from occupied R∗-boxes to active fine-grid cells. If a point lies in a box b, then every active cell caused by that point has center within distance R∗ of the point. Thus each occupied box can create active cells only within an Od(R∗)-neighborhood of the box. The number of such grid cells is at most Od((ΔR∗)d)=Od((ϵΓ)d). Using (3) and the fact that logn=O(Γ), we have
∣A∣≤Od((ϵΓ)dΓdDI(P))=Od(ϵ−dΓ2dDI(P)).
The lemma follows by taking Cβ sufficiently large.
2.3 Exponential Lower Envelopes and Local Updates
We estimate DIΔ(P)=∑g∈Goccng/Dg, where Dg=∑j=1nKσ(zg,pj). Recall that by Lemma 2.2, DIΔ(P) is a good approximation to DI(P).
For each occupied cell g, we define a random quantity whose expectation approximates 1/Dg. Multiplying this quantity by the cell count ng then gives an estimator for ng/Dg.
Sample E1,…,En∼Exp(1) independently, and fix a cell center zg. We call Ej the exponential rank of pj. By the scaling property of exponential random variables, Ej/Kσ(zg,pj)∼Exp(Kσ(zg,pj)).
Define the lower envelope at cell g by
Yg∘:=j∈[n]minKσ(zg,pj)Ej.
This is the minimum of independent exponential random variables with rates Kσ(zg,pj). Hence, for every t≥0,
Thus Yg∘∼Exp(Dg), and E[Yg∘]=1/Dg. Consequently, E[∑g∈GoccngYg∘]=∑g∈GoccDgng=DIΔ(P).
The challenge is that the exact quantity Yg∘ cannot be maintained using local streaming updates. In principle, every arriving point has a candidate value for every grid cell, so maintaining all exact minima would be infeasible. We therefore truncate the envelope at T:=CTlog(1/ϵ), where CT is a sufficiently large absolute constant, and define
Yg:=min{T,Yg∘},andW:=g∈Gocc∑ngYg.
The truncation makes updates local: once the stored value is capped at T, a point pj can matter for cell g only if the quantity Ej/Kσ(zg,pj) is below T.
The following lemma shows that truncation introduces only a small bias.
Lemma 2.6. E[W]=(1±ϵ/4)Dl(P).
Proof. For Y∼Exp(λ),
E[min{T,Y}]=∫0TPr[Y>t]dt=∫0Te−λtdt=λ1−e−λT.
Thus truncating loses exactly 1/λ−E[min{T,Y}]=e−λT/λ. By Lemma 2.3, every occupied cell has Dg≥ng/2≥1/2. Hence
0≤Dg1−E[Yg]=Dge−DgT≤Dge−T/2.
Multiplying by ng and summing over occupied cells gives
0≤DIΔ(P)−E[W]≤e−T/2DIΔ(P)≤10ϵDIΔ(P),(4)
where the last inequality holds by choosing CT large enough so that e−T/2≤ϵ/10. Therefore, (1−ϵ/10)DIΔ(P)≤E[W]≤DIΔ(P). The lemma follows from Lemma 2.2.
The next lemma bounds the variance of W. The main observation is that the square of the cell sum can be controlled by the number of occupied cells. Since every occupied cell is active, this number is at most the number of active cells. Lemma 2.5 then converts this geometric bound into a bound in terms of DI(P), with a loss of the packing factor β.
Lemma 2.7. E[∑g∈Gocc(ngYg)2]≤8Dl(P), and E[W2]≤8β⋅Dl(P)2.
Proof. Since Yg≤Yg∘ and Yg∘∼Exp(Dg), we have E[Yg2]≤E[(Yg∘)2]=2/Dg2. Therefore,
Eg∈Gocc∑(ngYg)2≤2g∈Gocc∑Dg2ng2.
For an occupied cell g, Lemma 2.3 gives ng/Dg≤2 and Di≤2Dg for every i∈Pg. Hence
Summing over all cells gives ∑g∈Goccng2/Dg2≤4DI(P), and the first claim follows.
For the second claim, by Cauchy-Schwarz,
W2=g∈Gocc∑ngYg2≤∣Gocc∣g∈Gocc∑(ngYg)2.
Since every occupied cell has its center within distance ρ≤R∗ of an input point, Gocc⊆A. Lemma 2.5 gives ∣Gocc∣≤∣A∣≤β⋅D∣(P). Taking expectations and using the first claim gives E[W2]≤8β⋅D∣(P)2. □
Local updates suffice. We now show that the truncated envelope can be maintained by local updates. Suppose a new point pj with exponential rank Ej arrives. Its candidate value for cell g is Ej/Kσ(zg,pj). Because the stored value at g is Yg=min{T,Yg∘}≤T, this point can change the stored value only if Ej/Kσ(zg,pj)<T. Using Kσ(zg,pj)=exp(−2σ2∥zg−pj∥22), this condition is equivalent to Ejexp(2σ2∥zg−pj∥22)<T, and hence to
∥zg−pj∥2<σ2ln(T/Ej).(5)
Thus, a point with rank Ej<T only needs to be tested against cells in the ball of radius σ2ln(T/Ej) around it. If Ej≥T, no cell can be updated.
Note that the radius in (5) is random, since it depends on the random exponential rank Ej. In the final algorithm (see Section 2.5), we will use a median-of-means estimator with a total of nrep=O(βϵ−2log(1/δ)) repetitions. Accordingly, for each point pj, we generate independent exponential ranks Ej(1),…,Ej(nrep) and use one independent rank for each repetition. The following lemma shows that, with high probability, the fixed active radius R∗ suffices for all relevant updates, simultaneously over all stream points and all repetitions used by the algorithm.
Lemma 2.8. With probability at least 1−δ/20, for every input point pj, every repetition r∈[nrep], and every cell g, the value Yg(r) can change because of pj only if ∥zg−pj∥2≤R∗. Moreover, no cell is updated if Ej(r)≥T.
Proof. Define α:=δ/(20n⋅nrep). For each r∈[nrep], let Ei(r) be the exponential rank assigned to pi in repetition r. Since Pr[Ei(r)<α]≤α for an Exp(1) random variable, a union bound gives
Pr[i∈[n],r∈[nrep]minEi(r)<α]≤n⋅nrep⋅α=20δ.
If mini∈[n],r∈[nrep]Ei(r)≥α, then every relevant update radius is at most σ2ln(T/α). We choose CΓ in the definition of Γ=CΓlog(n/(ϵδ)) large enough so that 2ln(T/α)≤Γ. This is possible because log(T/α)=Od(logϵδn+logΓ). Therefore, except with probability at most δ/20, every cell that can ever be affected by a truncated-envelope update is contained in A={g∈G:dist(zg,P)≤R∗}, where R∗=σΓ. □
2.4 Sampling Active Cells
The active set A, whose size is bounded by βD∣(P), may still be too large to store explicitly. We thus perform subsampling. Let U:=∣A∣. We maintain a standard F0 estimator for U, such as the algorithm of [KNW10], based on updates to active cells and using randomness independent of all cell-sampling hashes and exponential ranks. Active-cell updates are generated by enumerating all grid cells whose centers are within distance R∗ of each arriving point. Using O(log(n/δ)) words, the F0-estimator maintains a value U such that, with probability at least 1−δ/20,
21U≤U≤2U.(6)
Let Lmax:=⌈log2n⌉+1 and L:={0,1,…,Lmax−1}. The algorithm runs geometric sampling levels pℓ=2−ℓ for ℓ∈L, and nrep repetitions for each level. Set K0:=CKβϵ−2log(δnrepLmax), where CK is a sufficiently large constant. For each repetition r∈[nrep] and level ℓ∈L, we use an independent uniform hash function hr,ℓ:G→[0,1] to sample a cell g when hr,ℓ(g)≤pℓ. The dictionary Dr,ℓ for each pair (r,ℓ) stores sampled active cells, capped at CcapK0 cells. Each stored cell is represented as a tuple (g,ng,Yg(r)): the cell index g, its count ng, and its current truncated envelope value Yg(r).
At the end of the stream, we choose a level ℓ∗ using U. If U≤K0, take ℓ∗=0, so pℓ∗=1. Otherwise, choose the smallest level ℓ∗∈L satisfying pℓ∗≤K0/U; if no such level exists, take ℓ∗=Lmax−1. On the event in (6), we have
min{1,4UK0}≤pℓ∗≤min{1,U4K0}.(7)
If the selected level satisfies pℓ∗=1, then U≤2K0 on the event (6). Otherwise, pℓ∗<1, and by (7) the expected number of sampled active cells at the selected level is pℓ∗U≤4K0. By a Chernoff bound, for a sufficiently large constant Ccap, the number of sampled active cells exceeds CcapK0 with probability at most δ/(20nrep) in any repetition. Taking a union bound over all nrep repetitions, the sampled set at the selected level ℓ∗ exceeds the storage cap in some repetition with probability at most δ/20.
For each repetition r∈[nrep], let Sr,ℓ∗ denote the uncapped set of active cells sampled at the selected level, and define the conceptual estimator
Wr:=pℓ∗1g∈Sr,ℓ∗∑ngYg(r).
On the event that the selected dictionary does not overflow, the implemented estimator equals this conceptual estimator. Conditional on the selected level and the exponential ranks, Wr is an unbiased estimator of Wr:=∑g∈GoccngYg(r).
Lemma 2.9. On the event in (6), for each selected level ℓ∗ and each r∈[nrep], writing μ:=E[Wr], E[(Wr−μ)2∣ℓ∗]≤16β⋅D∣(P)2.
Proof. Fix a repetition r and the selected level ℓ∗, and write E(r):=(Ej(r))j∈[n] for the vector of exponential ranks. Under this conditioning, the values Yg(r) and Wr=∑g∈GoccngYg(r) are fixed. The only remaining randomness in Wr is the sampling of cells. Let Ig be the indicator that cell g is sampled at level ℓ∗, and write θ:=pℓ∗. Then
Wr=θ1g∈Gocc∑IgngYg(r).
The indicators Ig are independent Bernoulli random variables with mean θ. Hence E[Wr∣ℓ∗,E(r)]=Wr, and
Var(Wr∣ℓ∗,E(r))≤θ1g∈Gocc∑(ngYg(r))2.
If θ=1, this conditional variance is zero. If θ<1, then (7) gives 1/θ≤4U/K0. Since U=∣A∣≤β⋅D∣(P)
Algorithm 1: Initialize the grid sketch
Input: Stream of n points in Rd for a fixed dimension d, bandwidth σ, accuracy parameter ϵ, failure probability δ.
Output: Initialized sketch state.
1 Set Γ←CΓlog(n/(ϵδ)), R∗←σΓ, and Δ←ϵσ/(CΔΓ) // active radius and grid side length
2 Set T←CTlog(1/ϵ) // truncation threshold
3 Set β←Cβϵ−dΓ2d // packing factor
4 Set bm←Cbβϵ−2, κm←Cκlog(1/δ), and nrep←bmκm // median-of-means block size, number of blocks, and total repetitions per sampling level
5 Set Lmax←⌈log2n⌉+1, L←{0,1,…,Lmax−1}, and pℓ←2−ℓ for every ℓ∈L
6 Set K0←CKβϵ−2log(nrepLmax/δ) // sampled-cell budget
7 Initialize an F0 estimator F0 for the active-cell set A
8 for r=1,…,nrep do
9 for ℓ∈L do
10 Draw a random hash function hr,ℓ:G→[0,1] // cell sampling at level ℓ
11 Initialize an empty dictionary Dr,ℓ with cap CcapK0 and overflow flag set to false
where the second inequality uses Lemma 2.7, and the last uses K0≥4.
It remains to account for the randomness of the exponential lower envelope. Because the selected level is independent of the exponential ranks, the conditional law of total variance gives
We now give the complete one-pass implementation of the algorithm. Because the description is lengthy, we split the algorithm into three subroutines. The initialization subroutine (Algorithm 1) fixes the grid, repetitions, sampling levels, and capped dictionaries. The update subroutine (Algorithm 2) is called once for each arriving stream point. The query subroutine (Algorithm 3) selects one sampling level and applies median-of-means to the repetition estimates.
Algorithm 2: Process one stream point
Input: The j-th stream point x.
1 Let gx←g(x)
2 Draw independent ranks Ej(r)∼Exp(1) for all r∈[nrep] // one rank per repetition
// Create sampled records for active cells caused by x
3 foreach g∈Near(x,R∗) do
4 Feed g to F0 // support update for A
5 for r=1,…,nrep do
6 for ℓ∈L do
7 if hr,ℓ(g)≤pℓ and g∈/Dr,ℓ then
8 if Dr,ℓ has fewer than CcapK0 records then
9 Insert (g,0,T) into Dr,ℓ // count starts at 0; envelope is truncated at T
10 else
11 Set the overflow flag of Dr,ℓ to true
// Update the count of the point's own cell in every sampled dictionary that stores it
12 for r=1,…,nrep do
13 for ℓ∈L do
14 if gx is stored in Dr,ℓ then
15 Increase the stored count ngx by 1
// Apply the local lower envelope updates
16 for r=1,…,nrep do
17 if Ej(r)<T then
18 Set Rj(r)←σ2ln(T/Ej(r)) // only cells within this radius can improve
19 foreach g∈Near(x,Rj(r)) do
20 foreach ℓ∈L such that g is stored in Dr,ℓ do
21 Update Yg(r)←min{Yg(r),Ej(r)/Kσ(zg,x)} in Dr,ℓ
For a point x and radius R, write Near(x,R):={g∈G:∥zg−x∥2≤R}. We also write g(x) for the grid cell containing x. For each repetition r and level ℓ, the capped dictionary Dr,ℓ stores records of the form (g,ng,Yg(r)), where g is the cell index, ng is the current number of stream points in g, and Yg(r) is the current truncated lower envelope value for repetition r. If an insertion would exceed the cap, the dictionary sets an overflow flag; this event is charged to the failure probability in the analysis.
In Algorithm 2, records for cells within distance R∗ of the arriving point are created before the count of the point's own cell is incremented; therefore, a sampled active cell does not miss the first point that makes it
Algorithm 3: Query the grid sketch
Output: A (1+ϵ)-approximation to D∣(P).
1 Query F0 to obtain U
2 if U≤K0 then
3 Set ℓ∗←0 \quad // store all active cells at level 0
occupied. The lower envelope update is performed after this insertion step. If Ej(r)≥T, the point cannot improve any truncated envelope value; otherwise, Lemma 2.8 shows that, with a good probability, the radius Rj(r) includes every cell that the point can impact.
2.6 Proof of Theorem 2.1
Proof. By Lemma 2.6, each repetition satisfies μ:=E[Wr]=(1±ϵ/4)D∣(P). Let E0 be the event in (6). Conditional on E0 and on the selected level ℓ∗, Lemma 2.9 gives
E[(Wr−μ)2∣ℓ∗]≤16β⋅D∣(P)2.(10)
For s=1,…,κm, define Ws:=bm1∑r=(s−1)bm+1s,bmWr. Conditional on ℓ∗, the block averages are independent and, by (10), satisfy
Var(Ws∣ℓ∗)≤bm16βD∣(P)2=Cb16ϵ2D∣(P)2.
Choose Cb large enough so that this variance is at most ϵ2D∣(P)2/160. Chebyshev's inequality then gives
Pr[Ws−μ>4ϵD∣(P)ℓ∗]≤101
for every block s.
Let Zs:=1{Ws−μ>4ϵD∣(P)} for s=1,…,κm. Let Z:=∑s∈[κm]Zs. Conditional on ℓ∗, the variables Zs are independent and satisfy Pr[Zs=1∣ℓ∗]≤1/10. A Chernoff bound therefore gives Pr[Z≥κm/2∣ℓ∗]≤e−cκm for an absolute constant c>0. Choosing Cκ sufficiently large ensures that, conditional on E0, the median of the conceptual block averages differs from μ by at most 4ϵDI(P) with probability at least 1−δ/2.
On the event that no selected dictionary overflows, the implemented block averages equal the conceptual ones. Combining the median guarantee with the failure probabilities in Lemma 2.8, (6), and the storage-cap analysis gives an overall failure probability of at most δ.
It remains to analyze space. For each repetition and each sampling level, the capped dictionary stores at most O(K0) cell records. There are Lmax levels and nrep=O(βϵ−2logδ1) repetitions. Therefore, the number of stored cell records is
Substituting β=Cβϵ−dΓ2d and Γ=CΓlog(n/(ϵδ)) gives ϵ−2d−4logO(d)(ϵδn) words for fixed d, plus lower-order space for the F0 estimator. This proves the theorem.
2.7 A Dimension-Dependent Space Lower Bound
We next show an Ωd(logd/2n) lower bound for constant approximation in every fixed dimension d. Throughout this subsection, we fix the Gaussian bandwidth to σ=1 and write K(x,y):=exp(−2∥x−y∥22). The result for any other fixed bandwidth follows by scaling all coordinates.
We use the following fixed-weight variant of the standard one-way INDEX problem. The well-known randomized one-way communication complexity of INDEXis Ω(m) [KN97]. The same lower bound holds when Alice's input is promised to have Hamming weight exactly m/2; we include a proof in Appendix 6.1 for completeness.
Lemma 2.10. For an even m, Alice receives a vector x∈{0,1}m satisfying ∥x∥1=m/2, and Bob receives an index i∈[m]. Bob must output xi after receiving one message from Alice. Every randomized one-way protocol with error probability at most 1/3 communicates Ω(m) bits.
In this section, we prove the following theorem.
Theorem 2.11. For every fixed dimension d≥1, any one-pass streaming algorithm that, on every insertion-only stream P of at most n points in Rd, outputs a 1.01-approximation to DI(P) with probability at least 2/3 must use at least Ωd(logd/2n) bits of space.
Proof intuition. The reduction encodes a fixed-weight INDEX instance using well-separated clusters of points, one cluster for each 1-bit. To query a coordinate, Bob appends a sparse d-dimensional lattice cloud around the corresponding cluster center. The cloud contains q=Θd(logd/2n) points, while its Gaussian self-density remains bounded by a constant. If the queried bit is 0, each cloud point contributes a constant amount to the diversity index; if it is 1, the corresponding cluster adds a constant amount to every cloud point's density, decreasing each reciprocal-density contribution by a constant. This creates an Ω(q) gap in a statistic of size O(q), while the large separation between cluster centers makes all unintended interactions negligible. Hence, a constant-accuracy estimate reveals the queried bit, and the one-way INDEX lower bound implies an Ωd(logd/2n)-bit space lower bound.
Proof. We reduce the fixed-weight INDEX problem to constant-accuracy estimation of the Gaussian diversity index. Set λ:=2ln(8d) and consider the lattice λZd. Its total Gaussian similarity sum with respect to the origin is bounded by an absolute constant:
Let Nc:=⌊n⌋, r:=2lnNc, and t:=⌊λdr⌋, and define the “probe cloud”
Q:={λz:z∈Zd,∥z∥∞≤t}.
Write q:=∣Q∣=(2t+1)d. For fixed d,
q=Θd(rd)=Θd(logd/2n).(11)
Moreover, every z∈Q satisfies
∥z∥2≤λdt≤r.(12)
For z∈Q, let az:=∑y∈QK(z,y) be the density contributed by the cloud itself. Since Q⊆λZd,
1≤az≤Bd<2.(13)
Now suppose that Nc points are placed at the origin. Their contribution to the density of z is
bz:=Nc⋅K(0,z)=Ncexp(−2∥z∥22).
By (12),
bz≥Nce−r2/2=1.(14)
It follows from (13) and (14) that the Nc points at the origin decrease the reciprocal-density contribution of every cloud point by a constant amount:
az1−az+bz1=az(az+bz)bz≥61.(15)
The reduction. Consider fixed-weight INDEX with m:=2q, so Alice’s vector has exactly q ones. Let e1 be the first standard basis vector of Rd, set L:=r+10lnn, and define centers cj:=jLe1 for every j∈[m].
Given x∈{0,1}m with ∥x∥1=q, Alice inserts Nc copies of cj for every j satisfying xj=1. She then sends the streaming algorithm's memory state to Bob. Given i∈[m], Bob appends the translated cloud
ci+Q={ci+z:z∈Q}.
The resulting stream contains qNc+q=q(Nc+1) points. By (11) and the choice Nc=⌊n⌋, this is at most n for a fixed d and sufficiently large n.
Analysis with the idealized instances. We first ignore all interactions between distinct Alice clusters, and all interactions between the probe cloud and Alice clusters other than the queried cluster at ci. Let Vb denote the resulting idealized diversity index when xi=b.
If xi=0, all q Alice clusters are isolated. Each cluster consists of Nc identical points and therefore contributes exactly one to the diversity index. Hence
V0=q+z∈Q∑az1.(16)
If xi=1, there are q−1 unaffected Alice clusters. Let SQ:=∑z∈QK(0,z). The Nc points at the queried center have density Nc+SQ and together contribute Nc/(Nc+SQ). The cloud point indexed by z has density az+bz. Therefore,
V1=(q−1)+Nc+SQNc+z∈Q∑az+bz1.(17)
Subtracting (17) from (16) and using (15), we obtain
The actual instance. Two distinct Alice centers are separated by at least L. Every cloud point lies within distance r of ci, so its distance from any Alice center cj with j=i is at least L−r=10lnn. Thus every interaction omitted from the idealized instance has Gaussian weight at most exp(−2(L−r)2)=n−50. There are at most n points in the stream, so the total directed Gaussian mass of all omitted interactions is at most n−50⋅n2=n−48.
For a point v, let Dv be its density in the idealized instance and write its actual density as Dv=Dv+Ev, where Ev≥0 is the contribution of the omitted interactions. Since Dv,Dv≥1,
0≤Dv1−Dv1=DvDvEv≤Ev.
Summing over all points shows that, uniformly over all valid INDEX inputs with xi=b,
for all sufficiently large n. Consequently, the possible (1+ϵ0)-approximation ranges in the cases xi=0 and xi=1 are disjoint. Bob can recover xi by comparing the output with any fixed threshold between these two ranges. Thus, Lemma 2.10 implies that Alice's memory state must have size at least Ω(m)=Ω(q)=Ωd(logd/2n) bits, where the last equality follows from (11).
3 First Density Moment
In this section, we study the first density moment and establish the following result.
Theorem 3.1. There is a one-pass streaming algorithm that, given a stream P=(p1,…,pn) of n points in Rd for a fixed dimension d, outputs a (1+ϵ,δ)-approximation to M1(P). The algorithm uses O(ϵ−2logδ1) words of space.
Algorithmic overview. The Gaussian kernel has an exact continuous square-root feature identity: there are functions qx∈L2(Rd) such that ⟨qx,qy⟩=Kσ(x,y). Consequently, for Q=∑i∈[n]qpi, M1(P)=∥Q∥L2(Rd)2. We discretize and truncate the continuous features to obtain a deterministic sparse local feature map ϕ satisfying a uniform additive kernel error of η/n. If V=∑i∈[n]ϕ(pi), then ∥V∥22=(1±η)M1(P). The additive feature error becomes relative because M1(P)≥n, and an AMS second-moment sketch estimates ∥V∥22 in one pass using O(ϵ−2logδ1) words.
Again, for ease of presentation, we assume that the stream length n is known in advance. This assumption is not essential: it suffices to know any polynomial upper bound N≥n, which can be used in place of n in the feature-map parameters without changing the stated asymptotic space bound, since n appears only through logarithmic factors in these parameters.
Continuous feature identity. The starting point of our algorithm is an exact continuous feature representation of the Gaussian kernel. For every x∈Rd, define
qx(z)=(πσ22)d/4exp(−σ2∥z−x∥22),∀z∈Rd.
This is a square-root Gaussian feature: the inner product of two such functions equals the Gaussian kernel. For completeness, we prove the identity in Appendix 6.2.
Lemma 3.2. For all x,y∈Rd, ⟨qx,qy⟩L2(Rd)=Kσ(x,y). Consequently, if Q(z)=∑i∈[n]qpi(z), then M1(P)=∥Q∥L2(Rd)2.
A shared local feature grid. Our algorithm uses a deterministic local feature map for the Gaussian kernel. This is in the same spirit as explicit finite-dimensional feature approximations for shift-invariant kernels, such as random Fourier features [RR07]. The key difference is that our construction is grid-based and local: each point updates only a bounded neighborhood of grid cells, which is what makes the map suitable for streaming updates.
We now define a discretized and truncated version of qx. Let η=cηϵ be a feature-approximation parameter for a sufficiently small constant cη. Set the feature-grid scale Λη=CΛlogηdn, the feature-grid spacing h=ChΛησ, and the feature truncation radius L=CLσΛη.
For x∈Rd, define the local support S(x)={t∈Zd:∥ht−x∥∞≤L} and the feature vector ϕ(x)∈ℓ2(Zd) by
Since h=σ/(ChΛη)=σ/(ChCΛlog(dn/η)), choosing Ch and CΛ large enough (as functions of the fixed dimension d) makes this last sum at most η/(3n), uniformly in x and y.
It remains to account for truncation. We use the following property of Gaussian density; the proof can be found in Appendix 6.3.
Claim 3.4. For the feature maps ψ and ϕ defined above, if L=CLσΛη and CL,CΛ are sufficiently large as functions of the fixed dimension d, then ∥ψ(u)−ϕ(u)∥2≤12nη uniformly for all u∈Rd.
The same Poisson-summation estimate with x=y=u gives ∥ψ(u)∥2≤2, and ϕ(u) is obtained from ψ(u) by deleting coordinates, so ∥ϕ(u)∥2≤2. Hence, for arbitrary x,y,
Since Di≥1, this is a relative η error for each density. Summing over i gives M1−M1(P)≤ηn. Because all diagonal kernel terms (i.e., Kσ(pi,pi) for i∈[n]) equal 1, M1(P)≥n, so this is also a relative η error for the first Gaussian density moment.
We estimate M1(P) by applying an AMS second-moment sketch [AMS99] to the implicit vector V.
Lemma 3.6 (AMS sketch [AMS99]). Let V∈ℓ2(Zd) be fixed with finite support, and let χ:Zd→{−1,+1} be a 4-wise independent sign function. Define an AMS counter A:=∑t∈Zdχ(t)Vt. For any 0<α<1, suppose bm=Cbα−2 and κm=Cκlog(1/δ) for sufficiently large constants Cb and Cκ. Group bmκm independent AMS counters into κm blocks of size bm, average their squared values within each block, and return the median of the block averages. This median-of-means estimator is a (1+α)-approximation to ∥V∥22 with probability at least 1−δ.
Our algorithm is presented in Algorithm 4. The algorithm uses a deterministic local feature map to reduce the first density moment to an ℓ2-norm estimation problem. Each point x is mapped to a sparse vector ϕ(x) supported on nearby grid coordinates S(x), and for V=∑i∈[n]ϕ(pi) we have ∥V∥22=(1±O(ϵ))M1(P). The stream is processed by maintaining an AMS sketch of this implicit vector V: when x arrives, the algorithm enumerates S(x), computes the weights ϕ(x)t, and updates the sketch. At the end, the AMS estimator returns an approximation to ∥V∥22, which gives the desired estimate of M1(P).
Proof of Theorem 3.1. By Lemma 3.5, ∥V∥22=M1=(1±η)M1(P). By Lemma 3.6 (setting α=ϵ/4), the AMS median-of-means estimator in Algorithm 4 returns a (1+ϵ/4)-approximation to ∥V∥22 with probability at least 1−δ. Taking cη=1/4, the product of the two approximation factors, one from the feature approximation and one from the AMS sketch, is bounded by (1±ϵ). Therefore, Pr[(1−ϵ)M1(P)≤M1≤(1+ϵ)M1(P)]≥1−δ.
Algorithm 4 maintains bmκm=O(ϵ−2log(1/δ)) AMS counters, which dominate the space usage. □
Algorithm 4: One-pass AMS sketch for the first Gaussian density moment
Input: Stream of n points in Rd for a fixed dimension d, bandwidth σ, accuracy parameter ϵ, failure probability δ.
Output: A (1+ϵ)-approximation to M1(P).
1 Set η←cηϵ for a sufficiently small absolute constant cη // feature error
2 Set Λη←CΛlog(dn/η), h←σ/(ChΛη), and L←CLσΛη // feature grid scale, spacing, and truncation radius
3 Set aσ←(2/(πσ2))d/4 // normalization
4 Set bm←Cbϵ−2 and κm←Cκlog(1/δ) // median-of-means block size and number of blocks
5 Choose mutually independent sign functions χs,r:Zd→{−1,+1}, each drawn from a 4-wise independent family, for s=1,…,κm and r=1,…,bm // AMS signs
6 Initialize As,r←0 for all s,r // AMS counters
7 for each stream point x do
8 Enumerate S(x)={t∈Zd:∥ht−x∥∞≤L} // local support
9 foreach t∈S(x) do
10 Set w←hd/2aσexp(−∥ht−x∥22/σ2) // w=ϕ(x)t
11 for s=1,…,κm do
12 for r=1,…,bm do
13 ⨆As,r←As,r+χs,r(t)w
14 for s=1,…,κm do
15 Set Zs←bm−1∑r∈[bm]As,r2
16 return M1←median{Z1,…,Zκm}.
3.1 Lower Bound
We next show that estimating the first Gaussian density moment is at least as hard as estimating the classical second frequency moment. For a stream over a universe U with ∣U∣=poly(n), let fa denote the frequency of item a∈U, and recall that F2(f):=∑a∈Ufa2. For ϵ≥n−1/2+γ, the one-pass space complexity of obtaining a (1+ϵ)-approximation to F2 on a stream of length n is Ω(ϵ−2logn) bits [BZ25].
Theorem 3.7. There is an absolute constant c0>0 such that, for every fixed constant γ>0 and all n−1/2+γ≤ϵ≤c0, any one-pass streaming algorithm that, on every stream of at most n points on the real line, returns a(1+ϵ)-approximation to M1(P) with probability at least 2/3 requires Ω(ϵ−2logn) bits of space.
Proof. We reduce the insertion-only F2 problem to estimating the first Gaussian density moment. Let f=(fa)a∈U be the final frequency vector of the stream, and let ℓ:=∑a∈Ufa≤n be its length. Fix the Gaussian bandwidth to σ=1 and write K:=K1. Fix an arbitrary injective indexing π:U→N. Set η:=100ϵ, and L:=⌈2lnηn⌉. For every occurrence of item a∈U, insert the point
za:=π(a)L∈R.
Thus, the fa occurrences of item a become fa coincident Gaussian points at location za. Distinct item locations are separated by at least L, and hence, for all a=b,
K(za,zb)=exp(−2∣za−zb∣2)≤exp(−2L2)≤nη.
The contribution of pairs at the same location is exactly F2(f). Therefore,
The cross-location contribution is nonnegative and is at most
nηa,b∈Ua=b∑fafb≤nη(a∈U∑fa)2=nηℓ2≤ηℓ.
Since every fa is a nonnegative integer, F2(f)=∑a∈Ufa2≥∑a∈Ufa=ℓ. Consequently,
F2(f)≤M1(P)≤(1+η)F2(f).
Suppose there is a one-pass algorithm using s bits that returns a (1+ϵ/20)-approximation S to M1(P). Then (1−ϵ/20)F2(f)≤S≤(1+ϵ/20)(1+η)F2(f). For η=ϵ/100, this is a (1+ϵ/10)-approximation to F2(f). The Gaussian algorithm would therefore give a one-pass F2 estimator using the same s bits of space. The frequency-moment lower bound implies s=Ω(ϵ−2logn). Replacing ϵ/20 by ϵ changes only the constants.
4 Higher Density Moments
The algorithm for the first density moment relies on a linear sketch of a feature-space aggregate and does not extend directly to p>1. In this section, we give a different one-pass estimator for higher density moments and establish the following result.
Theorem 4.1. Let p>1 be a fixed integer and d a fixed dimension. There is a one-pass streaming algorithm that, given a stream P=(p1,…,pn) of n points in Rd, produces a(1+ϵ,δ)-approximation to Mp(P). The algorithm uses Op,d(ϵ−2n1−1/(p+1)logn⋅logδ1) words of space.
Algorithmic overview. We use a sample-and-probe approach. The algorithm samples candidate points uniformly from the stream and maintains p independent sets of probe samples. For a candidate point pi, each probe set provides an unbiased estimate of Di; multiplying the p independent estimates gives an unbiased estimate of Dip. Averaging over candidates and rescaling then gives an unbiased estimator of Mp(P).
The main challenge is variance. Reusing the same probe samples across many candidates introduces significant correlation, and a black-box moment argument is insufficient. We establish geometric regularity properties of Gaussian densities: a low-density set cannot contribute too much Gaussian mass near a fixed query point, a point of high density forces many points to have comparable density, and Gaussian overlap sums control correlations between different candidates. These bounds give a sample size of Op,d(ϵ−2n1−1/(p+1)logn) per independent copy and, after median amplification, imply Theorem 4.1.
We will first assume that the stream length is known in advance. We then explain in Section 4.3 how to remove this assumption without changing the estimator or its asymptotic space complexity.
4.1 Geometric Regularity of Gaussian Densities
We begin by establishing several properties of density moments in fixed-dimensional Gaussian geometry. For x∈Rd, write D(x):=∑j∈[n]Kσ(x,pj), so that D(pi)=Di. The following lemma states that a set of low-density input points cannot place too much Gaussian mass near any fixed query point.
Lemma 4.2. Let Q be a subset of stream points satisfying D(q)≤θ for every q∈Q. Then for every x∈Rd, ∑q∈QKσ(x,q)≤CQθ for a sufficiently large constant CQ=CQ(d).
Proof. For t=0,1,2,…, define At:={q∈Q:tσ≤∥q−x∥2<(t+1)σ} to be the t-th annulus of points around x.
We first bound ∣At∣. The ball B(x,(t+1)σ) can be covered by CQ′(t+1)d Euclidean balls of radius cσ, for a sufficiently small absolute constant c>0 and a sufficiently large constant CQ′=CQ′(d). Consider one covering ball B with B∩At=∅, and fix q0∈B∩At. For every q∈B∩At, we have ∥q−q0∥2≤2cσ and Kσ(q0,q)≥e−2c2. Since D(q0)≤θ, we have
∣B∩At∣⋅e−2c2≤q∈B∩At∑Kσ(q0,q)≤D(q0)≤θ.
Thus ∣B∩At∣≤e2c2θ, and summing over the covering balls gives
The next lemma says that a point of large Gaussian density cannot be isolated: a large value of Di forces many input points to have comparable density.
Lemma 4.3. For every stream point pi, Mp(P)≥cKDip+1 for a sufficiently small constant cK=cK(p,d).
Proof. Let θ=Di. Apply Lemma 4.2 to Q:={pj:Dj≤θ/(2CQ)} with query point pi. The total contribution of Q to Di is at most θ/2. Hence the complementary subset H:={pj:Dj>θ/(2CQ)} contributes at least θ/2 to Di. Since each Gaussian kernel value is at most 1, this implies ∣H∣≥θ/2. Therefore
Mp(P)≥pj∈H∑Djp≥2θ(2CQθ)p=cKθp+1
for a small enough constant cK
Set τ:=n1/(p+1). Since Di≥1 for every i, we have
Mp(P)≥n=τp+1.(21)
The following lemma bounds the power sums of the densities, which will be used in the subsequent variance analysis of our estimator.
Lemma 4.4. For every integer q∈{0,1,…,p}, ∑i∈[n]Di2p−q=Op,d(τq+1(Mp(P))2logn).
Proof. Define the dyadic density levels La:={i:2a≤Di<2a+1} (a=0,1,…,logn). Since 1≤Di≤n, these levels cover all stream points.
Fix one level La. Since ∑i∈LaDip≤Mp(P), we have ∣La∣≤Mp(P)/2ap. Hence
We next prove an upper bound on TU. Since each kernel value is at most 1, KU(i)≤Kσ(pi,pu1). Consider the dyadic density level La={i:2a≤Di<2a+1}. Applying Lemma 4.2 to the set Q={pi:i∈La} with θ=2a+1 and query point pu1 gives
i∈La∑Kσ(pi,pu1)≤CQ2a+1.
Therefore, the contribution of level La to TU is at most (recall that Cp=2p)
(2a+1)p−q⋅CQ2a+1≤CpCQ2a(p−q+1).(26)
We again analyze two cases:
If 2a≤τ, then using (21) gives
2a(p−q+1)≤τp−q+1≤τqMp(P).(27)
If 2a>τ and La is nonempty, then Lemma 4.3 gives Mp(P)≥cK2a(p+1), and therefore
2a(p−q+1)≤cK−12aqMp(P)≤cK−1τqMp(P).(28)
Combining (27) and (28) with (26) and summing over O(logn) levels gives
Our algorithm is presented in Algorithm 5. At a high level, it samples candidate points uniformly from the stream, uses independent probe samples to estimate their densities, and averages the resulting unbiased estimates of Dip.
Recall that Mp(P)=∑i∈[n]Dip and Di=∑j∈[n]Kσ(pi,pj). If we could sample a point x uniformly from the stream and compute D(x)p=(∑j∈[n]Kσ(x,pj))p exactly, then n⋅D(x)p would be an unbiased estimator for Mp(P).
Algorithm 5: One-pass density-moment estimator
Input: Stream of n points in Rd for a fixed dimension d, bandwidth σ, integer moment parameter p>1, accuracy parameter ϵ, and failure probability δ.
Output: A (1+ϵ)-approximation to Mp(P).
1 Set τ←n1/(p+1), bm←Cbϵ−2τplogn, and κm←Cκlog(1/δ) // density scale, sample size per repetition, and number of repetitions
4 Initialize probe samplers Rℓ,k(r)←⊥ for all ℓ∈[p] and k∈[bm]
// Streaming: maintain independent uniform samples with replacement
5 foreach j-th stream point pj do
6 for r=1,…,κm do
7 for a=1,…,bm do
8 ⨆ With probability 1/j, set Sa(r)←pj
9 for ℓ=1,…,p do
10 ⨆ for k=1,…,bm do
11 ⨆ With probability 1/j, set Rℓ,k(r)←pj
// Post-processing on the stored candidate samples and probe samples
12 for r=1,…,κm do
13 for a=1,…,bm do
14 for ℓ=1,…,p do
15 ⨆ Set Dℓ,a(r)←bmn∑k∈[bm]Kσ(Sa(r),Rℓ,k(r))
16 ⨆ Set Za(r)←∏ℓ∈[p]Dℓ,a(r)
17 ⨆ Set M(r)←bmn∑a∈[bm]Za(r)
18 return Mp←median{M(1),…,M(κm)}.
During the stream, the algorithm maintains bm independent candidate samplers and, for each ℓ∈[p], bm independent probe samplers. At the end of the stream, the stored points in all samplers are independent uniform samples from the stream, with replacement. Let S denote the multiset of candidate samples, and let Rℓ denote the multiset of samples in the ℓ-th probe set. For each sampled candidate x and each ℓ∈[p], we form the density estimate
Dℓ(x)=bmny∈Rℓ∑Kσ(x,y).
Each Dℓ(x) is an unbiased estimator for D(x). Moreover, the samples R1,…,Rp are independent, and therefore ∏ℓ∈[p]Dℓ(x) is an unbiased estimator for D(x)p. The final estimator is
Mp=bmnx∈S∑ℓ∈[p]∏Dℓ(x).
Note that during the stream, we only maintain reservoir samples. All kernel evaluations are performed after the stream and only between stored candidate and probe points.
The main technical issue is that the same probe samples are reused for all candidate points, which creates correlations among the summands. The fixed-dimensional Gaussian geometry is used to control these correlations: roughly, a point of high Gaussian density cannot be isolated, and the low-density regions cannot contribute too much Gaussian mass to any query point. This gives a density-level correlation bound and a variance bound for the shared-probe estimator.
For the analysis, it suffices to analyze one repetition. Dropping the repetition superscript r, let I1,…,Ibm be the candidate indices sampled by S1,…,Sbm, and let Rℓ,1,…,Rℓ,bm denote the probe indices in the ℓ-th probe set. These indices are independent and uniform in [n]. For every stored candidate pi and every ℓ∈[p], define
Dℓ(pi):=bmna∈[bm]∑Kσ(pi,pRℓ,a).
The corresponding base estimator is
Mp:=bmna∈[bm]∑ℓ∈[p]∏Dℓ(pIa).(30)
Lemma 4.6. The estimator in (30) satisfies E[Mp]=Mp(P).
Proof. For every fixed i and every ℓ, E[Dℓ(pi)]=bmn⋅bm⋅nDi=Di. The p probe samples are independent, so E[∏ℓ∈[p]Dℓ(pi)]=Dip. Since each candidate sample is uniform in [n], E[Mp]=n⋅n1∑i∈[n]Dip=Mp(P).
We analyze the variance of Mp.
Lemma 4.7. Var[Mp]≤ϵ2(Mp(P))2.
Proof. Let Zi:=∏ℓ∈[p]Dℓ(pi) and Z:=∑i∈[n]Zi. We decompose the variance according to the probe samples R and the candidate samples I:
Var[Mp]=VarR[EI[Mp∣R]]+ER[VarI(Mp∣R)].(31)
Conditioned on R.
EI[Mp∣R]=bmn⋅bm⋅n1i∈[n]∑Zi=Z.
Thus the first term in (31) is VarR[Z].
We first bound VarR[Z]. For one probe sample, a direct calculation gives
Here, CZ′=CZ′(p) is a sufficiently large constant. The last equality holds because ∑i,j∈[n](DiDj)p=(∑i∈[n]Dip)2=(Mp(P))2.
By Lemma 4.5,
VarR[Z]≤CZlogn⋅(Mp(P))2⋅q=1∑p(bmτn)q,(34)
for a sufficiently large constant CZ=CZ(p,d). Since n=τp+1 and bm=Cbϵ−2τplogn, we have bmτn=Cblognϵ2. Choosing the constant Cb in bm sufficiently large, (34) becomes
where CM=CM(p,d) is a sufficiently large constant. Again, for a sufficiently large constant Cb, this is at most
ER[VarI(Mp∣R)]≤2ϵ2(Mp(P))2.(36)
Combining (35) and (36) proves the lemma.
Proof of Theorem 4.1. For one copy of the estimator, Lemmas 4.6 and 4.7, together with Chebyshev's inequality, imply that
Pr[Mp−Mp(P)>3ϵMp(P)]≤91.
Run O(log(1/δ)) independent copies and return the median. This boosts the success probability to at least 1−δ. Rescaling the accuracy parameter by a constant factor gives the stated (1±ϵ) guarantee.
Each copy of the estimator stores bm candidate samples and pbm probe samples, where bm=Op,d(ϵ−2np/(p+1)logn). Since p is fixed, the space bound follows after multiplying by O(log(1/δ)) independent repetitions.
4.3 Removing the Assumption of Known Stream Length
The algorithm presented above assumes that n is known in advance, since the sample budget bm is chosen as a function of n. We now remove this assumption without changing the estimator or its asymptotic space complexity. The only modification is to the implementation of the candidate and probe samplers.
We run the median amplification above with failure probability δ/2, and hence set κm=Cκlogδ2. The remaining failure probability δ/2 is allocated to the sampling construction below.
Set α:=p+1p. Partition the stream positions into dyadic time blocks
Jj:={2j,2j+1,…,2j+1−1},j=0,1,2,….
The final block may be only partially filled. When the first point in block Jj arrives, initialize sj:=Csϵ−2κm2αj(j+1) independent reservoir samplers, where Cs=Cs(p,d) is a sufficiently large constant. These samplers receive only the points belonging to Jj. Consequently, after the stream ends, their outputs are independent uniform samples, with replacement, from the points in Jj.
Maintain the current stream length using a counter. After the stream ends, set τ:=n1/(p+1) and bm:=Cbϵ−2τplogn. The higher-moment estimator requires Q:=(p+1)κmbm independent uniform samples from the final stream: bm candidate samples and p⋅bm probe samples for each of the κm repetitions.
For every j, let νj:=∣Jj∩[n]∣ be the length of the j-th block. Independently for each t∈[Q], draw a block label Jt according to Pr[Jt=j]=νj/n. Let ξj:=∣{t∈[Q]:Jt=j}∣ be the number of requested samples from block Jj. If ξj>sj for some j, declare a sampling overflow and return an arbitrary value. Otherwise, assign the first ξj reservoir outputs from block Jj to the sample slots whose label is j. Finally, use any fixed bijection between these Q slots and the candidate and probe samples
Conceptually, we try to merge the reservoir samples maintained separately for different blocks into Q samples from the entire stream.
We first show that, in the absence of an overflow, this procedure produces exactly the samples required by the analysis above. Couple every block Jj with an infinite sequence of independent uniform samples from that block, and regard the stored samples as the first sj elements of this sequence. For any sample slot t and any stream position i∈Jj∩[n], the probability that slot t selects position i is
Pr[Jt=j]⋅νj1=nνj⋅νj1=n1.
Because the block labels and all block sample sequences are independent, the resulting stream positions are independent and uniform in [n]. Therefore, the conceptual construction produces candidate and probe samples with the same joint distribution as those used in the estimator and variance analysis above. On the event that no block overflows, the actual implementation agrees exactly with this conceptual construction.
It remains to bound the probability of overflow. Let jmax:=⌊log2n⌋. For each j≤jmax, the random variable ξj is binomial with mean
where C0,C1 depend only on p and d. To justify the last inequality, write r=jmax−j. Then jmax+1=j+r+1≤(j+1)(r+1), while supr≥0(r+1)2−r/(p+1)=Op(1) for fixed p.
Choose Cs sufficiently large that sj≥4λj for every j. A Chernoff bound then gives
Pr[ξj>sj]≤exp(−csj)≤2j+2δ,
where the last inequality follows by increasing Cs and Cκ if necessary. A union bound over all dyadic blocks gives that the probability that some sample pool overflows is at most δ/2.
Finally, at any time during block Jjmax, the number of stored reservoir samples is
Let E denote the event that no sample pool overflows. Conditioned on E, the actual implementation agrees exactly with the conceptual estimator, and thus the failure probability in this case is at most δ/2. Since Pr[Ec]≤δ/2, the overall failure probability is at most δ.
4.4 Lower Bound
In this section, we give a lower bound for one-dimensional Gaussian density moments by performing a reduction from the classical frequency-moment problem. Recall that, for a frequency vector f=(f1,…,fN), its k-th frequency moment is Fk(f):=∑a∈[N]fak. For every fixed integer k>2, the classical lower bound for frequency moments states that, for any ϵ∈[CkN−1/k,1/10] (for a sufficiently large constant Ck), any one-pass randomized algorithm that returns a (1+ϵ)-approximation to Fk with constant success probability requires Ωk(logNϵ−2N1−2/k) bits of space [Gan12].
Theorem 4.8. Fix an integer p>1. For Cpn−1/(p+1)≤ϵ≤1/20, where Cp is a sufficiently large constant, any one-pass streaming algorithm that, on every stream of at most n points on the real line, returns a (1+ϵ)-approximation to Mp(P) with probability at least 2/3 requires Ωp(lognϵ−2n1−2/(p+1)) bits of space.
Proof. Set k:=p+1. To distinguish it from the frequency stream used in the reduction, we refer to the stream for Mp as the Gaussian point stream. Throughout this subsection, we fix the Gaussian kernel bandwidth to σ=1.
We reduce the insertion-only Fk problem to estimating Mp. We use N for the universe size of the frequency stream, reserving n for the upper bound on the length of the Gaussian point stream. The hard instances underlying the classical Fk lower bound can be chosen to have O(N) updates. More specifically, in the standard reduction the frequency vector has entries in {0,1} except for at most one coordinate of frequency O(ϵN1/k), together with one additional spike of size N1/k; hence the resulting insertion-only stream has length at most 2N for sufficiently large N. We therefore set N:=⌊2n⌋, so that every frequency stream maps to a Gaussian point stream of length at most n.
Let f=(f1,…,fN) be the final frequency vector and let ℓ:=∑a∈[N]fa≤n be its stream length. Choose η:=100pϵ and L:=2lnηn. For each occurrence of item a∈[N], insert the point za:=aL∈R. Thus, the fa occurrences of item a become fa coincident Gaussian points at location za. Distinct item locations are separated by at least L, and therefore
K1(za,zb)=exp(−2∣a−b∣2L2)≤exp(−2L2)≤nη
for all a=b.
Every point placed at za has the same Gaussian density, which we denote by D(a). It satisfies
D(a)=fa+b=a∑fbK1(za,zb)=fa+ra,
where 0≤ra≤ℓ⋅nη≤η. For every active item a, we have fa≥1, and hence
fa≤D(a)≤fa+η≤(1+η)fa.
Since there are fa stream points at za, it follows that Mp(P)=∑a∈[N]faD(a)p. Therefore,
Fp+1(f)=a∈[N]∑fap+1≤Mp(P)≤(1+η)pFp+1(f).
For the chosen value of η and ϵ≤1/20, we have (1+η)p≤eϵ/100≤1+99ϵ. Hence, if M is a (1+ϵ)-approximation to Mp(P), then
so M is a (1+2ϵ)-approximation to Fp+1(f). The success probability can be increased from 2/3 to the constant required by the classical frequency-moment lower bound using a constant number of parallel repetitions. Since 2ϵ≤1/10, and 2ϵ≥Cp+1N−1/(p+1) when Cp+1 is sufficiently large, the lower bound for Fp+1 applies with accuracy parameter 2ϵ and gives
This paper develops one-pass streaming algorithms for the diversity index and density moments under Gaussian kernel similarity. Several questions remain open. For higher density moments, a small polynomial gap remains between the upper and lower bounds. For the diversity index, our lower bound shows that a dimension-dependent polylogarithmic amount of bit space is necessary; closing the gap between the exponents in the upper and lower bounds remains open. More broadly, it would be interesting to characterize the kernels or geometric similarity functions that admit sublinear-space streaming algorithms.
Use of AI assistance
The research questions, algorithms, proof strategies, and substantive mathematical arguments in this paper were developed by the author. ChatGPT (GPT-5.5 and GPT-5.6) was used for language editing, proofreading, and to assist with routine algebraic manipulations in the Gaussian-kernel and variance analyses. The resulting text and calculations were verified by the author, who takes full responsibility for the paper's contents.
References
[AMS99] Noga Alon, Yossi Matias, and Mario Szegedy. The space complexity of approximating the frequency moments. J. Comput. Syst. Sci., 58(1):137–147, 1999.
[BJK +02] Ziv Bar-Yossef, T. S. Jayram, Ravi Kumar, D. Sivakumar, and Luca Trevisan. Counting distinct elements in a data stream. In RANDOM, pages 1–10, 2002.
[BZ25] Mark Braverman and Or Zamir. Optimality of frequency moment estimation. In STOC, pages 360–370. ACM, 2025.
[Car79] Yair Caro. New results on the independence number. Technical report, Tel-Aviv University, 1979.
[CDK18] Graham Cormode, Jacques Dark, and Christian Konrad. Approximating the Caro–Wei bound for independent sets in graph streams. In Combinatorial Optimization, volume 10856, pages 101–114. Springer, 2018.
[CKNS20] Moses Charikar, Michael Kapralov, Navid Nouri, and Paris Siminelakis. Kernel density estimation through density constrained near neighbor search. In FOCS, pages 172–183, 2020.
[CS20] Benjamin Coleman and Anshumali Shrivastava. Sub-linear RACE sketches for approximate kernel density estimation on streaming data. In WWW, pages 1739–1749, 2020.
[CZ16] Di Chen and Qin Zhang. Streaming algorithms for robust distinct elements. In SIGMOD, pages 1433–1447. ACM, 2016.
[CZ18] Jiecao Chen and Qin Zhang. Distinct sampling on streaming data with near-duplicates. In PODS, pages 369–382. ACM, 2018.
[FM85] Philippe Flajolet and G. Nigel Martin. Probabilistic counting algorithms for data base applications. J. Comput. Syst. Sci., 31(2):182–209, 1985.
[Gan12] Sumit Ganguly. A lower bound for estimating high moments of a data stream. CoRR, abs/1201.0253, 2012.
[KN97] Eyal Kushilevitz and Noam Nisan. Communication complexity. Cambridge University Press, 1997.
[KNW10] Daniel M. Kane, Jelani Nelson, and David P. Woodruff. An optimal algorithm for the distinct elements problem. In PODS, pages 41–52. ACM, 2010.
[LC12] Tom Leinster and Christina A. Cobbold. Measuring diversity: The importance of species similarity. Ecology, 93(3):477–489, 2012.
[LZ26a] Kaiwen Liu and Qin Zhang. Frequency moments in noisy streaming and distributed data under mismatch ambiguity. Proc. ACM Manag. Data, 4(2):105:1–105:24, 2026.
[LZ26b] Kaiwen Liu and Qin Zhang. Statistics of similarity graphs in node-arrival streams, 2026. arXiv:2609.04505.
[Mut05] S. Muthukrishnan. Data streams: Algorithms and applications. Foundations and Trends in Theoretical Computer Science, 1(2):117–236, 2005.
[PT20] Jeff M. Phillips and Wai Ming Tai. Near-optimal coresets of kernel density estimates. Discrete & Computational Geometry, 63(4):867–887, 2020.
[RR07] Ali Rahimi and Benjamin Recht. Random features for large-scale kernel machines. In NeurIPS, pages 1177–1184. Curran Associates, Inc., 2007.
[Tai22] Wai Ming Tai. Optimal coreset for Gaussian kernel density estimation. In SoCG, volume 224, pages 63:1–63:15, 2022.
[Wei81] V. K. Wei. A lower bound on the stability number of a simple graph. Technical Report TM 81-11217-9, Bell Laboratories, Berkeley Heights, NJ, 1981.
[Zha25] Qin Zhang. Robust statistical analysis on streaming data with near-duplicates in general metric spaces. Proc. ACM Manag. Data, 3(2):111:1–111:25, 2025.
[Zha26] Qin Zhang. Frequency moments beyond equality: Streaming cosine density moments, 2026. arXiv:2609.06925.
6 Omitted Proofs
6.1 Proof of Lemma 2.10
Proof. Let X be uniform over the vectors in {0,1}m of Hamming weight m/2, and let I be uniform in [m] and independent of X. Let R denote the public randomness and let M=M(X,R) be Alice's message. If Bob recovers XI with error probability at most 1/3, then the binary form of Fano's inequality gives
H(XI∣M,R,I)≤h2(1/3),
where h2 is the binary entropy function. Since I is uniform and independent of (X,M,R), we have
j∈[m]∑H(Xj∣M,R)=mH(XI∣M,R,I).
By subadditivity of conditional entropy,
H(X∣M,R)≤j∈[m]∑H(Xj∣M,R)≤mh2(1/3).
On the other hand,
H(X)=log(m/2m)=m−O(logm).
It follows that
I(X;M∣R)=H(X)−H(X∣M,R)=Ω(m).
The message length is at least I(X;M∣R), proving the lemma.
and that ψ(u)t=hd/2qu(ht), and ϕ(u)t=ψ(u)t1[∥ht−u∥∞≤L].
Under our choices of parameters, h=ChΛησ, L=CLσΛη, and Λη=CΛlogηdn. Since 0<η≤1/2 and n,d≥1, by choosing the constants sufficiently large we may assume that h≤σ and L≥σ.
Define the normalized one-dimensional Gaussian
gσ(s):=(πσ22)1/2exp(−σ22s2).
Then
qu(z)2=r=1∏dgσ(zr−ur),and∫Rgσ(s)ds=1.
For a∈R, define
M(a):=hm∈Z∑gσ(hm−a)
and
TL(a):=hm∈Z∣hm−a∣>L∑gσ(hm−a).
We first establish bounds on these one-dimensional shifted-lattice sums. The function gσ is even and nonincreasing on [0,∞). On either half-line, the points of the shifted lattice hZ−a are spaced by h. Comparing all but the point closest to the origin with the integral over the preceding interval of length h gives
M(a)≤2hgσ(0)+2∫0∞gσ(s)ds=1+2hgσ(0).
Since h≤σ, M(a)≤1+2π2<3. The same comparison, now applied beyond distance L, gives
Substituting L=CLσΛη and Λη=CΛlog2(dn/η) gives
∥ψ(u)−ϕ(u)∥2≤Ad(ηdn)−γ,
where Ad:=2d3d−1 and γ:=ln2CL2CΛ. Since d is fixed and dn/η≥2d, we may choose CL and CΛ sufficiently large that γ>1 and Ad(2d)−(γ−1)≤12d. It follows uniformly for all u∈Rd that