Adversarial Robustness of Streaming Algorithms through Importance Sampling

In this paper, we introduce adversarially robust streaming algorithms for central machine learning and algorithmic tasks, such as regression and clustering, as well as their more general counterparts, subspace embedding, low-rank approximation, and coreset construction. For regression and other numerical linear algebra related tasks, we consider the row arrival streaming model. Our results are based on a simple, but powerful, observation that many importance sampling-based algorithms give rise to adversarial robustness which is in contrast to sketching based algorithms, which are very prevalent in the streaming literature but suffer from adversarial attacks. In addition, we show that the well-known merge and reduce paradigm in streaming is adversarially robust. Since the merge and reduce paradigm allows coreset constructions in the streaming setting, we thus obtain robust algorithms for $k$-means, $k$-median, $k$-center, Bregman clustering, projective clustering, principal component analysis (PCA) and non-negative matrix factorization. To the best of our knowledge, these are the first adversarially robust results for these problems yet require no new algorithmic implementations. Finally, we empirically confirm the robustness of our algorithms on various adversarial attacks and demonstrate that by contrast, some common existing algorithms are not robust. (Abstract shortened to meet arXiv limits)


Introduction
Robustness against adversarial attacks have recently been at the forefront of algorithmic design for machine learning tasks [GSS15, CW17, AEIK18, MMS + 18, TSE + 19]. We extend this line of work by studying adversarially robust streaming algorithms.
In the streaming model, data points are generated one at a time in a stream and the goal is to compute some meaningful function of the input points while using a limited amount of memory, typically sublinear in the total size of the input. The streaming model is applicable in many algorithmic and ML related tasks where the size of the data far exceeds the available storage. Applications of the streaming model include monitoring IP traffic flow, analyzing web search queries [LMV + 16], processing large scientific data, feature selection in machine learning [HZZ21, GRB + 19, WYWD10], and estimating word statistics in natural language processing [GDC12] to name a few. Streaming algorithms have also been implemented in popular data processing libraries such as Apache Spark which have implementations for streaming tasks such as clustering and linear regression [ZXW + 16a].
In the adversarial streaming model [MBN + 17, BMSC17, AMYZ19, BY20, BJWY20, HKM + 20, WZ20, ABD + 21, KMNS21], an adversary gives an algorithm a sequence of adaptively chosen updates u 1 , . . . , u n as a data stream. The goal of the algorithm is to compute or approximate some predetermined function for every prefix of the adversarial stream, but the adversary may generate future updates based on previous outputs of the algorithm. In particular, the adversary may gradually learn the random bits internally used by an algorithm to manipulate dependencies in the input. This is especially problematic as many important problems in the streaming model require randomized algorithms, as they are known to not admit any deterministic algorithms that use sublinear space. Studying when adversarially robust streaming algorithms are possible is an important problem in lieu of recent interest in adversarial attacks in ML with applications to adaptive data analysis.
Formally, we define the model as a two-player game between a streaming algorithm StreamAlg and a source Adversary of adaptive and adversarial input to StreamAlg. At the beginning of the game, a fixed query Q is determined and asks for a fixed function for the underlying dataset implicitly defined by the stream. The game then proceeds in rounds, and in the t-th round, (1) Adversary computes an update u t ∈ [n] for the stream, which depends on all previous stream updates and all previous outputs from StreamAlg.
(2) StreamAlg uses u t to update its data structures D t , acquires a fresh batch R t of random bits, and outputs a response A t to the query Q.
(3) Adversary observes and records the response A t .
The goal of Adversary is to induce StreamAlg to make an incorrect response A t to the query Q at some time t ∈ [m] throughout the stream.
Related Works. Adversarial robustness of streaming algorithms has been an important topic of recent research. On the positive note, [BJWY20] gave a robust framework for estimating the L p norm of points in a stream in the insertion-only model, where previous stream updates cannot later be deleted. Their work thus shows that deletions are integral to the attack of [HW13]. Subsequently, [HKM + 20] introduced a new algorithmic design for robust L p norm estimation algorithms, by using differential privacy to protect the internal randomness of algorithms against the adversary. Although [WZ20] tightened these bounds, showing that essentially no losses related to the size of the input n or the accuracy parameter ε were needed, [KMNS21] showed that this may not be true in general. Specifically, they showed a separation between oblivious and adversarial streaming in the adaptive data analysis problem.
[BY20] showed that sampling is not necessarily adversarially robust; they introduce an exponentially sized set system where a constant number of samples, corresponding to the VC-dimension of the set system, may result in a very unrepresentative set of samples. However, they show that with an additional logarithmic overhead in the number of samples, then Bernoulli and or reservoir sampling are adversarially robust. This notion is further formalized by [ABD + 21], who showed that the classes that are online learnable requires essentially sample-complexity proportional to the Littlestone's dimension of the underlying set system, rather than VC dimension. However, these sampling procedures are uniform in the sense that each item in the stream is sampled with the same probability. Thus the sampling probability of each item is oblivious to the identity of the item. By contrast, we show the robustness for a variety of algorithms based on non-oblivious sampling, where each stream item is sampled with probability roughly proportional to the "importance" of the item.

