Frequency statistics of streams #
The frequency of an item a in a stream s : List α is s.count a. The k-th frequency
moment is F_k = ∑ₐ (count a s) ^ k (Cslib.Streaming.freqMoment), and the largest
frequency is F∞ = maxₐ count a s (Cslib.Streaming.maxFreq), the statistics studied by Alon,
Matias and Szegedy [AMS99]. F₀ is the number of distinct items, F₁ the length
of the stream, and the items of a stream are distinct exactly when F∞ ≤ 1
(Cslib.Streaming.maxFreq_le_one_iff).
The join size of two streams u and v is the inner product of their frequency vectors,
Cslib.Streaming.joinSize u v = ∑ₐ count a u · count a v. Read as lists of the join attribute
values of two relations, it is the number of tuples in their equijoin: for key functions k and
l, the pairs (a, b) of u ×ˢ v with k a = l b number joinSize (u.map k) (v.map l)
(Cslib.Streaming.length_filter_product_eq_joinSize). When a key may be absent (k a = none), as
SQL NULL keys are, a pair matches only on a common present key, and the pairs number
joinSize (u.filterMap k) (v.filterMap l)
(Cslib.Streaming.length_filter_product_eq_joinSize_filterMap). The self-join is F₂, and
joinSize u v ^ 2 ≤ F₂ u F₂ v. The join-size sketch of Alon, Gibbons, Matias and Szegedy is in
CslibFrontier.Computability.Streaming.JoinSize.
Main definitions #
Cslib.Streaming.freqMoment: the frequency momentsF_kof a stream.Cslib.Streaming.maxFreq: the largest frequencyF∞of a stream.Cslib.Streaming.joinSize: the join size∑ₐ count a u · count a vof two streams.
Main results #
Cslib.Streaming.freqMoment_zero:F₀is the number of distinct items.Cslib.Streaming.freqMoment_map: renaming the items injectively keeps the frequency moments.Cslib.Streaming.freqMoment_eq_sum_of_subset,Cslib.Streaming.freqMoment_cons_add,Cslib.Streaming.freqMoment_pos: fork ≠ 0,F_ksums over any set containing the items, and prepending an itemareplaces the term(count a s) ^ kby(count a s + 1) ^ k.Cslib.Streaming.one_le_maxFreq,Cslib.Streaming.two_le_maxFreq_of_not_nodup,Cslib.Streaming.maxFreq_le_one_iff:F∞is at least1on nonempty streams, and at most1exactly on streams of distinct items.Cslib.Streaming.joinSize_eq_sum_of_subset: the join size sums over any set of items containing those of the first stream.Cslib.Streaming.joinSize_eq_sum_map_count,Cslib.Streaming.length_filter_product_eq_joinSize,Cslib.Streaming.length_filter_product_eq_joinSize_filterMap: the join size sums, over the items of the first stream, their counts in the second, so it counts the pairs of an equijoin, with total keys or with keys that may be absent.Cslib.Streaming.joinSize_self,Cslib.Streaming.joinSize_comm,Cslib.Streaming.joinSize_sq_le: the self-join isF₂, and|F ⋈ G|² ≤ F₂(F) F₂(G).
References #
The k-th frequency moment F_k = ∑ₐ (count a s) ^ k of a stream.
Instances For
F₀ is the number of distinct items of the stream.
Renaming the items of a stream injectively keeps its frequency moments.
For k ≠ 0, F_k is the sum of (count a s) ^ k over any set of items containing those of
s.
Prepending an item a to the stream replaces the term (count a s) ^ k of F_k by
(count a s + 1) ^ k, for k ≠ 0.
The frequency moments of a nonempty stream are positive.
The largest number of occurrences of an item in the stream s (F∞; zero for the empty
stream).
Instances For
The items of a stream are distinct exactly when no item occurs twice.
Join sizes #
The join size |F ⋈ G| = ∑ₐ count a u · count a v of the relations whose join attribute
values are listed by the streams u and v: the inner product of their frequency vectors.
Instances For
The join size is the sum of count a u · count a v over any set of values containing those
of u.
The join size is symmetric: |F ⋈ G| = |G ⋈ F|.
The self-join size of a relation is its second frequency moment.
Join sizes are bounded by self-join sizes: |F ⋈ G|² ≤ F₂(F) F₂(G), by the
Cauchy–Schwarz inequality.
The join size of u and v sums, over the items a of u with multiplicity, the number of
occurrences of a in v.
Equijoin cardinality with absent keys. If the tuples a of u and b of v have
optional join keys k a and l b, the pairs (a, b) of u ×ˢ v with a common present key
number joinSize (u.filterMap k) (v.filterMap l): a tuple without a key (none, such as an SQL
NULL key) matches nothing, not even another tuple without a key.
Equijoin cardinality. If the tuples a of u and b of v have join keys k a and
l b, the pairs (a, b) of u ×ˢ v with k a = l b number joinSize (u.map k) (v.map l).