{'fraction_non_alphanumeric': 0.04855630860644323, 'fraction_numerical': 0.009748398477393, 'mean_word_length': 4.145211368521615, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning to Cooperate in D2D Caching Networks

We consider a wireless device-to-device (D2D) cooperative network where memory-endowed nodes store and exchange content. Each node generates random file requests following an unknown and possibly arbitrary spatio-temporal process, and a base station (BS) delivers any file that is not found at its neighbors' cache, at the expense of higher cost. We design an online learning algorithm which minimizes the aggregate delivery cost by assisting each node to decide which files to cache and which files to fetch from the BS and other devices. Our policy relies on the online gradient descent algorithm, is amenable to distributed execution, and achieves asymptotically optimal performance for any request pattern, without prior information.


I. INTRODUCTION
The rapidly growing demand for mobile content delivery [1] creates new revenue opportunities for wireless networks, but also requires to increase rapidly their capacity. Unfortunately, typical solutions based on PHY-layer advances or network densification are constantly outpaced by the increasing demand [19], and this calls for new content delivery approaches. To this end, a potentially game-changing idea is to employ device-todevice (D2D) communications where memory-endowed user devices can cache popular files and exchange them with each other upon request [9]. Such cooperative D2D swarms can increase the network content delivery capacity, mitigate cellular congestion, and improve the end-user experience.
A key challenge in D2D cooperative caching is to design the caching policy, i.e., identify which files to cache at each device at any given time [20]. On the one hand the devices have small storage and therefore can store only a small subset of the possible content files; on the other hand each of them "sees" a small number of requests per unit time and hence estimating the popular files at each location becomes very challenging. In view of these limitations, the devices may consistently fail to store in their cache the files that will be requested in the future by their neighbors, rendering the D2D cache-hit ratio practically negligible and hence this solution ineffective.
Caching policies often assume that requests are generated by a given stationary process, cf. [19], and systems in practice rely on reactive policies such as LFU and LRU. These, however, solve the 1-cache problem conditionally on the request process. For example, LFU is suitable for stationary requests [7], and LRU for the adversarial model [17]. When the actual process is other than assumed these policies perform poorly [18], and this problem is exacerbated in D2D networks where popularity has hot spots in time and space. Recently, [2], [8], [14] proposed dynamic policies for caching networks, e.g., the m-LRU [8] or "lazy rule" [14] policies, which however G. S. Paschos  do not offer performance guarantees. Hence, the problem of designing a policy robust to the D2D network dynamics is an equally challenging and important open problem.
In this cooperative D2D network, users might change positions and content preferences, and hence we need an algorithm that will allow each device to decide: (i) which files to cache for serving its neighbors' needs; (ii) from which neighbors to retrieve a file, and when to use the last-resort solution of the base station (BS), Fig. 1. This requires a learning mechanism for making caching and routing decisions in an online and decentralized fashion. Previous efforts employing learning are restricted either to inference of the popularity model [3], [4]; or rely in Q-learning [21], [24] and classification techniques [15] to estimate request frequencies. These approaches are not applicable to this D2D scenario as they are centralized, exhibit often high complexity, presume a stationary model, and do not decide routing. Other interesting suggestions for D2D networks, see [6], [13], suffer from computational complexity or rely on assumptions that are valid only in some cases, e.g., known popularity. Finally, [11] proposes a decentralized D2D file sharing algorithm which however needs access to the pattern of file requests and network evolution.
Here we design a caching policy that has universallyoptimal performance, which is defined as the cost for delivering the requested files to users through (cheap) D2D or (costly) BS-to-device transmissions. We formulate the D2D caching operation as an online convex optimization (OCO) problem, and develop a dynamic and distributed algorithm that solves it without the need to make any assumption about the request pattern. That is, our policy ensures asymptotically no regret, as it achieves no more average cost than a static caching configuration selected with knowledge of future requests.
The contributions of this paper can be summarized as follows. (i) We propose the idea of embedding a distributed online learning mechanism to D2D caching policies. We achieve this by formulating an OCO problem, and this opens a link between caching and this novel machine learning tool. (ii) We design an online caching policy that leverages the online gradient descent algorithm to achieve asymptotically optimal performance under any possible spatio-temporal request pat-tern in our D2D network. We also explain how our policy can adapt to network changes and user churn. (iii) We compare our policy with the state-of-the-art mLRU and "lazy" LRU policies, verifying that it outperforms its competitors, while converging to the optimal static policy.

II. SYSTEM MODEL
Network. Consider a set I of I wireless users in an area, each one with a cache of size C i ≥ 0, i ∈ I. Let L be the set of direct links connecting the users, where a link appears if the devices' proximity and the electromagnetic environment allows it to be reliably established. A link between i and j is associated to a cost c ij , (i, j) ∈ L, which represents, e.g. application-layer latency performance or energy consumption during content transmission; and we assume c ii = 0, ∀i ∈ I. All users maintain a connection with a base station (BS, subscripted with 0), and we define I + = I ∪ {0} and I + = |I + |. The users can obtain any file from the BS at cost c i0 > c ij , ∀i ∈ I, (i, j) ∈ L. We assume that links can deliver the requested content in the considered time window.
Requests. There is a catalog N with N files of unit size. The system operation is time-slotted, and r i,n t ∈ {0, 1} denotes the event that a request for file n has been submitted by user i during slot t. At each t we assume there is one request, or, from a different perspective, that the system decisions are updated after each request. 1 Hence, the request process is described by a sequence of vectors {r t } t=1,...,T drawn from set: The instantaneous file popularity is expressed by the probability distribution P (r t ) (with support R), which is allowed to be unknown and arbitrary. The same holds for the joint distribution P (r 1 , . . . , r T ) that describes the file popularity evolution, for any user location, and within an interval of T slots. This generic model captures all possible spatio-temporal request sequences, including stationary (i.i.d. or otherwise), non-stationary, and adversarial models. The latter is the most general case, as they include request sequences selected by an adversary aiming to disrupt the system performance.
Caching. The cache of each user i ∈ I can store only C i < N files, but the BS has the entire catalog. Following the standard practice in wireless caching models [9], [19], we perform caching using the Maximum Distance Separable (MDS) codes. In MDS, the files are split into a fixed number of F data chunks, and we store in each cache an amount of coded chunks that are pseudo-random linear combinations of the data chunks. Using the MDS properties, a user can decode the file (with high probability) if it receives any F coded chunks. Hence, the caching decision vector y t has N ·I elements, where y i,n t ∈ [0, 1] denotes the amount of random 1 We can also consider batches of requests. If the batch has 1 request from each location, the pattern is biased to equal request rate at each location. An unbiased batch should contain an arbitrary number of requests from each location. Our guarantees hold for unbiased batches of arbitrary finite length. coded chunks of file n stored at user i during slot t. 2 Based on this, we introduce the convex set of eligible caching vectors: We are interested in distributed policies, where each user i changes its cache y i t = (y n,i t , n ∈ N ) based on information from its one-hop neighbors j : (i, j) ∈ L. Thus, we define: Definition 1 (Local Caching Policy). A local caching policy σ i for user i is a (possibly randomized) rule the caching policies for all users will be henceforth referred to as a "caching policy".
Routing. Since each user i ∈ I might have more than one neighbors, we introduce routing variables to determine the cache from which the requested file will be fetched. Let z n,i,j t ∈ [0, 1] denote the portion of request r n,i t that is fetched from cache j, and we define the routing vector z t = (z n,i,j t , n ∈ N , i, j ∈ I) implemented in slot t. There are two important remarks here. First, due to the coded caching model, the requests can be simultaneously routed from multiple caches. In terms of communications, this can be implemented through time-sharing among the activated links, or using concurrently different network interfaces. Second, the caching and routing decisions are coupled and constrained: (i) a request cannot be routed from an unreachable cache, (ii) we cannot route from a cache more data chunks than it has, and (iii) each request must be fully routed.
We define ij = 1 if {(i, j) ∈ L} and ij = 0 otherwise, and thus the set of eligible routing decisions conditioned on y t is: Note that z n,i,0 t does not appear in the second constraint, because the BS stores the entire catalog and can serve all users. This last-resort routing option ensures that Z t (y t ) is non-empty for any y t ∈ Y. As it will become clear next, the optimal routing decisions can be devised for a given cache configuration. This is an inherent property of linkuncapacitated caching networks, see also [9], [19].

III. PROBLEM FORMULATION
A file request of a node can be served, exclusively or partially (due to MDS), by neighboring devices at a smaller cost than fetching it from the base station. Given a cache configuration y t , the (minimum) cost to satisfy r t is: where the optimization decides the routing that minimizes the cost for a given file placement at the nodes. The function's form suggests that is beneficial if the file has been cached at the device asking for it (c ii = 0) or at nearby devices that can send it with low cost. However, it is daunting to assess the impact of y t , as it involves the solution of an optimization problem. Fortunately, the cost function above is convex: Proof: Fix a request vector r t and consider cache configurations y 1 , y 2 ∈ Y; note that, for any λ ∈ [0, 1], y = λy 1 +(1−λ)y 2 is also a valid configuration. We will show that: Let us denote z * 1 , z * 2 , z * the optimal routing vectors corresponding to y 1 , y 2 , y, respectively. We then have: Subscript t at the cost function (2) reminds us its dependence on the request r t that is generated at t. Since these events may vary according to a non-stationary process, we will use the concept of regret from online convex optimization [22].
We capture that the request sequence may follow any arbitrary and a priori unknown probability distribution, by using the idea of an adversary which selects r t at each slot t, while knowing y t . This assumption reflects that, in practice, caches are populated before the requests are issued. Since by Lemma 1 f t (y) are convex, our problem falls in the Online Convex Optimization framework [22]. The performance metric of an algorithm in this line of work is the regret: the difference between costs incurred by the algorithm and the best static configuration in hindsight. In our case, this benchmark is the optimal cache configuration (same for all slots) devised with knowledge of all requests in the time horizon of interest T . Hence, the regret of policy σ is: The expectation is over the joint probability distribution of requests and possible randomizations in σ and, is the best fixed action in hindsight, i.e. the best chunk placement over the entire sample path of requests. Our goal is to devise a policy whose regret scales sublinearly with T : This "no regret" property implies that the algorithm learns to perform as good as the best cache configuration y * . Note that if the requests are i.i.d. "no regret" implies that the performance of the policy approaches the optimal in terms of ∼ t f t (y * ). However, our adversarial model is much more general; in this case, comparing to a static policy is a way to limit the power of the adversary while still being able to obtain meaningful policies, which are robust for all request models.

IV. DISTRIBUTED D2D CACHING ALGORITHM
Our distributed caching algorithm is based on online gradient descent [25]. The main idea is to use the first order approximation f (y) = f t (y t )+∇f t (y t ) (y−y t ) as a predictor of the unknown function f t+1 (y) that the adversary will select next. The caching configurations, then, are updated by taking an appropriate step in the direction of the gradient ∇f t (y t ).

A. Finding the Direction of Improvement
Since the utility function (2) is not necessarily differentiable everywhere, we will rely on subgradients. In order to find one, we first simplify f t (y). Let us denote i t , n t the user making the request and the file requested at slot t, respectively, and J (i) = {j ∈ I + : ij = 1} the set of the nodes (including the BS) connected to user i. Then, it is z n,i,j = 0, ∀n = n t , i = i t , j / ∈ J (i t ), and hence f t (y t ) simplifies to: Equations (6)-(8) define an optimization problem, henceforth referred to as P f , the solution of which yields the optimal routing for any y t (constant input for P f ). That is, to evaluate f t (·) at vector y t we need to solve P f . Despite this intricate form of f t (y t ), we show that it is possible to obtain a subgradient which is needed for our online caching algorithm. We first define the Lagrangian of P f as follows: where α and β j are the dual variables, and we simplified notation by dropping n t , i t . We will prove that the subgradient of f t at y t is the optimal dual variables for (8) in P f . Lemma 2 (Subgradient). Let: and define: Then g t (y t ) is a subgradient of f t at y t , that is: f t (y ) ≥ f t (y t ) + g t (y t ) (y − y t ), ∀y ∈ Y. Proof. We start by denoting β * (y ) the outcome of (10) for cache configuration y ∈ Y and define the function: Λ(y, β) = max α∈R min z∈[0,1] I + L(y, z, α, β), ∀y ∈ Y, and hence: where (α) holds since (6)-(8) has the strong duality property; (b) holds since Λ(·) is linear and we can maximize successively over the different primal or dual variables; and (c) holds as only − j∈J (ut) β j y nt,j in L t (·) depends on y. Due to strong duality for y , we can replace f t (y ) = Λ(y , β * t (y )), and then suffices to rearrange terms.
Since β * t (y t ) is the optimal multiplier for (8), it has nonzero elements only where this constraint is tight. Intuitively, this means that after user i t requests file n t , the direction of the subgradient is towards caching more parts of this file at user i t and at users having low-cost D2D links with i t .

B. Algorithm Design
The Distributed Online Caching Policy (DOCP) is shown in Algorithm 1. The execution of the policy is iterative, where in each slot t the following steps take place. First, a user i t submits a request for a file n t (step 3). This user solves (6)-(7) to find the optimal routing for the current caching configuration y t (step 4), and requests the parts of n t from the respective neighbors or the BS (step 5). A certain utility is accrued based on this routing z * t and the existing y * t (that was calculated based on previous requests). Then, user i t sends the optimal multiplier β * ,j t (y t ) to each neighbor j ∈ J (i t ) (step 8) who updates its caching policy accordingly. This involves calculating the new y * t+1 , based on the latest request, and projecting them back into the feasible space (step 9): where Π X (.) is the Euclidean projection on X , and e n ∈ R N has zero elements except the n-th element being equal to 1. Note that DOCP is indeed distributed, since only the neighbors of each requester need to update their caches. Moreover, this update is based solely on messages received by the requester, and these communication overheads are moderate as only the Lagrange multipliers are sent to 1-hop neighbors. Finally, the projection operation can be executed efficiently, i.e., in O(N log N ) runtime, and for each user independently, by using the local projection algorithm introduced in [18]. We omit the details here due to lack of space.

C. Performance Guarantees
The next theorem proves that DOCP achieves no regret performance, under any possible spatio-temporal arrival pattern.

5
User it fetches data from BS or D2D links, based on z * t . 6 Utility ft is accrued based on y * t , z * t .

7
New caching configuration is devised: for j = 1, . . . , |J (it)| do 8 User it sends to user j message β * ,j t using (10). 9 User j updates its cache by y j t+1 = Π [0,1] N z j , where z j,n = y j,n t + γβ * ,j t 1{n = nt}, ∀n ∈ N . end end where, we defined the parameters c * = max i∈I c i,0 , C = max i∈I C i and J * = max i∈I |J (i)|.
Proof: Using non-expansiveness of Euclidean projection: Also, a telescopic sum over T slots gives To proceed, note that y 1 − y * 2 ≤ 2CJ * and g t (y t ) ≤ (max i∈I c 0,i ). Using that y T − y * 2 ≥ 0 and rearranging: Furthermore, due to convexity of f t (y), it holds f t (y * ) − f t (y t ) ≥ g t (y t ) (y * − y t ), thus: The value of the step size and regret bound follow by minimizing the Right Hand Side of the above inequality. Hence, no regret is achieved with a constant step which depends on T , and if T is unknown we can select step 1/ √ t, or employ the doubling trick, see [22,Sec. 2.3].

D. Dynamic Network Costs
The above model and analysis can be readily extended for the case where users change positions in different slots; or the user population evolves with time; or, finally, the users are static but the channel conditions vary. In particular, these scenarios can be captured by the updated cost function: f t (y t ) = min zt∈Zt(yt) n∈N i∈I j∈I+ where we have replaced the previously constant link costs with slot-specific ones {c t ij , ∀(i, j) ∈ L, t = 1, . . . , T }. For instance, if link (i, j) exists in slot t but not in slot (t + 1) (e.g., nodes have moved farther), then we can use c t+1 ij = c max > max{c i0 , ∀i ∈ I} which will make this link non-eligible for DOCP (the BS is available and cheaper). It is interesting to note that this extension does not change the regret bound, which is set by the highest cost of the available links, that remains the one between any device and the BS.

V. NUMERICAL RESULTS
We illustrate the performance of DOCP in a setting with N = 100 files, and 8 devices which are equipped with a cache of capacity C = 6 and are placed randomly in a cell of size 1.5Km. Devices can communicate if they are within a range of 500m, as in current LTE-direct standards [10]. The (relative) cost of downloading a file from the base station is set to 10; a device can fetch a file from its cache at no cost; and the respective costs from other devices vary with the distance: 2 if the device is closer that 100m, 5 if the distance is within [100m, 300m), 7 if in [300m, 400m), and 9 if in [400m, 500m]. File requests are drawn from a power law distribution with exponent 0.9. We compare DOCP with the best static policy in hindsight and the lazy LRU and mLRU.
Our results are presented in Fig. 2 which shows the empirical average of the cost for the different policies. We observe that DOCP outperforms both LRU and mLRU, and the margin gets wider as time progresses. In addition, the performance of DOCP gets closer to the one of the best policy in hindsight, thus verifying the no-regret theoretical guarantee. Figure 3 compares the total cache allocation, i.e., the total fraction of each file cached at the devices, for DOCP and the best static hindsight policy. We see that, while the algorithm starts from an almost uniform allocation, by the end of the time interval T = 4000 the DOCP cache contents are very aligned with the best configuration in hindsight. This demonstrates that DOCP indeed tends to learn the best static configuration.

VI. CONCLUSIONS
D2D cooperative caching is certainly very promising, but raises previously unseen challenges in devising effective caching policies. Here, we used OCO, a fast-developing area of machine learning, to design an online distributed caching and routing policy that adapts to any (unknown) spatiotemporal request process. This makes it an ideal candidate for such dynamic, often sparse, caching networks. Our work opens a new exciting area at the nexus of online learning and D2D caching systems, and a fascinating next step is to explore how such mechanisms can incorporate incentives for ensuring users' cooperation, leveraging credit mechanisms [12] or the human tendency to build reciprocal sharing relationships [23].