Our Contributions
Our main contribution is a powerful yet simple statement that algorithms based on non-oblivious sampling are adversarially robust if informally speaking, the process of sampling each item in the stream can be viewed as using fresh randomness independent of previous steps, even if the sampling probabilities depend on previous steps.
Let us describe, very informally, our meta-approach. Suppose we have an adversarial stream of elements given by u 1 , . . . , u n . Our algorithm A will maintain a data structure A t at time t which updates as the stream progresses. A will use a function g(A t , u t ) to determine the probability of sampling item u t to update A t to A t+1 . The function g measures the 'importance' of the element u t to the overall problem that we wish to solve. For example, if our application is k-means clustering and u t is a point far away from all previously seen points so far, we want to sample it with a higher probability. We highlight that even though the sampling probability for u t given by g(A t , u t ) is adversarial, since the adversary designs u t and previous streaming elements, the coin toss performed by our algorithm A to keep item u t is independent of any events that have occurred so far, including the adversary's actions. This new randomness introduced by the independent coin toss is a key conceptual step in the analysis for all of the applications listed in Figure 1.
Contrast this to the situation where a "fixed" data structure or sketch is specified upfront. In this case, we would not be adaptive to which inputs u t the adversary designs to be "important" for our problem which would lead us to potentially disregard such important items rendering the algorithm ineffective.
As applications of our meta-approach, we introduce adversarially robust streaming algorithms for two central machine learning tasks, regression and clustering, as well as their more general counterparts, subspace embedding, low-rank approximation, and coreset construction.
We show that several methods from the streaming algorithms "toolbox", namely merge and reduce, online leverage score sampling, and edge sampling are adversarially robust "for free." As a result, existing (and future) streaming algorithms that use these tools are robust as well. We discuss our results in more detail below and provide a summary of our results and applications in Figure 1.
Theorem 1.1 (Merge and reduce is adversarially robust) Given an offline ε-coreset construction, the merge and reduce framework gives an adversarially robust streaming construction for an ε-coreset with high probability.
For regression and other numerical linear algebra related tasks, we consider the row arrival streaming model, in which the adversary generates a sequence of row vectors a 1 , . . . , a n in d-dimensional vector space. For t ∈ [n], the t-th prefix of the stream induces a matrix A t ∈ R t×d with rows a 1 , . . . , a t . We denote this matrix as A t = a 1 • . . . • a t and define κ to be an upper bound on the largest condition number 1 of the matrices A 1 , . . . , A n . Theorem 1.2 (Row sampling is adversarially robust) There exists a row sampling based framework for adversarially robust streaming algorithms that at each time t ∈ [n]: ε 2 log n log κ rows (spectral approximation/subspace embedding/linear regression/generalized regression).
(2) Outputs a matrix M t such that for all rank k orthogonal projection matrices P ∈ R d×d , while sampling O dkκ ε 2 log n log 2 κ rows (projection-cost preservation/low-rank approximation). ( Finally, we show that our analysis also applies to algorithms for graph sparsification for in which edges are sampled according to their "importance". Define κ as the ratio of the largest and the smallest cut sizes in G (see Section 4 and Supplementary Section C for exact details). Theorem 1.3 Given a weighted graph G = (V, E) with |V | = n whose edges e 1 , . . . , e m arrive sequentially in a stream, there exists an adversarially robust streaming algorithm that outputs a 1 ± ε cut sparsifier with O κ 2 n log n ε 2 edges with probability 1 − 1/ poly(n).
Sketching vs Sampling Algorithms. A central tool for randomized streaming algorithms is the use of linear sketches. These methods maintain a data structure f such that after the (i + 1)-th input x i , we can update f by computing a linear function of x i . Typically, these methods employ a random matrix. For example, if the input consists of vectors, sketching methods will use a random matrix to project the vector into a much smaller dimension space. In [HW13], it was proved no linear sketch can approximate the L 2 -norm within a polynomial multiplicative factor against such an adaptive adversary. In general, streaming algorithms that use sketching are highly susceptible to the type of attack described in [HW13] where the adversary can effectively 'learn' the kernel of the linear function used and send inputs along the kernel. For example, if an adversary knows the kernel of the random matrix used to project the input points, then by sending points that lie on the kernel of the matrix as inputs, the adversary can render the whole streaming algorithm useless.
One the other hand, we employ a different family of streaming algorithms that are based on sampling the input rather than sketching it. Surprisingly, this simple change allows one to automatically get many adversarially robust algorithms either "for free" or without new algorithmic overheads. For more information, see Section 1.1. We emphasize that while our techniques are not theoretically sophisticated, we believe its power lies in its simple message that sampling is often superior to sketching for adversarial robustness. In addition to downstream algorithmic and ML applications, this provides an interesting separation and trade-offs between the two paradigms; for non adversarial inputs sketching often gives similar or better performance guarantees for many tasks [BYKS01]. {C 1,j }: C 1,1 C 1,2 C 1,3 C 1,4 {C 2,j }: {C 3,j }: C 3,1 Fig. 2: Merge and reduce framework. Each C 1,j is an O(ε/ log n)-coreset of the corresponding partition of the substream and each C i,j is an ε-coreset of C i−1,2j−1 and C i−1,2j for i > 1.

Merge and Reduce
We show that the general merge and reduce paradigm is adversarially robust. Merge and reduce is widely used for the construction of a coreset, which provides dimensionality reduction on the size of an underlying dataset, so that algorithms for downstream applications can run more efficiently: Definition 2.1 (ε coreset) Let P ⊂ X be a set of elements from a universe X, z ≥ 0, ε ∈ (0, 1), and (P, dist, Q) be a query space. Then a subset C equipped with a weight function w : P → R is called an ε-coreset with respect to the query space (P, dist, Q) if The study of efficient offline coreset constructions for a variety of geometric and algebraic problems forms a long line of active research. For example, offline coreset constructions are known for linear regression, low-rank approximation, L 1 -subspace embedding, k-means clustering, k-median clustering, k-center, support vector machine, Gaussian mixture models, M -estimators, Bregman clustering, projective clustering, principal component analysis, k-line center, j-subspace approximation, and so on. Thus, our result essentially shows that using the merge and reduce paradigm, these offline coreset constructions can be extended to obtain robust and accurate streaming algorithms. The merge and reduce paradigm works as follows. Suppose we have a stream p 1 , . . . , p n of length n = 2 k for some integer k, without loss of generality (otherwise we can use a standard padding argument to increase the length of the stream). Define C 0,j = p j for all j ∈ [n]. Consider k levels, where each level i ∈ [k] consists of n 2 i coresets C i,1 , . . . , C i,n/2 i and each coreset C i,j is an ε 2k -coreset of C i−1,2j−1 and C i−1,2j . Note that this approach can be implemented efficiently in the streaming model, since each C i,j can be built immediately once C i−1,2j−1 and C i−1,2j are constructed, and after C i,j is constructed, then both C i−1,2j−1 and C i−1,2j can be discarded. For an illustration of the merge and reduce framework, see Figure 2, though we defer all formal proofs to the supplementary material. Using the coresets of [BDM + 20], Theorem 1.1 gives the following applications: Theorem 2.2 There exists a merge-and-reduce row sampling based framework for adversarially robust streaming algorithms that at each time t ∈ [n]: ε 2 log 4 n log κ rows (spectral approximation/subspace embedding/linear regression/generalized regression).
(2) Outputs a matrix M t such that for all rank k orthogonal projection matrices P ∈ R d×d , while sampling O k ε 2 log 4 n log 2 κ rows (projection-cost preservation/low-rank approximation). ( Using coresets of [HV20], then Theorem 1.1 also gives applications for (k, z)-clustering such as k-median for z = 1 and k-means for z = 2. Moreover, [LK17] noted that constructions of [FL11] give coresets for Bregman clustering, which handles µ-similar Bregman divergences such as the Itakura-Saito distance, KL-divergence, Mahalanobis distance, etc.
Theorem 2.3 There exists a merge-and-reduce importance sampling based framework for adversarially robust streaming algorithms that at each time t: (1) Outputs a set of centers that gives a (1 + ε)-approximation to the optimal (k, z)-clustering, k-means clustering (z = 2), and k-median clustering (z = 1), while storing O 1 ε 2z+2 k log 2z+2 n log k log k log n ε points.
(2) Outputs a set of centers that gives a (1 + ε)-approximation to the optimal k-Bregman clustering, while storing O 1 ε 2 dk 3 log 3 n points. Using the sensitivity bounds of [VX12a, VX12b] and the coreset constructions of [BFL16], then Theorem 1.1 also gives applications for the following shape fitting problems: Theorem 2.4 There exists a merge-and-reduce importance sampling based framework for adversarially robust streaming algorithms that at each time t: (1) Outputs a set of lines that gives a (1 + ε)-approximation to the optimal k-lines clustering, while storing (2) Outputs a subspace that gives a (1 + ε)-approximation to the optimal dimension j subspace approximation, while storing O d ε 2 g(d, j)k g(d,j) log 4 n points of R d , for a fixed function g(d, j).
(3) Outputs a set of subspaces that gives a (1 + ε)-approximation to the optimal (j, k)-projective clustering, , for a set of input points with integer coordinates.
Adversarially robust approximation algorithms for Bayesian logistic regression, Gaussian mixture models, generative adversarial networks (GANs), and support vector machine can be obtained from Theorem 1.1 and coreset constructions of [HCB16, FKW19, SZG + 20, TBFR20]; a significant number of additional applications of Theorem 1.1 using coreset constructions can be seen from recent surveys on coresets, e.g., see [LK17,Fel20]. The merge-and-reduce framework also has applications to a large number of other problems such as finding heavy-hitters [MG82] or frequent directions [GLPW16] and in various settings, such as the sliding window model [DGIM02], time decay models [BLUZ19] or for at-the-time or back-in-time queries [SZP + 21].

Adversarial Robustness of Subspace Embedding and Applications
We use [n] to represent the set {1, . . . , n} for an integer n > 0. We typically use bold font to denote vectors and matrices. For a matrix A, we use A −1 to denote the Moore-Penrose inverse of A. We first formally define the goals of our algorithms: Problem 3.1 (Spectral Approximation) Given a matrix A ∈ R n×d and an approximation parameter We note that linear regression is a well-known specific application of spectral approximation.
Problem 3.2 (Projection-Cost Preservation) Given a matrix A ∈ R n×d , a rank parameter k > 0, and an approximation parameter ε > 0, the goal is to find a matrix M ∈ R m×d with m n such that for all rank k orthogonal projection matrices P ∈ R d×d , Note if M is a projection-cost preservation of A, then its best low-rank approximation can be used to find a projection matrix that gives an approximation of the best low-rank approximation to A. Problem 3.3 (Low-Rank Approximation) Given a matrix A ∈ R n×d , a rank parameter k > 0, and an approximation parameter ε > 0, find a rank k matrix M ∈ R n×d such that for a matrix A denotes the best rank k approximation to A.
Problem 3.4 (L 1 -Subspace Embedding) Given a matrix A ∈ R n×d and an approximation parameter We consider the general class of row sampling algorithms, e.g., [CMP16, BDM + 20]. Here we maintain a L p subspace embedding of the underlying matrix by approximating the online L p sensitivities of each row as a measure of importance to perform sampling. For more details, see Algorithm 1.
Algorithm 1 Row sampling based algorithms, e.g., [CMP16, BDM + 20] Input: A stream of rows a 1 , . . . , a n ∈ R d , parameter p > 0, and an accuracy parameter ε > 0 Output: Remark 3.6 We note that for p = 1, a constant fraction approximation to any online L p sensitivity τ i such that τ i > 1 poly(n) can be computed in polynomial time using (offline) linear programming while for p = 2, τ i is equivalent to the online leverage score of a i , which has the closed form expression a i (A i A i ) −1 a i , which can be approximated by a i (M M) −1 a i , conditioned on M being a good approximation to A i−1 when a i is in the span of M. Otherwise, τ i takes value 1 when a i is not in the span of M.
Lemma 3.7 (Adversarially Robust L p Subspace Embedding and Linear Regression) Given ε > 0, p ∈ {1, 2}, and a matrix A ∈ R n×d whose rows a 1 , . . . , a n arrive sequentially in a stream with condition number at most κ, there exists an adversarially robust streaming algorithm that outputs a (1 + ε) spectral approximation with high probability. The algorithm samples O d 2 κ 2 ε 2 log n log κ rows for p = 2 and O d 2 λ 2 ε 2 log 2 n log κ rows for p = 1, with high probability, where λ is a ratio between upper and lower bounds on A 1 .
We also show robustness of row sampling for low-rank approximation by using online ridge-leverage scores. Together, Lemma 3.7 and Lemma 3.8 give Theorem 1.2.
Lemma 3.8 (Adversarially Robust Low-Rank Approximation) Given accuracy parameter ε > 0, rank parameter k > 0, and a matrix A ∈ R n×d whose rows a 1 , . . . , a n arrive sequentially in a stream with condition number at most κ, there exists an adversarially robust streaming algorithm that outputs a (1 + ε) low-rank approximation with high probability. The algorithm samples O kdκ 2 ε 2 log n log κ rows with high probability.

Graph Sparsification
In this section, we highlight how the sampling paradigm gives rise to an adversarially robust streaming algorithm for graph sparsification. First, we motivate the problem of graph sparsification. Massive graphs arise in many theoretical and applied settings, such as in the analysis of large social or biological networks.
A key bottleneck in such analysis is the large computational resources, in both memory and time, needed. Therefore, it is desirable to get a representation of graphs that take up far less space while still preserving the underlying "structure" of the graph. Usually the number of vertices is much fewer than the number of edges; for example in typical real world graphs, the number of vertices can be several orders of magnitude smaller than the number of edges (for example, see the graph datasets in [RA15]). Hence, a natural benchmark is to reduce the number of edges to be comparable to the number of vertices.
The most common notion of graph sparsification is that of preserving the value of all cuts in the graph by keeping a small weighted set of edges of the original graph. More specifically, suppose our graph is G = (V, E) and for simplicity assume all the edges have weight 1. A cut of the graph is a partition of V = (C, V \ C) and the value of a cut, Val G (C), is defined as the number of edges that cross between the vertices in C and V \ C. A graph H on the same set of vertices as V is a sparsifier if it preserves the value of every cut in G and has a few number of weighted edges. For a precise formulation, see Problem 4.1.
In addition to being algorithmically tractable, this formulation is natural since it preserves the underlying cluster structure of the graph. For example, if there are two well connected components separated by a sparse cut, i.e. two distinct communities, then the sparsifier according to the definition above will ensure that the two communities are still well separated. Conversely, by considering any cut within a well connected component, it will also ensure that any community remains well connected (for more details, see [SPR11] and references therein). Lastly, graph sparsification has been considered in other frameworks such as differential privacy [EKKL20], distributed optimization [WWLZ18], and even learning graph sparsification using deep learning methods [ZZC + 20]. The formal problem definition of graph sparsification is as follows.
Problem 4.1 (Graph Sparsification) Given a graph weighted G = (V, E) with |V | = n, |E| = m, and an approximation parameter ε > 0, compute a weighted subgraph H of G on the same set of vertices such that (1) every cut in H has value between 1 − ε and 1 + ε times its value in G: (1 + ε)Val G (C) for all cuts C where Val G (C), Val H (C) denotes the cost of the cut in the graphs G and H respectively and for the latter quantity, the edges are weighted, (2) the number of edges in H is O n log n ε 2 .
Ignoring dependence on ε, there are previous results that already get sparsifiers H with O(n log n) edges [BK96, SS08]. Their setting is when the entire graph is present up-front in memory. In contrast, we are interested in the streaming setting where future edges can depend on past edges as well as revealed randomness of an algorithm while processing the edges.
Our main goal is to show that the streaming algorithm from [AG09] (presented in Algorithm 2 in the supplementary section), which uses a sampling procedure to sample edges in a stream, is adversarially robust, albeit with a slightly worse guarantee for the number of edges. Following the proof techniques of the non streaming algorithm given in [BK96], it is shown in [AG09] that Algorithm 2 outputs a subgraph H such that H satisfies the conditions of Problem 4.1 with probability 1 − 1/ poly(n) where the probability can be boosted by taking a larger constant C. We must show that this still holds true if the edges of the stream are adversarially chosen, i.e., when new edges in the stream depend on the previous edges and the randomness used by the algorithm so far. We thus again use a martingale argument; the full details are given in Supplementary Section C. As in Section 3, we let κ 1 and κ 2 to be deterministic lower/upper bounds on the size of any cut in G and define κ = κ 2 /κ 1 . Theorem 1.3 Given a weighted graph G = (V, E) with |V | = n whose edges e 1 , . . . , e m arrive sequentially in a stream, there exists an adversarially robust streaming algorithm that outputs a 1 ± ε cut sparsifier with O κ 2 n log n ε 2 edges with probability 1 − 1/ poly(n).

Experiments
To illustrate the robustness of importance-sampling-based streaming algorithms we devise adversarial settings for clustering and linear regression. With respect to our adversarial setting, we show that the performance of a merge-and-reduce based streaming k-means algorithm is robust while a popular streaming k-means implementation (not based on importance sampling) is not. Similarly, we show the robustness superiority of a streaming linear regression algorithm based on row sampling over a popular streaming linear regression implementation and over sketching.
Streaming k-means In this adversarial clustering setting we consider a series of point batches where all points except those in the last batch are randomly sampled from a two dimensional standard normal distribution and points in the last batch similarly sampled but around a distant center (see the data points realization in both panels of Figure 3). We then feed the point sequence to StreamingKMeans, the streaming k-means implementation of Spark [ZXW + 16b] the popular big-data processing framework. As illustrated in the left panel of Figure 3, the resulting two centers are both within the origin. Now, this result occurs regardless of the last batch's distance from the origin, implying that the per-sample loss performance of the algorithm can be made arbitrarily large. Alternatively, we used a merge-and-reduce based streaming k-means algorithm and show that one of the resulting cluster centers is at the distant cluster (as illustrated in the right panel of Figure 3) thereby keeping the resulting per sample loss at the desired minimum. Specifically we use Streamkm, an implementation of StreamKM++ [AMR + 12] from the ClusOpt Core library [Mac20]. Streaming linear regression. Similar to the clustering setting, in the adversarial setting for streaming linear regression all batches except the last one are sampled around a constellation of four points in the plane such that the optimal regression line is of −1 slope through the origin (see the leftmost panel of Figure 4). The last batch of points however, is again far from the origin (L, L) such that the resulting optimal regression line is of slope 1 through the origin 2 . We compare the performance of LinearRegression from the popular streaming machine learning library River [MHM + 20] to our own row sampling based implementation of streaming linear regression along the lines of Algorithm 1 and observe the following: Without the last batch of points, both implementations result in the optimal regression line, however, the River implementation reaches that line only after several iterations, while our implementation is accurate throughout (This is illustrated in the second-left panel of Figure 4). When the last batch is used, nevertheless, Algorithm 1 picks up the drastic change and adapts immediately to a line of the optimal slope (the blue line of the second right panel of Figure 4) while the River implementation update merely moves the line in the desired direction (the orange line in that same panel) but is far from catching up. Finally, the rightmost panel of Figure 4) details the loss trajectory for both implementations. While the River loss skyrockets upon the last batch, the loss of Algorithm 1 remains relatively unaffected, illustrating its adversarial robustness.  Note that in both the clustering and linear regression settings above the adversary was not required to consider the algorithms internal randomization to achieve the desired effect (this is due to the local nature of the algorithms computations). This is no longer the case in the following last setting.
Sampling vs. sketching. Finally, we compare the performance of the leverage sampling Algorithm 1 to sketching. In this setting, for a random unit sketching matrix S (that is, each of its elements is sampled from {−1, 1} with equal probability), we create an adversarial data stream A such that its columns are in the null space of S. As a result, the linear regression as applied to the sketched data S · A as a whole is unstable and might significantly differ from the resulting linear regression applied to streamed prefixes of the sketched data. As illustrated in Figure 5, this is not the case when applying the linear regression to the original streamed data A using Algorithm 1. Upon the last batch, the performance of the sketching-based regression deteriorates by orders of magnitude, while the performance of Algorithm 1 is not affected. Moreover, the data reduction factor achieved by leveraged sampling 3 is almost double compared to the data reduction factor achieved by sketching. [BJWY20] Omri Ben-Eliezer, Rajesh Jayaram, David P. Woodruff, and Eylon Yogev. A framework for adversarially robust streaming algorithms.  [LK17]) Given ε > 0 and δ ∈ (0, 1), let P be a set of weighted points, with non-negative weight function µ : P → R ≥0 and let s : P → R ≥0 denote an upper bound on the sensitivity of each point. For S = p∈P µ(p)s(p), let m = Ω S 2 ε 2 d + log 1 δ , where d is the pseudo-dimension of the query space. Let C be a sample of m points from P with replacement, where each point p ∈ P is sampled with probability q(p) = µ(p)s(p) S and assigned the weight µ(p) m·q(p) if sampled. Then C is an ε-coreset of P with probability at least 1 − δ.
We first observe that any streaming algorithm that uses linear memory is adversarially robust because intuitively, it can recompute an exact or approximate solution at each step.
Lemma A.2 Given a set of points P , there exists an offline adversarially robust construction that outputs an ε-coreset of P with probability at least 1 − δ.

Proof :
Given an adversary A, let P = p 1 , . . . , p n be a set of points such that each p i with i ∈ [n] is generated by A, possibly as a function of p 1 , . . . , p i−1 . For example, it may be possible that the points p 1 , . . . , p n/2 are a coreset of some set of points P 1 and the points p n/2+1 , . . . , p n (1) were either generated with full knowledge of p 1 , . . . , p n/2 or (2) are a coreset of a set of points P 2 generated with full knowledge of P 1 . Let s(p) be an upper bound on the sensitivity of each point in P and consider the sensitivity sampling procedure described in Lemma A.1. We would like to sample each point with probability q(p). Each point in C is chosen to be p with probability q(p). However, if our algorithm generates internal randomness to perform this sampling procedure, it may be possible for an adversary to either learn correlations with the internal randomness or even learn the internal randomness entirely (such as the seed of a pseudorandom generator). Thus the choice for each point of C may no longer be independent, so we are no longer guaranteed that the resulting construction is a coreset.
Instead, suppose the randomness used by the algorithm at time i in the sampling procedure is independent of the choices of p 1 , . . . , p i−1 , e.g., the algorithm has access to a source of fresh public randomness at each time in the data stream. Then the algorithm can generate C independent of the choices of p 1 , . . . , p i−1 . Thus by Lemma A.1, C is an ε-coreset of P with probability at least 1 − δ. 2 We emphasize that Lemma A.2 shows that any offline coreset construction is adversarially robust; the example of sensitivity sampling is specifically catered to our applications of the merge and reduce framework to clustering.
We now prove our main statement.
Proof of Theorem 1.1: Let δ = 1 poly(n) and consider an ε-coreset construction with failure probability δ. We prove that the merge and reduce framework gives an adversarially robust construction for an ε-coreset with probability at least 1 − 2nδ. We consider a proof by induction on an input set P of n points, supposing that n = 2 k for some integer k > 0. Observe that C 0,j is a coreset of p j for j ∈ [n] since C 0,j = p j . Let E i be the event that for a fixed i ∈ [k] that C i−1,j is an ε 2k -coreset of C i−1,2j−1 and C i−1,2j for each j ∈ n 2 i−1 . By Lemma A.2, it holds that for a fixed j, C i,j is an ε 2k -coreset of C i−1,2j−1 and C i−1,2j with probability at least 1 − δ. By a union bound over n 2 i−1 possible indices j, we have that for a fixed i, all C i,j are ε 2k -coresets of C i−1,2j−1 and C i−1,2j with probability at least 1 − n 2 i−1 · δ. Thus, Pr [E i+1 ] ≥ 1 − nδ 2 i−1 , which completes the induction. Hence with Pr ∪ k i=0 E i , we have that the cost induced by C k,1 is a 1 + ε 2k k -approximation to the cost induced by P . Since 1 + ε 2k k ≤ e ε/2 ≤ 1 + ε, then C k,1 is an ε-coreset of P with probability with high probability. We define the predictable quadratic variation process of the martingale by . Then for all ε ≥ 0 and σ 2 > 0, and every k ∈ [n], |Y t | > ε and w k ≤ σ 2 ≤ 2 exp − ε 2 /2 σ 2 + Rε/3 .
We first show robustness of our algorithm by justifying correctness of approximation for L p norms.
Lemma B.2 (L p subspace embedding) Suppose ε > 1 n , p ∈ {1, 2}, and C > κ p , where κ is an upper bound on the condition number of the stream. Then Algorithm 1 returns a matrix M such that for all x ∈ R d , for sufficiently large C > (κ 1 /κ 2 ) p . Note for p = 2, we have the upper bound on the condition number κ ≥ κ 1 /κ 2 so it suffices to set C = κ 2 . Since κ p 1 x p p ≤ Ax p p , then we have Thus | Mx p p − Ax p p | ≤ ε Ax p p with probability at least 1 − 1 2 d poly(n) . By a rescaling of ε since p ≤ 2, we thus have that | Mx p − Ax p | ≤ ε Ax p with probability at least 1 − 1 2 d poly(n) . We now show that we can union bound over an ε-net. We first define the unit ball B = {Ay ∈ R n | Ay p = 1}. We also define N to be a greedily constructed ε-net of B. Since balls of radius ε 2 around each point cannot overlap, but must all fit into a ball of radius 1 + ε 2 , then it follows that N has at most 3 ε d points. Therefore, by a union bound for 1 ε < n, we have | My p − Ay p | ≤ ε Ay p for all Ay ∈ N , with probability at least 1 − 1 poly(n) . We now argue that accuracy on this ε-net implies accuracy everywhere. Indeed, consider any vector z ∈ R d normalized to Az p = 1. We shall inductively define a sequence Ay 1 , Ay 2 , . . . such that Az − i j=1 Ay j p ≤ ε i and there exists some constant γ i ≤ ε i−1 with 1 γi Ay i ∈ N for all i. Define our base point Ay 1 to be the closest point to Az in the ε-net N . Then since N is a greedily constructed ε-net, we have that Az − Ay 1 p ≤ ε. Given a sequence Ay 1 , . . . , Ay i−1 such that Ay j p = 1. Thus we inductively define the point Ay i ∈ N so that Ay i is within which completes the induction for time n. 2

B.1 Adversarially Robust Spectral Approximation
We observe that Lemma B.2 provides adversarial robustness for free.
Proof : Let us inspect the proof of Lemma B.2. Observe that since the adversary can observe the past data and the past randomness of Algorithm 1, then the rows a i are random variables that depend on the history and the randomness of the algorithm. In other words, a i is measurable with respect to the sigma algebra generated by a 1 , . . . , a i−1 , B 1 , . . . , B i−1 , C i where B i is the indicator of the event that we sample row a i in Algorithm 1 and C i is the random vector generated by the adversary at step i to create row a i . Denote F i the sigma algebra generated by a 1 , . . . , a i−1 , B 1 , . . . B i−1 , C i . Then a i is measurable with respect to F i . Let us remind that Y j = Y j−1 + X j and let us observe that the definition of X j in Equation (1) can be rewritten as It can be easily checked that This is because Y j−1 , p j , a j are measurable with respect to F j . This implies that in the adversarial setting sequence Y j is a martingale with respect to the filtration F 0 ⊂ F 1 ⊂ · · · ⊂ F n .
The remainder of the proof of Lemma B.2 goes through as is for arbitrary rows a i 's. Thus, the algorithm is indeed adversarially robust.  ) for p = 2. We note that κ is an adversarially chosen parameter, since the rows of the input matrix A are generated by an adversary. One can mitigate possible adversarial space attacks by tracking κ and aborting if log κ exceeds a desired threshold.

Proof of Lemma 3.7:
Algorithm 1 is adversarially robust by Lemma B.3. It remains to analyze the space complexity of Algorithm 1. By Lemma B.3 and a union bound over the n rows in the stream, each row a i is sampled with probability at most 4ατ i , where τ i is the online leverage score of row a i . By Lemma B.4, we have n i=1 τ i = O (d log κ) and we also set α = O dκ ε 2 log n . Let γ > 0 be a sufficiently large constant such that We use a martingale argument to bound the number of rows that are sampled. Consider a martingale U 0 , U 1 , . . . , U n with difference sequence W 1 , . . . , W n , where for j ≥ 1, we set W j = 0 if U j−1 > d 2 γκ log κ ε 2 log n and otherwise if U j−1 ≤ d 2 γκ log κ ε 2 log n, we set We have E [U j |U 1 , . . . , U j−1 ] = U j−1 , then the sequence U 0 , . . . , U n induced by the differences is indeed a valid martingale. Note that intuitively, U n is the difference between the number of sampled rows and n j=1 p j . Since a j is sampled with probability p j ∈ [0, 1], Moreover, we have E [|W j | | U 1 , . . . , U j−1 ] ≤ 1. Thus by Freedman's inequality (Theorem B.1) with σ 2 = n j=1 ατ j ≤ d 2 γκ log κ ε 2 log n and R ≤ 1, Pr |U n | > d 2 γκ log κ ε 2 log n ≤ 2 exp − d 4 γ 2 κ 2 log 2 κ log 2 n/(2ε 4 ) σ 2 + Rd 2 γκ log κ log n/(3ε 2 ) ≤ 1 poly(n) .
Hence we have that with high probability, the number of rows sampled is O 1 ε 2 d 2 κ log κ log n . 2 We remark that the space bounds for Lemma 3.7 could similarly be shown (with constant probability of success) using Markov's inequality though analysis Freedman's inequality provides much higher guarantees in terms of probability of success.
On the other hand, it is not clear how to execute a similar strategy using the Matrix Freedman's Inequality rather than using Freedman's inequality. This is because to obtain the desired spectral bound, we must define a martingale at time j in terms of both the matrix A j and whether the rows a 1 , . . . , a j−1 were previously sampled. However, since A j is itself a function of whether a 1 , . . . a j−1 were previously sampled, the resulting sequence is not a valid martingale.
We first require the following bound on the sum of the online ridge leverage scores, e.g., Theorem 2.12 from [BDM + 20], which results from considering Lemma 2.11 in [BDM + 20] at O (log n) different scales. . . . • a n ∈ R n×d arrive in a stream with condition number at most κ, let λ i = is the best rank k approximation to A i . Let i be the online ridge leverage score of a i with regularization λ i . Then n i=1 i = O (k log n log κ). From Lemma B.5 and a similar argument to Lemma B.2, we also obtain adversarially robust projectioncost preservation and therefore low-rank approximation. Namely, [CMM17, BDM + 20] showed that projectioncost preservation essentially reduces to sampling a weighted submatrix M of A such that Mx 2 2 + λ x 2 2 ∈ (1 ± ε)( Ax 2 2 + λ x 2 2 ) for a ridge parameter λ. Since the online ridge leverage score of each row a i can be rewritten as max x∈R d ai,x 2 +λ x 2 2 Aix 2 2 +λ x 2 2 , then the same concentration argument of Lemma B.2 gives Lemma 3.8.

B.2 Adversarially Robust Linear Regression
We first give the formal definition of linear regression: Problem B.6 (Linear Regression) Given a matrix A ∈ R n×d , a vector b ∈ R n and an approximation parameter ε > 0, the goal is to output a vector y such that Lemma B.7 (Adversarially Robust Linear Regression) Given ε > 0 and a matrix A ∈ R n×d whose rows a 1 , . . . , a n arrive sequentially in a stream with condition number at most κ, there exists an adversarially robust streaming algorithm that outputs a (1 + ε) approximation to linear regression and uses O d 3 ε 2 log 2 n log κ bits of space, with high probability.
Proof : Suppose each row of A arrives sequentially, along with the corresponding entry in b. Let B = A•b so that the effectively, the rows of B arrive sequentially. Note that if M is a spectral approximation to B, for all vectors v ∈ R d+1 . In particular, let w ∈ R d+1 be the vector that minimizes Mv 2 subject to the constraint that the last coordinate of w is 1, and let w = y 1 . Then we have Let z be the vector that minimizes Ax − b 2 and let u = z 1 . Then we have where the last inequality follows from the minimality of w. Thus we have that Ay − b 2 ≤ (1 + O (ε)) Az − b 2 . 2

C Missing Proofs from Section 4
Other Related Works. Note that there is an alternate streaming algorithm for graph sparsification given in [GKK10] which has the same guarantees but is computationally faster. However, we choose to analyze the algorithm of [AG09] since its core argument is sampling based. Nevertheless, it is possible that the algorithm from [GKK10] is also adversarially robust. Lastly, we recall that our model is the streaming model where edges arrive one at a time. There is also related work in the dynamic streaming model (see [KNST19] and references therein) where previously shown edges can be deleted but this is not the scope of our work. The notion of the connectivity of an edge is needed to in the algorithm of [AG09].

Definition C.1 (Connectivity [BK96])
A graph is k-strong connected iff every cut in the graph has value at least k. A k-strong connected component is a maximal node-induced subgraph which is k-strong connected. The connectivity of an edge e is the maximum k such that there exists a k-strong connected component that contains e.
Algorithm 2 Graph sparsification algorithm from [AG09]. Input: A stream of edges e 1 , · · · , e m and an accuracy parameter ε > 0 Output: Sparified graph H 1: H ← ∅ 2: ρ ← C(log n + log m)/ε 2 for sufficiently large constant C > 0 3: for each new edge e do Add e to H with probability p e and weight 1/p e times its original weight 7: return H We begin by providing a brief overview of our proof. The first step is to show that for a cut in G of value c, the same cut in the sparsified graph H has value that concentrates around c. Note that in [AG09], the concentration inequality they obtain depends roughly on exp(−c). In other words, they get a stronger concentration for larger cuts in the original graph. However, their concentration inequality is not valid in our setting since the value c is random. Therefore, we employ a different concentration inequality, namely Freedman's inequality (Theorem Theorem B.1) in conjunction with an assumption about the sizes of cuts in the graph to obtain concentration for a fixed cut. The second step is to use a standard worst-case union bound strategy to bound the total number of cuts with a particular size in the original graph. This uses the standard fact that the number of cuts in a graph that is at most α times the minimum cut is at most n 2α . Then the final result for the property (1) in Problem 4.1 follows by combining the union bound with the previously mentioned concentration inequality. The bound for the total number of edges (condition (2) in Problem 4.1) is a "worst case" calculation in [AG09] so it automatically ports over to our setting. Note that we assume κ 1 and κ 2 to be deterministic lower and upper bounds on the size of any cut in G and define κ to be their ratio. Theorem 1.3 Given a weighted graph G = (V, E) with |V | = n whose edges e 1 , . . . , e m arrive sequentially in a stream, there exists an adversarially robust streaming algorithm that outputs a 1 ± ε cut sparsifier with O κ 2 n log n ε 2 edges with probability 1 − 1/ poly(n).
Proof : We claim through induction the stronger statement that the value C H of any cut in H is a (1 + ε)approximation of the value C G of the corresponding cut in G for all times j ∈ [m] with high probability. Consider a fixed set S ⊆ V and the corresponding cut C = (S, V \ S). Let e 1 , . . . , e m be the edges of the stream in the order that they arrive. We emphasize that e 1 , . . . , e m are possibly random variables given by the adversary rather than fixed edges. For each j ∈ [m], let G j be the graph consisting of the edges e 1 , . . . , e j and let H j be the corresponding sampled weighted subgraph. We abuse notation and define p j := p ej to denote the probability of sampling the edge e j that arrives at time j. We use C (j) G and C (j) H to denote the value of the cut at time j in graphs G and H, respectively. Note that p 1 = 1, so we have H 1 = G 1 for our base case.
We assume the statement holds for all j ∈ [m − 1] and prove it must hold for j = m. We define a martingale Y 0 , Y 1 , . . . , Y m through its difference sequence X 1 , . . . , X m , where for j ≥ 1, we set X j = 0 if C (j−1) H ∈ (1 ± ε)C (4)