Recurrent Flow Networks: A Recurrent Latent Variable Model for Density Modelling of Urban Mobility
Abstract
Mobility-on-demand (MoD) systems represent a rapidly developing mode of transportation wherein travel requests are dynamically handled by a coordinated ﬂeet of vehicles.
Crucially, the efﬁciency of an MoD system highly depends on how well supply and demand distributions are aligned in spatio-temporal space (i.e., to satisfy user demand, cars have to be available in the correct place and at the desired time).
When modelling urban mobility as temporal sequences, current approaches typically rely on either (i) a spatial discretization (e.g. ConvLSTMs), or (ii) a
Gaussian mixture model to describe the conditional output distribution.
In this paper, we argue that both of these approaches could exhibit structural limitations when faced with highly complex data distributions such as for urban mobility densities.
To address this issue, we introduce recurrent ﬂow networks which combine deterministic and stochastic recurrent hidden states with conditional normalizing ﬂows and show how the added ﬂexibility allows our model to generate distributions matching potentially complex urban topologies.
1. Introduction
With the growing prevalence of smart mobile phones in our daily lives, companies such as Uber, Lyft, and DiDi have been pioneering Mobility-on-Demand (MoD) and online ride-hailing platforms as a solution capable of providing a more efﬁcient and personalized transportation service.
Notably, an efﬁcient MoD system could allow for reduced idle times and higher fulﬁllment rates, thus offering a better user experience for both driver and passenger groups.
The efﬁciency of an MoD system highly depends on the ability to model and accurately forecast the need for transportation, such to enable service providers to take operational deci- and Explicit Likelihood Models (ICML 2021). Copyright
(s). sions in strong accordance with user needs and preferences. However, the complexity of the geo-spatial distributions characterizing MoD demand requires ﬂexible models that can capture rich, time-dependent 2d patterns and adapt to complex urban geographies (e.g. presence of rivers, irregular landforms, etc.).
Historically, dynamic Bayesian networks (DBNs), such as hidden Markov models (HMMs) and state space models (SSMs) (Durbin & Koopman, 2001), have characterized a unifying probabilistic framework with illustrious successes in modelling time-dependent dynamics.
Advances in deep learning architectures however, shifted this supremacy towards the ﬁeld of Recurrent Neural Networks (RNNs).
At a high level, both DBNs and RNNs can be framed as parametrizations of two core components: 1) a transition function characterizing the time-dependent evolution of a learned internal representation, and 2) an emission function denoting a mapping from representation space to observation space.
Recently, evidence has been gathered in favor of combinations bringing together the representative power of
RNNs with the consistent handling of uncertainties given by probabilistic approaches (Chung et al., 2015; Fraccaro et al., 2016; Krishnan et al., 2016; Karl et al., 2017).
The core concept underlying recent developments is the idea that, in current RNNs, the only source of variability is found in the conditional emission distribution (i.e. typically a unimodal distribution or a mixture of unimodal distributions).
Most efforts have therefore concentrated in building models capable of effectively propagating uncertainty in the transition function of RNNs.
In this paper, we build on these recent advances by shifting the focus towards more ﬂexible emission functions.
We suggest that the traditional treatment of output variability through the parametrization of either (i) unimodal (or mixtures of unimodal) distributions, or (ii) discretized representations of naturally-continuous distributions, may act as a bottleneck in cases characterized by complex data distributions, such as the ones observed in urban mobility.
We propose the use of Conditional Normalizing Flows (CNFs)
(Winkler et al., 2020) as a general approach to deﬁne arbitrarily expressive output probability distributions under temporal dynamics.
On one hand, we model the temporal variability in the data through a transition function combining stochastic and deterministic states, on the other, we u t h t z t x t b t h t −z t −(a) Transition u t h t z t x t b t h t −z t −(b) Emission u t h t z t x t b t h t −z t −(c) Inference u t h t z t x t b t h t −z t −(d) Overall propose to use this mixed hidden representation as a conditioning variable to capture the output variability with a CNF.
We call this model a Recurrent Flow Network (RFN).
To summarize, the main contributions of this paper are twofold: ﬁrst, we propose a probabilistic neural generative model which is able to combine deterministic and stochastic temporal representations with the ﬂexibility of normalizing ﬂows in the conditional output distribution.
Second, we showcase how our model is able to represent ﬁne-grained urban mobility patterns on several real-world tasks, which could drastically impact downstream decision making processes in current mobility systems.
2. Recurrent Flow Networks
In this section, we deﬁne the generative model p θ and inference network q φ characterizing the RFN for the purpose of sequence modelling 1 .
RFNs explicitly model temporal dependencies by combining deterministic and stochastic layers.
The resulting intractability of the posterior distribution over the latent states z 1: T , as in the case of VAEs (Kingma &
Welling, 2014; Rezende et al., 2014), is further approached by learning a tractable approximation through amortized variational inference .
The schematic view of the RFN is shown in Fig 1.
Generative model
As in the case of the SRNN (Fraccaro et al., 2016), the transition function of the RFN interlocks an SSM with an RNN:
[Equation]
with [ µ 0 ,t , σ 0 ,t ] =
f θ z ( z t − 1 , h t ) , where µ 0 ,t and σ 0 ,t represent the parameters of the conditional prior distribution over the stochastic hidden states z 1: T .
In our implementation, f θ h and f θ z are respectively an
LSTM cell and a deep feed-forward neural network, with parameters θ h and θ z .
In Eq.
(1), ϕ extr τ can also be a neural network extracting features from u t .
Unlike the SRNN, the learned representations (i.e. z 1: T , h 1: T ) are used as conditioners for a CNF parametrizing the output distribution.
That is, for every time-step t , we learn a complex distribution p ( x t | z t , h t ) by deﬁning the conditional base distribution p ( b t | z t , h t ) and conditional coupling layers (Dinh et al., 2017) for the transformation T ψ as follows:
Conditional Prior:
[Equation]
3) with [ µ b,t , σ b,t ] = f ψ [Equation] z t , h
[Equation]
Conditional Coupling:
[Equation]
In Eq. 4 we assume vectors x and b to be D -dimensional vectors with d < D .
In our implementation, f ψ , s ψ and t ψ are parametrized by deep neural networks.
Together, Eq.
(3) and Eq.
(4) deﬁne the emission function, enabling the generative model to result in the factorization p ( x , z , h ) = (cid:81) [Equation]
x
[Equation]
) , where the emission and transition distributions have parameters θ x , θ z , θ h , and where we assume that h t follows a delta distribution centered in h t = f θ h ( h t − 1 , u t ) .
Inference
The variational approximation deﬁning the
RFN directly depends on z t − 1 , h t and x t as follows:
[Equation]
where ϕ enc τ is an encoder network deﬁning the parameters of the approximate posterior distribution µ z,t and σ z,t .
Given the above structure, the generative and inference models are tied through the RNN hidden state h t , resulting in the factorization given by:
[Equation]
In addition to the explicit dependence of the approximate posterior on x t and h t , the inference network deﬁned in Eq.
(5) also exhibits an implicit dependence on x 1: t and h 1: t through z t − 1 .
This implicit dependency on all information from the past can be considered as resembling a ﬁltering approach from the state-space model literature (Durbin &
Koopman, 2001).
Denoting θ and φ as the set of model and variational parameters respectively, variational inference offers a scheme for jointly optimizing parameters θ and computing an approximation to the posterior distribution by maximizing the evidence lower bound 2 (i.e. ELBO).
3. Experiments
Concretely, we evaluate the proposed RFN on three transportation datasets:
NYC Taxi (NYC-P/D) :
This dataset is released by the New
York City Taxi and Limousine Commission.
We focused on aggregating the taxi demand in 2-hour bins for the month of
March 2016 containing 249,637 trip geo-coordinates.
We further differentiated the task of modelling pick-ups (i.e. where the demand is) and drop-offs (i.e. where people want to go).
In what follows, we denote the two datasets as
NYC-P and NYC-D respectively.
Copenhagen Bike-Share (CPH-BS) :
This dataset contains geo-coordinates from users accessing the smartphone app of Donkey Republic, one of the major bike sharing services in Copenhagen, Denmark.
As for the case of New York, we aggregated the geo-coordinates in 2-hour bins for the month of August, resulting in 87,740 app accesses.
Models
We compare the proposed RFN against various baselines assuming both continuous and discrete support for the output distribution.
In particular, in the continuous case (i.e. where we assume to be modelling a 2-dimensional distribution directly in longitude-latitude space), we consider RNN, VRNN (Chung et al., 2015) and SRNN (Fraccaro et al., 2016) models each using two different emission distributions based on Mixture Density Networks (MDN), as in (Bishop, 1994).
That is, we compare against a GMM output parametrized by Gaussians with either diagonal (MDNDiag) or full (MDN-Full) covariance matrix.
On the other hand, when assuming discrete support for the output distribution (i.e. we divide the map into tiled non-overlapping patches and view the pixels inside a patch as its measurements), we consider Convolutional LSTM (ConvLSTM), (Shi et al., 2015) which leverage the spatial information en- [Table] coded on the sequences by substituting the matrix operations in the standard LSTM formulation with convolutions.
Results
One-step Prediction :
In Table 1 we compare test log-likelihoods on the tasks of continuous spatio-temporal demand modelling for the cases of New York and Copenhagen.
We report exact log-likelihoods for both RNN-MDNDiag and RNN-MDN-Full, while in the case of VRNNs,
SRNNs and RFNs we report the importance sampling approximation to the marginal log-likelihood using 30 samples, as in (Rezende et al., 2014).
We see from Table 1 that
RFN outperformes competing methods yielding higher loglikelihood across all tasks.
The results support our claim that more ﬂexible output distributions are advantageous when modelling potentially complex and structured temporal data distributions.
To further illustrate this, in Fig.
2, we show a visualization of the predicted spatial densities (one-stepahead) from three of the implemented models at speciﬁc times of the day.
Opposed to GMM-based densities, the ﬁgures show how the RFN exploits the ﬂexibility of conditional normalizing ﬂows to generate sharper distributions capable of better approximating complex shapes such as geographical landforms or urban topologies (e.g. Central
Park or the sharper edges in proximity of the Hudson river along the west side of Manhattan).
Multi-step Prediction : In order to take reliable strategic decisions, service providers might also be interested in obtaining full roll-outs of demand predictions, opposed to 1-step predictions.
To do so, we generate entire sequences in an autoregressive way (i.e., the prediction at timestep t is fed back into the model at t + 1 ) and analyze the ability of the proposed model to unroll for different forecasting horizons.
From a methodological point of view, we are interested in measuring the effect of explicitly modelling the stochasticity in the temporal evolution of demand opposed to fully-deterministic architectures.
To this regard, in Table 2 we compare the RFN with the most competitive deterministic benchmark (i.e. RNN-MDN-Full).
As the results suggest, the stochasticity in the transition probability allows the RFN to better capture the temporal dynamics, thus resulting in lower performance decay in comparison with the [Table] [Figure] fully deterministic RNN-MDN assuming full covariance.
Quantization :
As a further analysis, we compare the proposed RFN with a Convolutional LSTM, under the assumption that the spatial map has been discretized in a 64 ×pixel space described by a Categorical distribution.
This comparison is particularly relevant given the prevalence of ConvLSTMs in spatio-temporal travel modelling applications (Petersen et al., [-
 ;-]2019; Yuan et al., 2018; Wang et al., 2018).
