{'fraction_non_alphanumeric': 0.038392743068864185, 'fraction_numerical': 0.009539627784165922, 'mean_word_length': 4.66023864047246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
CAPS: Context Aware Personalized POI Sequence Recommender System

The revolution of World Wide Web (WWW) and smart-phone technologies have been the key-factor behind remarkable success of social networks. With the ease of availability of check-in data, the location-based social networks (LBSN) (e.g., Facebook1, etc.) have been heavily explored in the past decade for Point-of-Interest (POI) recommendation. Though many POI recommenders have been defined, most of them have focused on recommending a single location or an arbitrary list that is not contextually coherent. It has been cumbersome to rely on such systems when one needs a contextually coherent list of locations, that can be used for various day-to-day activities, for e.g., itinerary planning. This paper proposes a model termed as CAPS (Context-Aware Personalized POI Sequence Recommender System) that generates contextually coherent POI sequences relevant to user preferences. To the best of our knowledge, CAPS is the first attempt to formulate the contextual POI sequence modeling by extending Recurrent Neural Network (RNN) and its variants. CAPS extends RNN by incorporating multiple contexts to the hidden layer and by incorporating global context (sequence features) to the hidden layers and the output layer. It extends the variants of RNN (e.g., Long-short term memory (LSTM)) by incorporating multiple contexts and global features in the gate update relations. The major contributions of this paper are: (i) it models the contextual POI sequence problem by incorporating personalized user preferences through multiple constraints (e.g., categorical, social, temporal, etc.), (ii) it extends RNN to incorporate the contexts of individual item and that of the whole sequence. It also extends the gated functionality of variants of RNN to incorporate the multiple contexts, and (iii) it evaluates the proposed models against two real-world data sets.


INTRODUCTION
The POI recommendation systems have been very popular in the last few years. Such systems exploit the explicit historical check-in data and some implicit aspects or contexts to generate a list of POIs that are of potential interest to users. Generally, most of the POI recommenders recommend a single POI or an arbitrary list of POIs (Yuan et al. (2013); Zhang and Chow (2015)) that satisfy the personalized user preferences but may not be contextually coherent. Often, users need a list of items that are contextually coherent as per the preferences of users. Such a coherent list of recommendation can be formulated as a sequence modeling problem where the sequence of items need to adhere to users' preferences by addressing constraints that are applicable to the consecutive items and also to the whole sequence. For instance, in the case of itinerary recommendation, the distance between consecutive places, total trip time, tentative start/end time, start/end place/category, etc. can be the major concerns.
In comparison to the general item recommendation, the POI recommendation is more challenging as it is sensitive to various aspects (e.g., categorical, social, spatial, temporal, etc.) (Yuan et al. (2013); Zhang and Chow (2015); ; ) and the impact of those aspects might vary on the preference of user ( Baral and Li (2017)). The POI sequence recommendation becomes even more interesting and challenging because of following major reasons: 1. the brute-force approaches on computing all permutations of the POIs are NP-hard problem and are not useful, 2. getting a preferred list from an arbitrary list may not be optimal because the preferred list need to satisfy multiple constraints, for instance, the places in a trip should be contextually coherent, need to satisfy many constraints, such as spatial (near/far places), temporal (relevant places for a time of a day, for instance bars can be relevant at evening or night), social (as the trip might be a family, friend focused), time budget constraint of the traveler, start and end POIs, etc., 3. the contexts can be user dependent and can vary dynamically in real-time (e.g., the same context may not be always relevant to a user).
There are few studies that focused on POI sequence recommendation. Most of the existing systems are focused on either frequency-based user interest or the average visit durations but incorporation of major constraints (such as distance between consecutive POIs, social constraints, categorical constraints, and temporal constraints) is less explored and is of great interest in the recommendation community. This paper attempts to fill the gap by incorporating multiple constraints for POI sequence modeling.
We can envision some implicit relevance between POI sequence modeling and the word sequence modeling. First, the smallest elements (check-ins and words) have some contextual coherence with their neighbors. Second, most of the subsequences (check-ins made within a time duration, and a sentence) comprise of contextually coherent elements and also have contextual relation with neighbors (check-ins of preceding/succeeding time duration, and neighbor sentences). Third, the ordered sequence of elements (chronological check-ins of a user, and a text) follow some pattern which can be modeled to learn relation between subsequences (e.g., predict the next check-in and predict next word).
Besides the aforementioned relevances, the contextual POI sequence modeling is more challenging due to the following reasons: (i) the POI sequence modeling can have longer contextual impact (e.g., unlike the language model where the n-grams can capture most of the context, the set of check-ins can be unique every day) and adhere to personalized preferences, (ii) unlike the language modeling tasks (where there is mostly a one-to-one mapping between the input and output items, e.g., language translation problems), the POI sequence modeling can have many-to-many relation (e.g., depending on the context, a user who has visited a set of locations can select multiple destinations). Sometimes the POI sequences can repeat (for instance, a user can depict same check-in pattern after some time interval) which is rare in language modeling (e.g., in next sentence prediction, the input sentences are mostly unique), and (iii) the real-time contexts can complicate the problem formulation using traditional sequence models.
Inspired from the wider popularity of RNN and its variants in sequence modeling (e.g., language modeling (machine translation) and image caption generation) (Mikolov et al. (2010); Mikolov and Zweig (2012); Ghosh et al. (2016); Bengio et al. (2003)), we attempt to cope with the challenges of contextual POI sequence modeling by incorporating the local contexts (context valid for subsequence) and global contexts (context valid for whole sequence). The local contexts (known as context now onwards in the paper) are incorporated into the recurrent module and the global contexts (known as feature of sequence now onwards in the paper) are fed to all the layers in the network. We also extend the gating mechanism of LSTM to incorporate the context and feature for personalized POI sequence modeling. To the best of our knowledge, the proposed model is the first one to address the multi-context POI sequence modeling using extended RNN and its variants.
The major contributions of this paper are: (i) it introduces all the major personalized user constraints (such as temporal, categorical, spatial etc.) as the influential context in the POI sequence modeling, (ii) it extends RNN and its variants to explicitly incorporate relevant contexts, and (iii) it evaluates the proposed models against two real-world datasets.

RELATED RESEARCH
We categorize the relevant studies using two broad notions -general data mining-based studies, and neural networkbased studies.

General Data Mining Approaches
Most of the existing studies were focused on analysis of landmark visit patterns by exploiting the geo-spatial and temporal traces from check-ins. However, those studies mostly focused on the analysis only and ignored synthesis or recommendation of new paths. The Orienteering approach from Feillet et al. (2005) (2016)), content-based approach (Bohnert et al. (2012)), Apriori principle (Lu et al. (2012); Yu et al. (2016)), matrix factorization ), topic-modeling (Liu et al. ( , 2014), and tree traversal approaches (Zhang et al. (2015)). Dunstall et al. (2003) proposed a trip planner that matched the explicit user inputs against a database to get the best matching itineraries. Tai et al. (2008) mined itineraries' data and generated sequences by implicitly incorporating users' interests via the images on Flickr 2 . However, they did not focus on constructing an itinerary from scratch and also did not address the major aspects, such as the temporal influence on users and locations. A content-based filtering approach from Bohnert et al. (2012) exploited visitors' explicit ratings to recommend tours in a museum. Unlike a real trip, the order of recommended items and the distance between consecutive items were not focused in this system. The greedy algorithm-based approaches (De Choudhury et al. (2010); Vansteenwegen et al. (2011)) matched user profiles (consisting of preferred location categories, types, start/end time, and keywords) to relevant places. Lu et al. (2012) mined user check-in data and exploited the Apriori-based algorithm. Thought it was computationally intensive, it was able to find optimal trips under multiple constraints, such as social relationship, temporal property, categorical diversity, and parallel computing simultaneously.  exploited the uncertain travel time between two POIs and the POI availability constraints and proposed a tree-based algorithm to solve the personalized trip recommendation problem. A recent study from Wang et al. (2016) proposed a personalized trip recommender that was able to handle the crowd constraints (i.e., avoid peak hour of POIs) by extending the Ant Colony Optimization algorithm. Zheng and Xie (2011) proposed a HITS-based inference model to evaluate the degrees of user experiences and location interests based on GPS trajectory data.
A heuristic-based algorithm from Chen et al. (2015) exploited user preferences, and traveling times based on different traffic conditions using trajectory patterns derived from taxi GPS traces. The heuristic search-based travel route planning system from Yu et al. (2016) exploited only user preferences and spatio-temporal constraints. Jiang et al. (2016) proposed a ranking-based system to recommend personalized travel sequences in different seasons by merging textual data and view point information extracted from images. However, they did not use the constraints for social, temporal preference of users, and temporal popularity of places. Another recent study from Lim et al. (2017) proposed time-based user interest and demonstrated advantages over the use of frequency-based popularity measures.They exploited geo-tagged images and incorporated contexts, such as visit duration, users' preferences, and start and end points. However, their model did not address the categorical, temporal, and social constraints on the POI sequence. A probabilistic model from  incorporated POI categories and user behavior history to generate trajectories. They used Rank-SVM to rank the items and used Markov model to predict the transition between POIs.
Most of the existing studies have exploited few contexts and have focused on personalized POI visit durations. Unlike others, our study exploits multiple contexts (temporal, spatial, categorical, and social) to generate the POI sequence. In comparison to the existing studies, this paper presents following major differences: (i) it exploits multiple contexts (temporal, spatial, categorical, and social) to model the contextual POI sequence problem, (iii) it extends the RNN by incorporating multiple contexts to efficiently model the personalized contexts in POI sequence generation. It extends the gating mechanism of variants of RNN to incorporate multiple contexts for efficient POI sequence modeling, and (iii) it evaluates the generated sequences with various relevant metrics (e.g., pairs-F1 score, diversity, displacement (see Section 4.2 for detail)) on two real-world datasets.

Neural Network-based approaches
The Recurrent Neural Networks and its variants (e.g., Long Short-Term Memory (LSTM), Gated Recurrent Unit(GRU), etc.) were quite effective in sequence modeling problems (for instance speech recognition and machine translation) (Mikolov and Zweig (2012); Twardowski (2016); Sutskever et al. (2011)) that can exploit the dependencies between spatially correlated items (such as words in a sentence and pixels in images). Though some of the neural network-based models focused on predicting trajectories, they were more focused on collision avoidance between humans (Alahi et al. (2016)). The Social LSTM from Alahi et al. (2016) extended the approach from Graves (2013) by incorporating the spatial distance between neighbor objects and predicted the trajectory for human movement. The existing models were mainly focused on collision avoidance and ignored the constraints (such as user preferences and POI contexts) relevant to POI sequence generation.
Though RNNs were quite popular in sequence modeling for image and text, relatively fewer studies have exploited it for the recommendation domain. A recent study from Wu et al. (2017) used the Recurrent Recommender Networks (RRN) to predict future behavioral trajectories. They exploited LSTM (Hochreiter and Schmidhuber (1997)) based model to capture the user-movie preference dynamics, in addition to a more traditional low-rank factorization. Hidasi et al. (2015) trained a GRU (Cho et al. (2014))-based model with a ranking loss to predict the next item in the user session on e-commerce system. However, they did not consider personalization. A contextual network from Smirnova and Vasile (2017) used three different techniques (concatenation, multiplication, and both) to integrate the context embedding with the input embedding and was used for next item prediction. Though some of the neural network-based recommenders exist, none of them focused on multi-context personalized POI sequence modeling.

Methodology
In this section, we define our proposed approach. First, we define the basic concepts that are frequently used in the paper and then we elaborate the incorporation of contexts into RNN and its variants.
Context : A context of a check-in represents the current and previous scenarios which have direct or indirect influence on the selection of next POI. Such a context (for instance current time, category of current place, category of previous place, popularity score of current place, and so forth.) can be represented as a high-dimensional vector.
Context-aware POI sequence : Given a set of contexts C = {c i }, where i ∈ K, is a context type, our objective is to predict or generate a sequence of POIs, that are most relevant to the given context and match the user preferences.
Given a user u who has made n check-ins, we define her travel history as an ordered sequence, H u = (V 1 , V 2 , ..., V n ), where V i is a check-in activity and can be represented by the triplet V i = (l i , a i , d i ) indicating the location (l i ) of the check-in, arrival time (a i ) to l i , and the departure time (d i ) from l i respectively. The travel sequences can be split into small subsequences (for instance, the check-ins made within a time interval, e.g., 8 hours, one day, etc.). As in earlier studies (Lim et al. (2015); De Choudhury et al. (2010)), we use the time interval of 8 hours.
Visit duration of POI : The average visit duration (stay time (ST)) of a POI i is defined as: where U is the set of all users, V u,l is the set of visits made by the user u to location l, TT(a,b) is the travel time between POI a and POI b. We can use a log normal distribution to compute the travel time between two POIs visited consecutively. The stay time is 0-1 normalized and is represented as ST (i).
We define the user interest to a place in terms of aggregate of stay time (AST) to that place. This term in turn relies on the visit frequency and the stay time to that place, and the stay time to the places of same category.
u has some visits to location i, if ∃V u,l ∧ l.cat = i.cat, i.e., u has some check-ins on category i.cat , where V u is the set of visits by user u, V u,l is the set of visits by user u to location l, V u,l = |V u,l | |V u | is the normalized visit count of user u to location l, l.cat is the category of location l, and α is a constant tuning factor estimated using the fraction of check-ins that are of same category as location i . After incorporating social impact, the average stay time on a location i can be defined as: where F u represents the set of friends of user u, ψ 1 is a constant tuning parameter estimated using the fraction of check-ins of the user u that are common to her friends. Similarly, the average stay time by a user u to a location category 'cat' can be defined as: where γ 1 is a tuning factor estimated using the fraction of check-ins of user u that are common to her friends and have category 'cat'. AST cat is the aggregate of average stay on the category 'cat' from all users and AST t cat gives the measure for time t.
Preference score of POI : For a user u, the preference score (PS) of a place l at time t is defined using the following relation: if ∃V u,l ∧ l.cat = i.cat, i.e., u has some check-ins on category i.cat , where V u,l,t is the set of visits made by user u to location l at time t, L is the set of all locations, θ can be estimated as in Equation 2, and β is a tuning factor estimated using TF-IDF (term frequency inverse document frequency) (Salton and McGill (1986)). This relation addresses the trade-offs between visit frequency and stay time which is crucial to reward the preferred check-ins with low frequency but reasonable stay time. The generalized preference score P S(l, t) can be easily derived from above relation by considering the visit frequencies of all the users and stay time of all the users to this location at time t. Furthermore, the usage of categorical and the social contribution can handle the cold-start items (items with no check-ins information) and cold-start users (users with no check-ins) to some extent as the relations defined above incorporate some contributions from categorical and social factors. We also handle the scenario in which places with higher preference scores are compromised due to other constraints, such as travel time and cost. To address the trade-off between constraints and preference score, we define a consolidated preference score as: where Constraint i (l, p) is a normalized numeric measure of i th constraint between the users' current location p and the target location l. For instance, the spatial constraint is the measure of distance between locations p and l which is min-max normalized by the minimum and maximum distance traveled by any user to reach location l from any other location. The above mentioned preference metrics are used as features and attributes (defined later) when we train our prediction model.

Network Design
We exploit RNNs because they are ideal to our problem due to the following reasons: (i) the POI check-in patterns are relatively casual and vary across the users. Thus a long term dependency is required which can be modeled by RNNs (or its variants like GRU and LSTM), (ii) the check-in trends are associated with many contextual attributes, such as social, categorical, temporal, and spatial. The capability of RNNs to incorporate additional attributes (e.g., Mikolov et al. (2010); Mikolov and Zweig (2012)) is another reason behind selecting them.   Figure a shows the sequence modeling with general RNN where no contextual information is used in the hidden and output layers. Figure b shows the sequence modeling with extended RNN where the contextual information is explicitly fed to the hidden and output layer.

Preliminaries of proposed Network
RNNs are ideal for sequence modeling problem because they can efficiently model the generative process of sequential information, can summarize the information in hidden states, and can generate new sequences by using the probability distribution specified by the hidden states. The hidden state h t from the input sequence ( where U and V are weight matrices). The overall probability of a sequence − → x = x 1 , x 2 , ....., x N can be defined as: Training such a regular RNN by maximizing the above function suffers from vanishing gradient (i.e., a problem with gradient based learning methods where the gradient (error signal) decreases exponentially with the value of n (number of layers) while the front layers train very slowly, see Hochreiter (1998) for further detail). While the architectural enhancements, such as long short-term memory (LSTM) from Hochreiter and Schmidhuber (1997) and Gated Recurrent Unit (GRU) from Cho et al. (2014) are believed to address the vanishing gradient problem, the context enriched models (Mikolov et al. (2010); Mikolov and Zweig (2012)) are also claimed as an effective solution. We formulate the contextual POI sequence modeling by incorporating the contexts into RNN and its variants. The basic POI sequence modeling with regular RNN is illustrated in Figure 2(a). The proposed contextual POI sequence modeling is illustrated in Figure 2(b). The unraveled view of the contextual RNN (Figure 2(b)) is illustrated in Figure 3. The input vector and the output vector both have the dimension of the number of POIs. The input vector w(t) is the check-in at time t (which is a one hot encoding), and the output layer produces a probability distribution over the POIs, given the context, feature and the previous check-in. The hidden layers of RNNs are responsible to maintain the history of check-ins that form the sequence. Inspired from Mikolov and Zweig (2012), we extend the vanilla RNN to incorporate the context and feature inputs (f(t)). The context and the attribute of the current input, the current input itself, and the features representing the whole sequence are fed to the network. The features are propagated to the hidden as well as to the output layers. This helps us to retain the important features which the network will be aware at each and every iteration (see Figure 2(b)).

Basic POI Sequence Modeling
In this model, we use the regular RNN which is popular for modeling the sequential data. The capability of maintaining the session information into the recurrent states are often considered as its strength. Although they are theoretically claimed as poor candidates for problem with long session relations (due to vanishing gradient problem), architectural extensions (e.g., LSTM) or contextual extensions (e.g., Mikolov and Zweig (2012)) are some of the state-of-art techniques in language modeling domain.
With respect to POI sequence modeling, the RNNs can use the probability distribution specified by the hidden state to predict the next POI. The hidden state summarizes the information of the sequence observed so far (e.g., l 1 , l 2 , ...., l t−1 ). A hidden layer depends on the current input (x t ) and the input at previous step (h t−1 ), i.e. h t = f (W xh x t + W hh h t−1 ), where W xh and W hh are the weights for the current input, and for the value from previous hidden layer respectively. The probability of a POI sequence can then be defined using the chain rule: where T is the number of timesteps to be considered. The negative log likelihood is used as the sequence loss to train the network: For the defined network, the partial derivative of the loss can be computed using the backpropagation through time (Williams and Zipser (1995)) and the network can be trained using gradient descent. Such a sequence modeling is illustrated in Figure 2(a). This network predicts the next POI by learning from the previously fed POI sequences only and does not consider other information, such as POI attributes, current context, and other relevant features. The contextual model defined in next subsection addresses these aspects.

Contextual POI Sequence Modeling using RNN
This model is termed as CAPS-RNN and represents the contextual POI sequence modeling as illustrated in Figure 2(b) and Figure 3. CAPS-RNN extends the regular RNN by incorporating the context to hidden layers and the feature (f(t)) to the hidden and output layers. This extension has following major advantages: (i) as the regular RNNs have no provision of explicit context propagation and as the POI sequence modeling requires the contexts to be remembered for longer span, the extension helps us to propagate the relevant contexts to make sure that the next predicted subsequence adheres to the context, (ii) the regular RNNs suffer from vanishing gradient problem (i.e. during backpropagation, the gradients decrease exponentially with the value of n (number of layers) and the front layers train very slowly, see Hochreiter (1998) for further detail). The explicit feeding of contexts to the hidden layer and the features to hidden and output layers helps alleviate the gradients, meanwhile retaining the relevant context (see Mikolov and Zweig (2012) for detail).
The feature contains information that is relevant to the current input and also to the whole sequence, for instance with respect to POI sequence modeling, it can be the time budget constraint, start/end place categories, the geographical vicinity of interest, etc. These are the auxiliary information that can have significant impact on the prediction tasks. The context represents the aspect that is relevant to the current input (for instance, the current time, previous check-ins which impact the current check-in). In addition to context and feature, the attribute vector which represents any information that is relevant to the current item (for e.g., the locations' category, locations' hours, locations' popularity, locations' preference score, and locations' average stay time) is also incorporated to the network. For the sake of ease, the attribute and context vectors can be combined together.
After we train the network (using stochastic gradient descent), the output vector y(t) gives the probability measure of different POIs at time t, given the previous POI, context, and the feature vector. The hidden and output layers are updated using the following relations: where H(.) is a non-linear function (e.g., tanh), A(t) is the context attribute vector of current item for time t (see Eqn. 14), f(t) is the sequence feature vector (see Eqn. 13), and g(a i ) = exp(a i ) j exp(a j ) is the softmax function. The sequence feature vector contains the information relevant to the whole sequence. We use the feature vector of following format: f (t) =< cat start , cat end , loc start , loc end , loc dist , time start , time end >, where cat start is category of starting place, cat end is category of ending place, loc start is starting place, loc end is ending place, loc dist is the distance between consecutive places, time start is starting hour, and time end is ending hour of the POI sequence. All the non-numeric elements of this vector are label encoded before feeding to the network. The attribute vector contains the information relevant to the current item and current context. We use the following format for the attribute vector: A(l, t) =< ST (l), AST (l), AST t cat , P S(l), l.cat, l T , l dist >, where l T = l 1 , l 2 , ..., l T is the temporal popularity of location l for each hour, 'cat' =l.cat is category of location l, and l dist is the distance of location l from the previous location in the sequence. All the non-numeric elements of this vector are label encoded. The feature vector and the attribute vector can be used to incorporate additional features and attributes if required. The network is trained to learn the weight matrices (U, V, W, F, and G), and to maximize the likelihood of the training data (Mikolov (2012); Bengio et al. (2003)). The probability of a POI sequence l for the network can be defined as:

Contextual POI Sequence modeling using LSTM
This model is termed as CAPS-LSTM. The core idea behind LSTM is the introduction of memory state and multiple gating functions to control the write, read, and removal (forget) of the information written on memory state. The information is propagated by applying these gates to the input data and data from the previous memory states. We incorporate the explicit context to each LSTM cell because each cell models a subsequence and each subsequence can have potentially unique context. This explicit context to each LSTM cell and the feature of sequence to all LSTM cells help us propagate the relevant context for the sequence modeling. Due to space constraint, we only provide the update equations of our extended LSTM which incorporates the contextual information. The hidden layer of contextual LSTMs are updated using the following relations: where c t is the memory state, z t is the module that transforms information from input space x t to the memory space, and h t is the information read from the memory state. The input gate i t controls information from input z t to memory state, the forget gate f t controls information in the memory state to be forgotten, and the output gate o t controls information read from the memory state. The memory state c t is updated through a linear combination of input filtered by the input gate and the previous memory state filtered by the forget gate. The term W f is feature weight matrix, F is feature vector, A t is attribute vector as in the contextual RNN model, and is element-wise product operator. The relevant weight matrices W and biases b are subscripted accordingly.

Sequence generation
After the model is trained, it can generate the personalized POI sequences. The basic idea is to train the network using a sequence data one step at a time. The sampled output from the network is then fed as the input for the next level. If we have k different POIs, and k th POI is checked-in at time t, then the input x t is one-hot encoded vector with only the k th entry set to 1. The output of the network is a multinomial distribution which is parameterized using a softmax function and can be defined as: .
From the generated sequences, the top-k scorers (sum of preference scores (AS) of all places in a sequence) are recommended to user.

Evaluation
In this section, we describe the dataset, the evaluation baselines, evaluation metrics, and the experimental results.

Dataset
We used two real-world datasets collected from two popular LBSNs -Gowalla and Weeplaces (Liu et al. (2013)). These datasets were well defined and have the attributes relevant to the context of this paper, such as (i) the location category, (ii) geospatial co-ordinates, (iii) friendship information, and (iv) check-in time. The statistics of the dataset is summarized in   Grocery (884,557), and (iv) Gas & Automotive (863,199) for the Gowalla dataset. The work or home-related category (Home/Work/ Other:Corporate/Office) was popular from 6 am to 6 pm, with the highest check-ins (42,019) made at 1 pm. Similarly, the bars had highest of 21,806 check-ins at 2 am and the lowest check-ins (15,209) at 5 am. Most of the check-ins were at 12 pm -6 pm and were either in Home or Work related categories.
The check-in distribution of all users in the Weeplaces and Gowalla dataset is illustrated in Figure 1. Figure 8(a) and Figure 8(b) show that the frequency of daily check-ins is <50 for most of the users. This implies that most of the users have daily sequence length that is reasonable and exploiting the proposed model within this sequence length is enough to evaluate its performance. Among the many factors influencing the check-in trend of the users, distance measure is one of the major factors. Figure 5 illustrates the inverse relation between the distance of a location and likelihood of check-ins (i.e. most users preferred near places (≤1 K.m.)). This implies that most of the users prefer to visit near places and hence the POIs within a sequence should also be within a reasonable distance. The three days' check-in distribution of three users with most check-ins in Weeplaces dataset is illustrated in Figure 6. Three different color marks are used to distinguish the check-in of different days. The overlapping check-ins on different days are overlapped in the map and are not distinguishable. This figure also illustrates that most of the users prefer check-ins to near locations and most of the users have reasonably smaller sequence length.  Unlike other studies, we did not split the dataset into different cities because we found that most of the users have check-ins spanned across multiple cities and splitting the dataset into multiple cities can disrupt the coherence of the places the users have in the dataset. The check-ins were chronologically sorted and for every user, the check-ins were splitted into subsequence of every 8 hours.

Evaluation Metrics
It is difficult to measure the correctness of the order of items using simple precision, recall, and F-score. We use the pairs-F1 metrics defined in . It considers both the POI identity and its order by using the F1 score of every pair of POIs in a sequence and is defined as: where P P AIR and R P AIR are the precision and recall of the ordered POI pairs respectively. We also evaluate the diversity (Bradley and Smyth (2001)) of locations in the sequence. The diversity of locations is measured using their categorical similarity (i.e. Similarity =1 if two places are of same category and Similarity = 0 otherwise). We use the following relation to define the diversity of items in the list: We use the displacement metric to measures the distance (in K.m.) between the predicted POIs and the actual POIs in the sequence. It is defined as: where seq a and seq e are the actual and estimated sequences respectively.

Evaluation Baselines
We compared our proposed method with the following baseline models: 1. POI Popularity: This is a naive approach that relies on the popularity of POIs. For a given location, an area within a predefined radius is used to find the most popular POI (i.e. most visits in the locality) within that area which is not already included in the list. The radius is dynamically updated by a predefined factor when no location is found in the area. 2. Markov Chain-based approach: We use first order Markov Chain to generate the POI sequences. The Laplace smoothed state-transition matrix and initial probability matrix are derived from the check-in data and are personalized for each user. 3. Apriori-based approach: The most frequently checked-in place of a user is considered as the starting point because the model does not have provision of user inputs. From the starting point, we select the places that are within some threshold distance ( ) to get the candidate 1-sets. The candidate 1-sets are used to get the other candidate sets. All the candidates that do not satisfy the constraints are pruned. The constraint checking procedure and candidate generation procedure continues till the trip of desired length is obtained or the candidate sets are exhausted. Every trip that has greater than 8 hours travel time are pruned. Basically, we adapt a greedy pruning approach to get rid of the less preferred routes. Among the available candidate sets, we select the one that satisfies the following criteria: (i) has higher trip score, and (ii) has lower travel time (see Eqn 6). The trip score is calculated by adding the preference scores (see Eqn. 5 and Eqn. 6) of all the places in the trip. The top-k trips with highest scores are recommended to the user. Some of the existing studies (Lu et al. (2012); Yu et al. (2016)) have also exploited the Apriori-based approach. 4. HITS-based approach (Zheng and Xie (2011)): In this, the locations are hierarchically organized into clusters/regions and the hub scores of user and authority scores of places are generated relevant to the regions. This facilitates in modeling the popularity of locations and users within a region. The inference is made by using the adjacent matrix between users and locations with respect to the region. The score of a sequence is determined using the hub scores of users who visited the sequence, and the authority scores of places weighted by the probability that people would consider the sequence. The top k popular sequences are recommended.

Experimental settings
We used a 5-fold cross validation to measure the performance of the models. An Ubuntu 14.04.5 LTS, 32 GB RAM, a Quadcore Intel(R) Core(TM) i7-3820 CPU @ 3.60 GHz was used to evaluate the models. The same configuration with a Tesla K20c 6 GB GPU was used to evaluate the neural network based models. We used Python 3 as the programming platform, Numpy 4 as the mathematical computation library, Pandas 5 as data analysis library, and TensorFlow 6 as the neural network library. The users with less than 25 check-ins were ignored. The context and feature vector were estimated from the historical check-ins of the users. For each user, 7 most frequently checked-in places were taken as starting point, and 10 sequence per starting point was generated. The average metrics on these 10 sequences was observed. The POI-Popularity and Apriori models used distance threshold of 2 K.m. The contextual LSTM used 512 hidden states, and the contextual RNN used 5 layers and 256 nodes. The input sequence length was set to 25, the data was fed in batches of size 50, embedding vectors were of size 384, and the experiment was repeated for 100 epochs. The learning rate was set to 0.002, and the gradients were clipped at 5 to prevent overfitting.

Experimental Results and Discussions
The pair-wise precision, recall, and F-score of different models is illustrated in Table 2 and Table 3. The diversity and displacement-based performance is illustrated in Table 4 and Table 5.  The popularity-based model performed worst among all the models. It generated almost similar sequences for all the users and hence was not relevant to personalized preferences. This might be due to the ignorance of the personalized preferences of user. The diversity measure was also quite low, which means the POIs in the generated sequences included few categories. The high displacement metrics indicates that the predicted POIs were far from the actual ones.
The Apriori-based model had better performance than popularity-based model. Although the Apriori-based model pruned irrelevant candidate sequences, it also did not capture the personalization aspect. This might be the reason behind its low performance. The diversity and displacement measures were also better than the popularity-based model.    Table 5: Diversity and displacement performance (on sequence length of 25) of models in Gowalla dataset The first-order Markov model relied on one previous check-in data to determine next location and hence was not able to fully model the check-in sequence generation process. However, its pair-Fscore, diversity and displacement metrics were better than popularity-based and Apriori-based models which is due to the personalization implied from separate initial-probability and state-transition tables for each user.
The HITS-based model slightly outperformed Markov-based model on all three metrics. As it relies on segregation of places into regions and finding the authority and hub scores of the places and users within that regions, its performance depends on the region generation approach. We used a radius of 10 K.m. from a specified location to generate such regions. Its performance with the radius of 5 K.m. and 15 K.m. was in par with popularity-based model.
Though not sophisticated, the performance of vanilla RNN was in par with the HITS model. This might be because of its capability to retain information of previous items from the sequence. The regular LSTM performed slightly better than vanilla RNN due to its implicit ability to cope with vanishing gradient problem.
The CAPS-LSTM model was best performer in both dataset. Its performance was slightly better than CAPS-RNN in all the cases except the diversity metrics in Weeplaces dataset where CAPS-RNN was slightly better. The performance of CAPS-LSTM was significant in larger dataset (i.e. Gowalla). This is obvious because the Gowalla dataset is larger, and has more social (friendship) relations, which favored the neural networks that need lots of training data for better performance. We used the threshold of 6, 8, and 10 hours and found that the threshold of 8 hours performed better than others. This might however, vary on the dataset used. In terms of execution time, CAPS-LSTM was slower as it used multiple epochs and required lots of training time. The execution time of different models were in the order of: CAPS-LSTM ≥ CAPS-RNN > LSTM ≥ vanilla RNN > HITS > Apriori ≥ Markov > Popularity-based.
To summarize, the CAPS-LSTM performed best, followed by the CAPS-RNN in all three metrics. This evaluation result supports our claim that extension of RNN and it's variants by incorporating item-wise contexts and sequencewise features can be efficient for sequence modeling.    Figure 7 illustrates the trend of diversity changes with the increasing sequence length. The diversity metric measures the extent to which different categories are included in the recommendation. A good recommendation should include items with different category that satisfy the user preferences. We can see that the CAPS-RNN and CAPS-LSTM have better diversity trend with the increasing sequence length. It is most likely to have locations of different category when sequence length is increased. This effect is clearly reflected in all neural network-based models in both datasets. The popularity model always recommends popular items and does not focus on the diversity, hence its diversity is lowest of all the models. Although the Apriori, Markov, and HITS models perform better than popularity-based model, their performance is lower than that of the neural network-based models. The increase in diversity was quite slow as we increase the sequence length. This might be because of the fine grained categories which cover only few places and most of the broader categories cover many items and after some sequence length, the newly added places overlap with the category of places already in the sequence. Figure 8 illustrates the impact of sequence length on the displacement. As the popularity model recommends only the popular items no matter how far they are, it has highest displacement among all the models. The displacement is increasing with the increasing sequence length. The CAPS-RNN and CAPS-LSTM show similar effect of sequence length on the displacement. The other models have reasonable displacement until we reach the sequence of length 25. For all the models, the increase in displacement is sharp after sequence length of 25. This is also supported by the check-in trend presented in Figure 4 which shows that the daily check-in frequency of a user is ∼25 and as we increase the sequence length, the check-ins are most likely to be made on another day (which might be in another city or some place farther than the one checked-in on previous days). As the CAPS-RNN and CAPS-LSTM have better performance for subsequences, they have better performance over other models.

Case study on generated trajectories
In this section, we provide a case study on POI sequences generated by popularity-based approach and CAPS-LSTM on Gowalla dataset. We select sequences of length 5 for two different users 'thadd-fiala', 'boon-yap' (known as u 1 , u 2 in rest of the paper) with most check-ins and analyze the relevance of the sequences for them. For u 1 , a sequence of length 5 from popularity model is {'sycamore-place-lofts-cincinnati', 'pg-gardens-cincinnati', 'lytle-parkcincinnati', 'piatt-park-cincinnati', 'sycamore-place-at-st-xavier-park-apartments-cincin'}, and their respective categories are {'Home/Work/Other:Home', 'Parks & Outdoors:Plaza / Square', 'Parks & Outdoors:Park', 'Parks & Outdoors:Plaza / Square', 'Home/Work/Other:Home'}. Similarly for user u 2 a length 5 sequence is {'starbucks-boston', 'mbta-south-station-boston', 'boston-common-boston', 'dunkin-donuts-boston', 'mbta-park-street-station-boston'}and their respective categories are {'Food:Coffee Shop', 'Travel:Train Station', 'Parks & Outdoors:Park', 'Food:Donuts', 'Travel:Train Station'}. Most of the places recommended are the popular ones and the generated sequences have less diversity. For both users, there are three different categories in the generated sequences. With the increasing sequence length, the diversity shows some increasing trend (see Figure 7) but this is lower in both datasets.
With the popularity-based model, the average displacement of above sequence was 19.36 K.M. for user u 1 and it was 20.03 K.M. for user u 2 . With the CAPS-LSTM, the average displacement of above sequence was 5.02 K.M for user u 1 and it was 5.61 K.M. for user u 2 . This shows that CAPS-LSTM addresses the distance constraint better for both users. With the increasing sequence length, the displacement trend increased for both models and followed the trend as shown in Figure 8.
Limitations The deep models need lots of training data and the valid check-in sequences (the sequences that have minimum number of check-ins) that we used might still be insufficient to exploit the full potential of the proposed model. As the model needs to be trained offline, the model in its current state might not be efficient for real-time prediction. The threshold of 8 hours might not be equally applicable for all users, all types of trips, and might vary across different datasets.

Conclusion and Future Work
We formulated the contextual personalized POI sequence modeling problem by extending the recurrent neural networks and its variants. We incorporated different contexts (such as social, temporal, categorical, and spatial) by feeding them to the hidden layer and the output layer. We propagated the feature vector to all the layers of the network and retained the contextual information that was valid throughout the sequence. We evaluated the proposed model with two realworld datasets and demonstrated that the contextual models can perform better than regular models. The proposed model performed slightly better with larger datasets. There are many interesting directions to explore. We would like to incorporate the textual attributes (e.g., tags, tips, and review text) and also visual information (e.g., image of places) to define the preference of users and popularity of places. We would also like to explore other datasets for sequence modeling.