As previously introduced, the RFN is naturally deﬁned by a continuous output distribution (in practice parametrized as a normalizing ﬂow), thus, in order to characterize a valid comparison, we apply a quantization procedure to obtain a discrete output distribution for the
RFN.
In particular, the implemented quantization procedure can be summarized with the following steps: (i) as in the continuous case, evaluate the approximated marginal loglikelihood under the trained RFN at the pixel-centers of a 64 × 64 grid, (ii) normalize the computed log-likelihood logits through the use of a softmax function and (iii) evaluate the log-likelihood under a Categorical distribution characterized by the probabilities computed in (ii), thus having values comparable with the output of the ConvLSTM.
Table 3 compares test log-likelihoods on the task of discrete spatio-temporal demand modelling.
To this regard, when considering results in Table 3, two relevant observations must be underlined.
First of all, the true output of the RFN (i.e. before quantization) is a continuous density, thus, its discretization will, by deﬁnition, result in a loss of information and granularity.
Secondly, and most importantly, the quantization is applied as post-processing evaluation step, thus, opposed to the implemented ConvLSTMs, the RFNs are not directly optimizing for the objective evaluated in
Table 3.
In light of this, the results under the discretized space assumption support even more our claims on the effectiveness of the RFN to approximate spatially complex [Table]
distributions. Moreover, the ability of the RFN to model a continuous spatial density, opposed to a discretized approach as in the case of ConvLSTMs, has several theoretical and practical advantages.
For instance, RFNs are be able to evaluate the log-likelihood of individual data points for anomaly and hotspot detection.
Secondly, ConvLSTMs deﬁne a discretized space whose cells might have different natural landscape characteristics (e.g. rivers, lakes), thus effectively changing the dimension of the support in each bin and making comparisons of log-likelihoods across pixels an ill-posed question.
Furthermore, if for discrete output distributions exploring different levels of discretization would require to repeatedly train independent ConvLSTM networks, the post-processing quantization of the RFN allows discretization to be done instantaneously, thus enabling for fast prototyping and exploration of discretization levels.
4. Related Work
A number of works have concentrated in deﬁning more ﬂexible emission functions for sequential models (Rasul et al., 2021;
Kumar et al., 2020; Castrejon et al., 2019).
Within this line of research, normalizing ﬂows are used to either parametrize the emission function for the tasks of video generation and multi-variate time series forecasting (Castrejon et al., 2019;
Rasul et al., 2021), or to describe the latent states representing the temporal evolution of the system (Kumar et al., 2020).
However, to the author’s best knowledge, there is no track of previous attempts for the task of urban mobility modelling.
Within the transportation domain, traditional approaches rely on spatial discretizations of the urban topology(Yuan et al., 2018; Petersen et al., 2019; Wang et al., 2018), which allow for the prediction of spatio-temporal sequences with discrete support through e.g. ConvLSTMs (Shi et al., 2015).
5. Conclusions
This work addresses the problem of continuous spatiotemporal density modelling by proposing the use of conditional normalizing ﬂows as a general approach to parametrize the output distribution of recurrent latent variable models.
Our experiments focus on real-world data for the task of urban mobility density modelling.
We empirically show that the ﬂexibility of normalizing ﬂows enables
RFNs to generate rich output distributions capable of describing potentially complex geographical surfaces under both continuous and discrete output distribution assumptions.
Ultimately, we believe that the ability to estimate ﬁne-grained distributions of urban mobility represents an important step towards user-tailored MoD services.
A. Appendix A.1. Training
We train each model using stochastic gradient ascent on the evidence lower bound L ( θ, φ ) deﬁned in Eq.
(7) using the
Adam optimizer (Kingma & Ba, 2015), with a starting learning rate of 0 .
003 being reduced by a factor of 0 .
1 everyepochs without loss improvement (in our implementation, we used the ReduceLROnPlateau scheduler in PyTorch with patience=100).
As in (Sønderby et al., 2016), we found that annealing the KL term in Eq.
(7) (using a scalar multiplier linearly increasing from 0 to 1 over the course of training) yielded better results.
The ﬁnal model was selected with an early-stopping procedure based on the validation performance.
Training using a NVIDIA GeForce RTX 2080 Ti took around 6 hours for CPH-BS and around 9 hours for NYC-P/D.
A.2. Benchmarks
For every model considered under the continuous support assumption, we select a single layer of 128 LSTM cells.
The feature extractor ϕ extr τ in Eq.
(1) has three layers of 128 hidden units using rectiﬁed linear activations (Nair & Hinton, 2010).
For the VRNN, SRNN and RFN we also deﬁne a 128-dimensional latent state z 1: T .
Both the transition function t θ z from
Eq.
(2) and the inference network ϕ enc τ in Eq.
(5) use a single layer of 128 hidden units.
For the mixture-based models, the MDN emission is further deﬁned by two layers of 64 hidden units where we use a softplus activation to ensure the positivity of the variance vector in the MDN-Diag case and a Cholesky decomposition of the full covariance matrix in
MDN-Full.
Based on a random search, we use 50 and 30 mixtures for MDN-Diag and MDN-Full respectively.
The emission function in the RFN is deﬁned as in Eq.
(3) and Eq.
(4), where f ψ , s ψ and t ψ are neural networks with two layers ofhidden units.
The conditional ﬂow is further deﬁned as an alternation of 35 layers of the triplet [Afﬁne coupling layer, Batch
Normalization (Ioffe & Szegedy, 2015), Permutation], where the permutation ensures that all dimensions are processed by the afﬁne coupling layers and where the batch normalization ensures better propagation of the training signal, as shown in (Dinh et al., 2017).
In our experiments we deﬁne u t = x
t − 1 , although u t could potentially be used to introduce relevant information for the problem at hand (e.g. weather or special event data in the case of spatio-temporal transportation demand estimation).
On the other hand, under the discrete support assumption, we train a 5-layer ConvLSTM network with 4 layers containinghidden states and 3 × 3 kernels (in alternation with 4 batch normalization layers) using zero-padding to ensure preservation of tensor dimensions, a 3 D Convolution layer with kernel 3 × 3 × 3 and softmax activation function to describe a normalized density over the next frame (i.e. time-step) in the sequence.
All models assuming continuous output distribution were implemented using PyTorch (Paszke et al., 2017) and the universal probabilistic programming language Pyro (Bingham et al., 2018), while the ConvLSTMs where implemented using
Tensorﬂow (Abadi et al., 2015).
To reduce computational cost, we use a single sample to approximate the intractable expectations in the ELBO.
For both New York and Copenhagen experiments we process the data so to discard corrupted geo-coordinates outside the area of interest.
For the taxi experiments, we discarded coordinates related to trips either shorter than 30 s or longer than 3 h , while in the bike-sharing dataset, we ensured to keep only one app access from the same user in a window of 5 minutes.
In both cases we divide the data temporally into train/validation/test splits using a ratio of 0 .
A.3. ELBO derivation
[Equation]