Skip to main content
Have a personal or library account? Click to login
LASPATED: A Library for the Analysis of Spatio-Temporal Discrete Data Cover

LASPATED: A Library for the Analysis of Spatio-Temporal Discrete Data

Open Access
|Jul 2026

Full Article

(1) Overview

Introduction

In many applications, one has data of events that occur at points in space and time, and one wants to use the data to estimate spatio-temporal statistical models of the occurrence of such events. Examples of such spatio-temporal events are medical emergencies such as cardiac arrests, crimes such as robberies, earthquakes, weather events such as tornadoes, vehicles accidents, and fires. In these applications, one would like to use data to fit a function such as f:S×[0,T]R, where S is a bounded subset of Rn. Often, the domain S is called “space” and the domain [0,T] is called “time”. For example, S may represent locations on a 2-dimensional map (in which case n=2), or locations in a 3-dimensional space (in which case n=3), or origin-destination pairs on a map (in which case n=4), and [0,T] may represent time of the day (in which case T=24 hours), or time of the week (in which case T=168 hours). In this paper, we describe an open source software that uses spatio-temporal data to estimate a variety of statistical models that describe the spatio-temporal intensity f(x,t) of events of interest. We illustrate the use of the models and software using real data of medical emergencies.

A widely used nonparametric approach for fitting such a function f with data is to discretize space and time in a way that may depend on the data, and to fit a function from a chosen class on each discrete subset of the domain. There are many ways to construct such a discretization. Also, there are benefits to allowing the discretization to depend on the data. For example, a finer discretization may be chosen in regions of space and time with a higher concentration of data. There are also many function classes that can be used on each discrete subset of the domain. For example, the fitted function may be piecewise constant or piecewise linear, that is, it may be constant or linear on each discrete subset of the domain. Furthermore, sometimes one has data of covariates on the same space-time domain, with the covariates being correlated with the dependent variable. Even if the main purpose of the study is not to model the relation between the dependent variable and the covariates, these covariate data can be used in various ways to improve the estimates. For example, the covariates can be used in the choice of discretization by choosing the subsets of the discretization to be uniform in terms of the covariate values. The covariates can also be used as independent variables in a fitted parametric or semiparametric model. The covariates can also be used to regularize the model estimates, especially when the data are sparse.

Software tools for managing the choice of discretization, the regularization, and the model estimation, can be of great use. This paper describes such software tools for function estimation with spatio- temporal data.

Related Literature and Software

Spatio-temporal point processes consisting of data with a location and a timestamp arise in many applications such as the epicenters of earthquakes (1, 2), sudden crimes such as robberies and assaults (3), epidemiology (4, 5), and medical emergencies (6). For the theory of point processes, see (7, 8). (9, 10, 11, 12, 13, 14) provide overviews of statistical models and estimation for spatial and spatio-temporal point processes. (15) and (16) describe the use of R for processing spatial and spatio-temporal data and for model estimation. (17) describes the R package spacetime for converting spatio-temporal data among different formats, aggregating spatio-temporal data, and creating various types of plots.

The references above consider two types of models of the intensity function λ:XR+ of a nonhomogeneous spatial or spatio-temporal Poisson process. One type of model is a nonparametric model such as the following. Let {xn}n=1NX denote the observed points. A kernel function κ:R+R+, and a smoothing parameter h>0 is chosen. Then the intensity model is given by

1
λ(x)=1h2n=1Nκ(xxnh).

One challenge is that the effort to compute λ(x) for a given x increases in the size N of the dataset. Another challenge is to select a good value for the smoothing parameter h. Several software packages make provision for the estimation of such kernel-based intensity models, including splancs (18) and spatstat (19). In contrast, LASPATED makes provision for the estimation of nonparametric models based on discretization of X. For example, let {Xi}i=1I denote a partition of X. Then the intensity model is given by

2
λ(x)=i=1I𝟙{xXi}λi

where λi, i=1,,I, is estimated with data. LASPATED facilitates both the discretization as well as the parameter estimation.

Another type of model is a parametric model such as the following. Let zk:XR, k=1,,K, denote a chosen collection of covariate functions, and let βk, k=1,,K, denote corresponding parameters to be estimated. Then the intensity model is given by

3
λ(x)=exp(k=1Kβkzk(x)).

An advantage of the exp() on the right side is that λ(x)>0 for all β and all x. A disadvantage is that exp() grows much faster when its argument is large than when its argument is small, which often results in poor fit and numerical instability. In contrast, LASPATED makes provision for the estimation of constrained parametric models such as

4
λ(x)=k=1Kβkzk(x)subject toβkzk(x)> 0xX

where typically z(X) is bounded. Several software packages make provision for the estimation of parametric intensity models of the form (3), including spatstat (19) and NHPoisson (20). More specifically, NHPoisson is an R package for the estimation and testing of parametric intensity functions of the form λ(t)=exp(βz(t)) in one dimension, say time t. It is assumed that the covariate values are piecewise constant over integer intervals, that is, z(t) is constant for all t(k,k+1] for integers k. NHPoisson can use two optimization routines, optim and nlminb, to compute the maximum likelihood estimates β^ of β. NHPoisson also computes the inverse of the negative of the Hessian of the log-likelihood function as an asymptotic estimate of the covariance matrix of β^. NHPoisson computes the residuals and correlation metrics such as the Pearson correlation coefficient, and performs distribution tests such as the Kolmogorov-Smirnov test. (20) also specifically consider Poisson process approximations of peak over threshold models.

(21) proposed hybrid point process models with densities given by the normalized product of densities of a number of point processes, and described the use of spatstat for statistical inference for the hybrid models.

(22) describes the ppstat-package for analyzing data from multivariate point processes in time or one-dimensional space based on a specification of the conditional intensity process.

Application

Next, we describe the application that motivated the development of these software tools, and we demonstrate the use of these tools for the application. Phone calls about medical emergencies arrive at an emergency medical service (EMS) call center. Each emergency is characterized by a type, a location, and the arrival time of the call. The type of emergency is determined by the classification system used by the EMS, such as the Medical Priority Dispatch System (MPDS) or the Association of Public-Safety Communications Officials (APCO) system. Typical classification systems classify emergencies by the anatomical region (e.g., chest) affected, the cause of the emergency (e.g., animal bites), the importance of response time (e.g., “hot” versus “cold”), and the level of emergency service needed (e.g., basic life support versus advanced life support). The location is typically specified by an address, but can be converted to a latitude-longitude coordinate. The arrival time of the call is specified by a date-time combination.

We would like to estimate the arrival rate of emergencies as a function of emergency type, location, and time. Such an arrival rate function can be used to optimize the types and number of ambulances needed, the types and number of crew members needed, the crew schedules, and the positioning and dispatch of ambulances, and to develop a simulation of the emergency response system. We consider methods that discretize space and time and then estimate the arrival rate as a function of discrete space and time. While working on such a project (see 23, 24), we identified the lack of easy-to-use tools for this type of statistical work. Thus, the LASPATED library was created as a general tool to fill this gap. Then LASPATED was used with data of medical emergencies reported to the Rio de Janeiro EMS to fit arrival intensity functions. The data included the date and time of the phone call, the location of the emergency, and the type of the emergency. The emergency type data included a “priority level”: high, intermediate, and low-priority emergencies.

Different models of arrival intensity λc,i,t as a function of emergency type c, location i, and time t, were calibrated. The models were periodic with a period of one week. The time of the week was discretized into time intervals of length 30 minutes (thus the model had T=7×48 time intervals). Three different space discretizations are demonstrated:

  • A 10×10 space discretization of a rectangle containing the city of Rio de Janeiro, shown in Figure 1 (76 of these rectangles have nonempty intersection with the city and are shown in the figure);

  • A hexagonal discretization of the city of Rio de Janeiro (obtained with scale parameter 7, with 297 hexagons intersecting Rio de Janeiro) shown in Figure 2;

  • A discretization by administrative districts of the city of Rio de Janeiro (with 160 subregions), shown in Figure 3.

Figure 1

Space discretization of a region containing the city of Rio de Janeiro into 10×10=100 rectangles, 76 of which have nonempty intersection with the region and are shown in the figure.

Figure 2

Space discretization of a region containing the city of Rio de Janeiro into hexagons using the Uber library H3 with scale parameter equal to 7.

Figure 3

Space discretization of a region containing the city of Rio de Janeiro into 160 administrative districts.

For each space discretization, the model without covariates described in Section 2.1 (called Model M1 in what follows), and the model with covariates described in Section 2.2 (called Model M2 in what follows), were calibrated with LASPATED. For Model M2, we used the following four covariates: (a) the population of the zone, (b) the land area of commercial activities and public facilities in the zone, (c) the land area of industrial activities in the zone, and (d) the non-populated land area (such as forests, beaches, and water) in the zone. For the calibration of Model M1, we used regularization (see Section 2.1) with regularization parameter wi,t=w if zones i and j are neighbors, that is, if zones i and j share an edge or a vertex, and wi,t=0 otherwise. The best value for w was selected from {0,0.01,0.02,0.03,0.04,0.05} using cross validation. We did not regularize by time groups. The optimization problems for calibration were solved using the projected gradient method with Armijo line search along a feasible direction (see Section 2.3).

Figure 4 shows the aggregated estimated intensities using the 10×10 rectangular discretization. More specifically, the top left plot of Figure 4 shows cCiIλ^c,i,t as a function of t, the top right plot of Figure 4 shows iIλ^c2,i,t where c2 denotes the high-priority emergencies, the bottom left plot of Figure 4 shows iIλ^c1,i,t where c1 denotes the intermediate priority emergencies, and the bottom right plot of Figure 4 shows iIλ^c0,i,t where c0 denotes the low-priority emergencies. The intensity estimates shown in this figure are obtained with (i) the empirical mean number of calls for each call type, zone, and time interval, (ii) Model M1 with the 10×10 rectangular space discretization, and (iv) Model M2 with the 10×10 rectangular space discretization. In this example, all estimators give similar estimates of the aggregated intensities.

Figure 4

Aggregated estimates of the intensities for 3 estimators: (i) Empirical: the empirical intensities, (ii) Rectangular 10×10: Model M1 with the 10×10 rectangular space discretization, and (iii) Covariates, rectangular 10×10: Model M2 with the 10×10 rectangular space discretization. Top left: emergencies of all priorities, top right: high-priority emergencies, bottom left: intermediate priority emergencies, bottom right: low-priority emergencies.

Figure 5 shows the aggregated estimated intensities using hexagonal discretization with scale parameter 7. The top left plot of Figure 5 shows cCiIλ^c,i,t, the top right plot of Figure 5 shows iIλ^c2,i,t, the bottom left plot of Figure 5 shows iIλ^c1,i,t, and the bottom right plot of Figure 5 shows iIλ^c0,i,t. The intensity estimates shown in this figure are obtained with (i) the empirical mean number of calls for each call type, zone, and time interval, (ii) Model M1 with hexagonal discretization with scale parameter 7, and (iii) Model M2 with hexagonal discretization with scale parameter 7.

Figure 5

Aggregated estimates of the intensities for 3 estimators: (i) Empirical: the empirical intensities, (ii) Hexagonal 7: Model M1 with hexagonal discretization with scale parameter 7, and (iii) Covariates, hexagonal 7: Model M2 with hexagonal discretization with scale parameter 7. Top left: emergencies of all priorities, top right: high-priority emergencies, bottom left: intermediate priority emergencies, bottom right: low-priority emergencies.

Figure 6 shows the aggregated estimated intensities using discretization by district. The top left plot of Figure 6 shows cCiIλ^c,i,t, the top right plot of Figure 6 shows iIλ^c2,i,t, the bottom left plot of Figure 6 shows iIλ^c1,i,t, and the bottom right plot of Figure 6 shows iIλ^c0,i,t. The intensity estimates shown in this figure are obtained with (i) the empirical number of calls for each call type, zone, and time interval, (ii) Model M1 with the space discretization by districts, and (iii) Model M2 with the space discretization by districts.

Figure 6

Aggregated estimates of the intensities for 3 estimators: (i) Empirical: the empirical intensities, (ii) District: Model M1 with the space discretization by districts, (iii) Covariates, district: Model M2 with the space discretization by districts. Top left: emergencies of all priorities, top right: high-priority emergencies, bottom left: intermediate priority emergencies, bottom right: low-priority emergencies.

Overview of the LASPATED Library

Various discretization methods to partition space and time were implemented in LASPATED, summarized next. LASPATED provides four types of space discretization: in rectangles, in hexagons, based on the Voronoi diagram/Dirichlet tessellation for a set of points in S, and customized discretizations. LASPATED also provides functions to combine information from two different space discretizations, such as functions to calculate the areas of intersection of pairs of subregions from two discretizations, or to calculate location data such as population in the intersection of pairs of subregions from two discretizations.

LASPATED also provides various types of time discretization. For example, a simple partitioning of time could be a partition of the week in time intervals of 1 hour each. Then the corresponding time intervals are

{Monday [0:00,1:00),Monday [1:00,2:00),Monday [2:00,3:00),,Sunday [23:00,24:00)}.

Time intervals of different types can also be distinguished. For example, there could be different time intervals such as Monday [0:00,1:00) for different holidays, or there could be different time intervals such as Friday [20:00,21:00) depending on the scheduling of a sport event at the time. For instance, for the time window Friday [20:30,21:00), one could have

  • a time interval for Friday [20:30,21:00) on days which are holidays and a major sport event is scheduled;

  • a time interval for Friday [20:30,21:00) on days which are holidays and a major sport event is not scheduled;

  • a time interval for Friday [20:30,21:00) on days which are not holidays and a major sport event is scheduled; and

  • a time interval for Friday [20:30,21:00) on days which are not holidays and a major sport event is not scheduled.

Given a point in space 0S and time t0[0,T], possibly with additional characteristics such as holiday or event type, LASPATED determines the combination of spatial subregion and time interval for the chosen discretization that contains the given point (0,t0). Furthermore, given a data set of observations consisting of several points, LASPATED computes the number of points in the data set in each combination of spatial subregion and time interval for the chosen discretization. For example, given a data set of medical emergencies, with a week of data associated with each observation, LASPATED computes the number of emergencies in the data set for each combination of type of emergency, spatial subregion, and time interval, for the chosen discretization, for each week of data.

LASPATED also facilitates calibration of nonhomogeneous spatio-temporal Poisson models using data prepared with the discretization subroutines. For example, suppose that the number of points of a spatio-temporal Poisson process is a function of type, spatial location, and time, and that a piecewise constant arrival rate model λc,i,t for type c, spatial subregion i, and time interval t, is estimated. LASPATED provides two approaches discussed in Section 2 to calibrate such models. Both approaches allow one to estimate with sparse data, for example when there are many combinations of subregion and time window in the discretization relative to the amount of data. In the first approach, the intensities are the solutions of an optimization problem which optimizes a linear combination of the log-likelihood and a regularization term that may include covariates or penalize non-smoothness of intensities regarding space and time. In the second approach, covariates are used as auxiliary explanatory variables in the model.

To the best of our knowledge, LASPATED is the first software that:

  1. implements the calibration of the models we propose for spatio-temporal data;

  2. provides a complete analysis and calibration of statistical models for spatio-temporal data taking only historical data as inputs and providing as outputs a discretized process, Poisson intensities, and scenarios for future arrivals;

  3. offers such a large set of options for spatial discretization;

  4. offers such a large set of options for time discretization;

  5. handles arrival types for discretization and provides outputs using information from several discretizations of several types of data.

Implementation and Architecture

1 Overview of Implementation and Functionalities

LASPATED contains a Python module that handles space and time discretization functions, given a dataset of events, and a C++ module that performs model estimation from the discretized set of events. The Python module is available on Pypi (Python package index) while the C++ source code is available on GitHub. Additionally, we provide an application for the model estimation tool for users unfamiliar with C++. The app may be used via a Docker image.

Python LASPATED module uses popular data science modules like (geo)pandas, shapely, numpy and matplotlib to perform its tasks. The user must provide a csv file, with header columns, containing data of events, see our user manual for details. Our spatiotemporal events in this file are identified by at least three columns: latitude, longitude, and a timestamp. If the events have other features, the user may provide a list of columns containing such features.

The border of the studied region may be defined from a Shapefile provided by the user, or LASPATED may obtain it from the events, defining a rectangle or a convex hull of the data that contains all events.

Space discretization may be done in four formats: rectangular, hexagonal, customized by regions, or using a Voronoi diagram for a set of locations. The hexagonal discretization is done via Uber python package H3. To use the customized discretization (for instance, administrative districts of a city), the user must provide a geopandas dataframe containing the subregions. The Voronoi diagram is computed from a dataframe containing latitude/longitude pairs, for instance, the locations of police stations for crime data.

If there is other data available for the area containing the data, such as population or land type, LASPATED allows us to combine this information with the spatiotemporal events. For instance, if the user provides a geopandas dataframe contaning the population of a region, LASPATED is able to compute the population inside each discretized subregion.

LASPATED allows users to specify a rich diversity of time discretizations, see below.

At the end of the discretization process, LASPATED outputs two dataframes:

  1. a geopandas dataframe containing data about space discretization, including the geometry of each subregion, its index, and attributes;

  2. a dataframe including for each event its features, its spatial discretization index related to the geopandas dataframe, and its time discretization indices.

LASPATED allows users to save these dataframes to a file or as a plot. The discretized data can also be saved as aggregates by discretization indices.

The C++ module takes spatio-temporal discretized events data (possibly generated by the Python module) and uses a projected gradient algorithm to solve the maximum likelihood estimation problem.

Next, we describe the statistical models on which LASPATED is based.

2 Poisson Models with Discretized Spatio-temporal Data

In this section, we describe the models that motivated the work on LASPATED, and we explain how LASPATED solves the optimization problems for the calibration of these models. We will use the medical emergency application as a running example to explain the models.

Let iI index the subsets of the space discretization forming a partition of the region SRn; the elements of I will be called zones. Let tT index the subsets of the time discretization forming a partition of all times of interest; the elements of T will be called time intervals. Let C denote the set of point types; C can be any finite set that forms a partition of all space-time points of interest; the elements of C will be called types.

2.1 Model without Covariates

Each time interval tT has a duration Dt (in time units). It is assumed that data are observed for multiple occurrences of the same interval t, and that each time data are observed for a type cC, zone iI, and interval tT, all such space-time points in the same time interval are recorded in the data. For example, suppose that T forms a partition of the week in time intervals of 1 hour each. Then it is assumed that the data contain observations of emergencies of type c in zone i during hour t for multiple weeks, and that each time emergency arrivals of type c in zone i are observed during a particular hour t of a particular week, all the emergency arrivals of the same type in the same zone during the same hour t of that week are recorded. (It is planned to make provision for censored data in future work.) All the emergency arrivals of a particular type c in a particular zone i during a particular hour t of a week together are called an observation. For each cC, iI, and tT, let Nc,i,t denote the number of observations for type c, zone i, and time interval t, and let these observations be indexed by nNc,i,t:={1,,Nc,i,t}. For each cC, iI, tT, and nNc,i,t, let Mc,i,t,n denote the number of points (arrivals) for observation n of type c, zone i, and time interval t, and let Mc,i,t:=n=1Nc,i,tMc,i,t,n denote the total number of points over all observations for type c, zone i, and time interval t.

Assume that {Mc,i,t,n:cC,iI,tT,nNc,i,t} are independent (but not necessarily identical) Poisson distributed random variables. Let λc,i,t denote the mean number of points per length of time (such as per hour) for type c, zone i, and time interval t. Then random variable Mc,i,t,n is Poisson distributed with mean λc,i,tDt. Let λ:=(λc,i,t,cC,iI,tT). Then the likelihood function is

L(λ)=cCiItTnNc,i,teλc,i,tDt(λc,i,tDt)Mc,i,t,nMc,i,t,n!

and intensities λ that maximize the log-likelihood are the same intensities that solve

5
minλ{L(λ):=cCiItT[Nc,i,tλc,i,tDtMc,i,tlog(λc,i,t)]}.

A typical issue with such applications is that the distribution of data is far from uniform — there are a few combinations of type c, zone i, and time interval t with many observations, but for most combinations of type c, zone i, and time interval t there are very few observations. In such cases, it may be advantageous to use data from “neighboring” observations, or to bring additional data to bear on the estimation problem.

For example, suppose that T forms a partition of the week in time intervals of 1 hour each, but that it is expected that many hours of the week are similar to other hours of the week in terms of arrival rates. A simple approach to incorporate such an idea is to partition T into a collection G of subsets of T in such a way that it may be reasonable to expect that, for each cC, iI, and GG, the values of λc,i,t for different tG will be close to each other (but not necessarily the same). Let WG0 denote a similarity weight for GG. Another approach to incorporate such an idea is to specify a similarity weight wt,t0 for each (unordered) pair t,tT. For example, wt,t=w>0 if t and t’ are neighboring time intervals, and wt,t=0 otherwise. Similarly, it may be expected that many zones are similar to other zones in terms of arrival rates. Such an idea can also be incorporated by partitioning the set I of zones into subsets, each with its own similarity weight, or by specifying for each pair i,tI, a similarity weight wi,t0. An example loss function with similarity regularization that uses the first approach for time intervals and the second approach for zones is given by

6
(λ)=cCiIGGtG[Nc,i,tλc,i,tDtMc,i,tlog(λc,i,t)+WG2tGNc,i,tNc,i,t(λc,i,tλc,i,t)2]+cCi,tItTwi,t2Nc,i,tNc,j,t(λc,i,tλc,j,t)2.

Example 2.1: Consider a simple example in which I={0,,I},  and C and T are singletons, that is, λ is estimated as a function of space only. Suppose that the number of observations Ni=N is the same for all iINote that the empirical estimates, without smoothing, are λ^iE=Mi/NFor smoothing, choose w0,i=1 for all iI, and wi,t=0 otherwise, that is, zone 0 is a neighbor of all other zones, but none of the other zones are neighbors of each other. Then the loss function  in (6) reduces to

(λ)=iI[NλiMilog(λi)]+iI12N2(λiλ0)2.

It follows from the first-order optimality conditions that

λ0(λ)=NM0λ0N2iI{0}(λiλ0)=0λ0Nλ0iI{0}(λiλ0)=M0N=λ^0E.λi(λ)=NMiλi+N2(λiλ0)=0iI{0}λi+Nλi(λiλ0)=MiN=λ^iEiI{0}iIλi+NiI{0}(λiλ0)2=iIλ^iE.

Unless λi=λ0 for all i, it follows from NiI{0}(λiλ0)2>0 that iIλi<iIλ^iEthat is, the estimated total rate is biased low.

To counter the bias illustrated in Example 2.1, one may want to use the data to constrain the estimates λ. For example, taking duration Dt of time interval t into account, one may want to constrain the estimates λ so that for every type cC, the sum of the intensities λc,i,tDt is equal to the sum of the empirical intensities λ^c,i,tEDt=Mc,i,t/Nc,i,t over zones iI and time intervals tT. The corresponding constraint is

7
iItTλc,i,tDt=iItTλ^c,i,tEDtcC.

Intensity estimates λ are then obtained by solving

8
minλ>0,(7)(λ).

2.2 Model with Covariates

Each type c, zone i, and time interval t may have covariates that are correlated with the arrival rates λc,i,t, and data of these covariates can be used to partly compensate for sparse data. For example, emergency arrival rates in different zones and time intervals can be expected to be correlated with the population and other measures of economic activity in the zones, as well as with festivals and other events during the time intervals. For each cC, iI, and tT, let xc,i,t:=(xc,i,t,1,,xc,i,t,K) denote the covariate values of type c, zone i, and time interval t. For example, xc,i,t,1 may be the population count with home addresses in a zone i, and xc,i,t,2 may be an indicator that a major sports event is scheduled in a zone i during a time interval t. Then consider the model

9
λ(xc,i,t)Dt=βxc,i,t

where β=(β1,,βK) are the model parameters. Let Xc,i,t denote the set of all possible values of xc,i,t. Often Xc,i,t can be chosen to be a polyhedron. Note that it should hold that

10
βxc,i,t 0xc,i,tXc,i,t,cC,iI,tT.

To facilitate such a model, let N=cCiItTNc,i,t denote the total number of observations, and let these observations be indexed n=1,,N. For each observation n{1,,N}, let Mn denote the number of arrival points for observation n and let xn:=(x1n,,xKn) denote the covariate values of observation n. Then the negative log-likelihood function is given by

11
L(β)=n=1N[βxnMnlog(βxn)].

As for the model without covariates, one may want to use the data to constrain the estimates λ. For example, one may add the constraint that for every type cC, the sum over all zones and all time intervals of the estimated rates is equal to the sum over all zones and all time intervals of the empirical rates, that is the constraint

12
tTiIβxc,i,t=tTiIλ^c,i,tEDtcC.

Next, we provide two examples of such models.

Example 2.2: Index C={1,,|C|}, T={1,,|T|}and let K1:=|C×T|For each cC, tTand k=(c1)|T|+t, let xkn be the number of people resident (population count) in the zone of observation n if observation n is for type c and time interval t, and xkn=0 otherwise. The next covariate is a set of occupational land use areas (in km2), for instance the areas of commercial activities and public facilities, of industrial activities, and of undeveloped land. Index the occupational land uses by O={1,,|O|}. For each cC, tT, mO, and k=K1+(c1)|T||O|+(t1)|O|+m, let xkn be the area of occupational land use m in the zone of observation n if observation n is for type c and time interval t, and xkn=0 otherwise. Then k=1K1 βkxkn denotes the forecasted number of arrivals for the type of observation n in the zone of observation n during the time interval of observation n due to people being in the residential area, which is modeled as proportional to the number of people resident in the zone of observation n with a proportionality coefficient that depends on the type and the time interval. Similarly, k=K1+1K1(1+|O|)βkxkn denotes the forecasted number of arrivals for the type of observation n in the zone of observation n during the time interval of observation n due to people being in the different occupational areas which is modeled as proportional to the areas of occupational land use in the zone of observation n with a proportionality coefficient that depends on the type and the time interval. If K1|O| is large, the number of parameters βk of the model specified in this example is also large. Similar to (6), similarity regularization can be used to estimate the parameters, for example, by minimizing a loss function such as

(β)=n=1N[βxnMnlog(βxn)]+k,k=1K1(1+|O|)wk,k2(βkβk)2.

Example 2.3: This example will be used to demonstrate the modeling of arrivals of emergency calls to an emergency medical service. The sets C, I, and O are the same as in Example 2.2. Let T denote the indices of discrete time periods during a day, for example, T={1,,48} if each day is discretized into 30-minute intervals. Let D denote the set of indices of the (normal) days of the week, as well as indices for special days such as holidays. Thus, the cardinality of D is 7 plus the number of special days. A pair (d,t)D×T specifies a time interval. For each zone iIconsider covariates xiR1+|O|where xi(1) is the population count in zone i, and xi(j+1) is the area (in km2) of occupational land use j in zone i for j=1,,|O|Here, we assume that these data (population and land type areas) do not depend on time, which is reasonable for moderate time periods. Then, for each type c, zone i, day d, and time period t, the arrival intensity is given by λc,i,d,tDt=βc,d,txi for some vector βc,d,tR1+|O|). Furthermore, for each type c, zone i, day d, and time period t, let Nc,i,d,t denote the number of observations, let Mc,i,d,t,n denote the number of arrival points for observation n, and let Mc,i,d,t:=n=1Nc,i,d,tMc,i,d,t,n. Then the negative of the log-likelihood function is given by

13
L(β)=cCiIdDtTn=1Nc,i,d,t[βc,d,txiMc,i,d,t,nlog(βc,d,txi)]=cCiIdDtT[Nc,i,d,tβc,d,txiMc,i,d,tlog(βc,d,txi)].

Note that call rates βc,d,txi should be positive. Additionally, for each type c, day d, and time period t, the coefficients βc,d,t(1) that represent the ratio of emergencies to population should be small (say less than 1), which implies the constraints 0βc,d,t(1)1. Therefore, the estimation problem is to solve the optimization problem

14
minL(β)s.t.βc,d,txi>0,   0βc,d,t(1)1,(12),     cC,dD,tT.

Depending on the solver, better numerical performance may be obtained by replacing the constraints of (14) with

15
βc,d,txiε,   0βc,d,t(1)1,(12),     cC,dD,tT,

for some ε>0 sufficiently small.

2.3 Solving the Optimization Problems

The calibration of models such as those of Section 2.1 requires solving an optimization problem (8) of the form min{(λ):λ>0}. The problem can also be formulated as

16
min{(λ):λC}

where C is a closed convex set such as

17
C={λ:λεe}

for a chosen ε>0 and e a vector of ones. The objective function of (16) is differentiable on such C.

The calibration of models such as those of Section 2.2 requires solving an optimization problem (14) of the form

18
min{L(β):βB}

where B is given by constraints such as (15). In both cases, the problem is a convex optimization problem with a differentiable objective function on the feasible set.

The algorithms described below for solving problems such as (16) take regularization weights such as WG and wi,j as input. LASPATED also provides cross validation functions, that facilitate use of the data to select regularization weights.

Projected gradient with line search. LASPATED provides the following two methods for solving problems (16) and (18): (1) a projected gradient method with line search along a feasible direction, and (2) a projected gradient method with line search along the boundary. These methods follow (25) except for the update of Δ. Here, we provide the pseudocode for these methods for a problem of form (16). Let ΠC(λ) denote the projection of the point λ onto a closed convex set C. The pseudocode presents methods that are run for a chosen number of iterations and that start from any feasible λ0C. For alternative stopping criteria, see the discussion at the end of this section.

Projected gradient method with Armijo line search along a feasible direction for convex problem (16)

Initialization: Choose σ(0,1), Δ¯>0, MaxNumberIteration >0, and an initial feasible point λ0C

λ=λ0, k=0, Δ=Δ¯

While k< MaxNumberIteration

      Compute (λ) and (λ)

      z=ΠC(λΔ(λ))

      zAux = z

      Compute (zAux)

      j=0

      While ((zAux)>(λ)+σ2j(λ)(zλ))

            jj+1

            zAux=λ+12j(zλ)

            Compute (zAux)

      End While

      λ=zAux

      Δ2Δ2j

      kk+1

End While

Projected gradient method with Armijo line search along the boundary for convex problem (16)

Initialization: Choose σ(0,1), Δ¯>0, MaxNumberIteration >0, and an initial feasible point λ0C

λ=λ0, k=0, Δ=Δ¯

While k< MaxNumberIteration

      Compute (λ) and (λ)

      z=ΠC(λΔ(λ))

      Compute (z)

      j=0

      While ((z)>(λ)+σ(λ)(zλ))

            jj+1

            z=ΠC(λΔ2j(λ))

            Compute (z)

      End While

      λ=z

      Δ2Δ2j

      kk+1

End While

Note that for problem (16) with C={λ:λεe}, the projection ΠC(λ)=max{λ,εe} onto C is easy to compute, where the max is taken componentwise. Furthermore, the first derivatives of are given by

λc,i,t(λ)=Nc,i,tDtMc,i,tλc,i,t+WG(t)tG(t)Nc,i,tNc,i,t(λc,i,tλc,i,t)+jIwi,tNc,i,tNc,j,t(λc,i,tλc,j,t),

where G(t) denotes the group of time intervals to which t belongs. For problem (18), the first derivatives of L are given by

Lβc,d,t(β)=iI[Nc,i,d,txiMc,i,d,txiβc,d,txi].

For problem (18) with B={β:βc,d,txiε,0βc,d,t(1)1,cC,dD,tT}, the projection ΠB(β) onto B is computed by solving a convex quadratic problem.

Stopping test for projected gradient method with line search. LASPATED makes provision for several stopping criteria such as convergence of the objective function values, a maximum number of iterations, or stopping when optimality conditions are approximately satisfied. We give more details about this latter criterion. Consider an optimization problem

(P)=min{(λ):λC}

where and C are convex, and C is compact. At the end of iteration k, points λ0,,λk have been generated, and the upper bound

19
uk=min{(λ0),,(λk)}

on can be computed. One can minimize the linear approximation of at λk to compute the lower bound

20
k=min{(λk)+(λk)(λλk):λC}

or one can minimize the piecewise linear approximation of at λ0,,λk to compute the lower bound

21
k=min{max{(λi)+(λi)(λλi):    i{0,,k}}:λC}=min{θ:θ(λi)+(λi)(λλi)    i{0,,k},λC}

The algorithm is stopped when

22
ukkε,

thus obtaining an ε-optimal solution.

3 Time Discretization

LASPATED provides multiple types of time discretization. The corresponding function is add_time_discretization — see the user manual for details of the use of this function to produce the time discretizations described below. Some time discretization methods are based on a periodic pattern. The duration of the periodic pattern can be chosen, for example, 7 days or 10 days or 3 months. To make provision for holidays and special events, LASPATED also facilitates time discretization methods that are not based on a periodic pattern. The subsets of the time discretization can be chosen to be time intervals, or finite unions of time intervals. For example, if the duration of the periodic pattern is 7 days, then Monday [08:00,09:00] Friday [17:00,18:00] can be chosen to be one subset of the time discretization. Next, we mention some special cases of time discretization facilitated by LASPATED.

3.1 Periodic with Equal Length Time Intervals

The simplest time discretization in LASPATED uses a periodic pattern, in which the duration of the periodic pattern is partitioned into time intervals of equal length. That is, each subset of the time discretization is a single time interval, and all these time intervals have the same length.

3.2 Periodic with Unequal Length Time Intervals

Another time discretization in LASPATED also uses a periodic pattern, in which the duration of the periodic pattern is also partitioned into time intervals, but the time intervals may have unequal lengths. As in the previous method, each subset of the time discretization is a single time interval, but unlike the previous method, all these time intervals do not have the same length.

3.3 Customized Subsets

LASPATED makes provision for customized subsets to facilitate holidays and special events. Each customized subset is assigned a unique index number, and consists of one or more time intervals. Each time interval is specified by its start time and its end time, as well as the index of the subset that the time interval belongs to. Time points that do not belong to any customized interval, belong to the customized subset with index 0. LASPATED also allows time intervals to repeat. For example, a time interval that starts and ends on date 2016-01-01 (New Year’s Day) may be specified to repeat each year. If the time interval is specified as repeating yearly, then for all observations on the same day of the year (such as January 1), the time intervals’ start time during the day, end time during the day, as well as the index of the subset that the time intervals belong to, will be the same for all years.

4 Space Discretization

LASPATED provides several space discretization tools. The corresponding functions are add_max_borders, plot_discretization, add_geo_discretization, get_intersection, add_geo_variable, get_events_aggregated, write_arrivals, write_regions — see the user manual for details of the use of this function to produce the space discretizations described below.

4.1 Defining Borders

The first step for space discretization is to choose a coordinate system and to specify the border of a region that contains the locations of all the points in the dataset. The border specifies the region that will be discretized in space. The border can be specified with LASPATED using different methods.

4.1.1 Custom Map

A custom map can be provided to LASPATED by specifying the coordinates of a sequence of vertices on the border of the region. Typically, a Shapefile is provided for this purpose; the user manual and the video tutorial contain details and examples.

4.1.2 Rectangular Border and Convex Hull

LASPATED can be instructed to determine various regions that contain the locations of all the points in a dataset, such as the smallest rectangle that contains all the points in the dataset, or the approximate convex hull of all the points in the dataset.

Once borders are specified, the space discretization step partitions the region inside the specified border into subregions. Similar to the subsets of the time discretization, the subregions of the space discretization can be chosen to be simple shapes such as rectangles or hexagons, or unions of simple shapes. Next we mention some special cases of space discretization facilitated by LASPATED.

4.2 Equal Sized Rectangular Space Discretization

The simplest space discretization in LASPATED partitions the region into equal sized rectangles, in such a way that adjacent rectangles share a common face, that is, if the boundaries of rectangle A and rectangle B intersect, then either rectangle A and rectangle B intersect in one (corner) vertex, or rectangle A and rectangle B share an edge between 2 vertices. For example, the rectangles A=[0,2]×[0,2] and B=[2,4]×[1,3] are adjacent but do not share a common face. If the region is not a union of these equal sized rectangles, then the intersections of the rectangles with the region may not be equal sized. For example, Figure 1 shows a discretization of a custom region containing the city of Rio de Janeiro into 10×10=100 rectangles, and Figure 7 shows a discretization of the same region into 100×100=10000 rectangles. Both discretizations were obtained with LASPATED.

Figure 7

Space discretization of a region containing the city of Rio de Janeiro into 100×100=10000 rectangles, 4916 of which have nonempty intersection with the region and are shown in the figure.

4.3 Equal Sized Hexagonal Space Discretization

Another simple space discretization in LASPATED partitions the region into equal sized hexagons, in such a way that adjacent hexagons share a common edge. (The Uber Python package H3 was used for the discretization.) Figure 2 shows a discretization of a region containing the city of Rio de Janeiro into hexagons using a scale parameter equal to 7, and Figure 8 shows a discretization of the same region into hexagons using a scale parameter equal to 8. Both discretizations were obtained with LASPATED.

Figure 8

Space discretization of a region containing the city of Rio de Janeiro into hexagons using the Uber library H3 with scale parameter equal to 8.

4.4 Customized Space Discretization

LASPATED also facilitates space discretization with customized subregions. For example, Figure 3 obtained with LASPATED displays a customized discretization of the city of Rio de Janeiro into 160 administrative districts.

4.5 Discretization using Voronoi diagrams

LASPATED also provides space discretization with Voronoi diagrams. Figure 9 obtained with LASPATED displays a discretization based on the Voronoi diagram given by the locations of ambulance stations in Rio de Janeiro. Each subregion includes the set of points that are closest to a specific station.

Figure 9

Discretization of a region containing the city of Rio de Janeiro into 34 subregions, given by the Voronoi diagram of ambulance stations in Rio de Janeiro.

5 Additional Discretization Functionalities

Often different discretizations are used for different purposes. For example, different spatial attribute data such as population count and land use type may be provided using different space discretizations. Consider two discretizations D1 and D2. Let I1 be the index set of the subregions of discretization D1, and let I2 be the index set of the subregions of discretization D2. In this context, LASPATED provides the following functionalities:

  • Given subregion indices i1I1 and i2I2, LASPATED computes the area A(i1,i2) of the intersection of subregions i1 and i2. As an example, Figure 10 displays a partition of Rio de Janeiro into 4 different types of land use. LASPATED can be used to compute for every subregion of a given space discretization (such as rectangles or hexagons) the area of each land use type in the subregion.

  • Consider a given attribute, such as population count, and assume that the attribute value Pi1 in each subregion i1I1 of discretization D1 is uniformly distributed with density di1=Pi1/A(i1), where A(i1) is the area of the subregion i1. We want to allocate this attribute value to the subregions of another discretization D2. LASPATED computes the value of the attribute allocated to subregion i2I2 of discretization D2 as i1I1di1A(i1,i2)=i1I1Pi1A(i1,i2)/A(i1).

Figure 10

4 types of land use in Rio de Janeiro.

6 Calibration Functions

LASPATED also provides tools in C++ for the calibration of the models described above. All code is contained in the header file laspated.h. The user can run the calibration functions by building a model object and a struct with parameters for the projected gradient and cross validation functions (see the user manual for details) or by using the application we provide, as described in Section 6.2. The next section discusses the compilation and dependencies.

6.1 Compilation and Dependencies

C++ calibration functions use the following libraries:

  • Gurobi (https://www.gurobi.com), an optimization tooblox used only in the model with covariates;

  • xtensor and xtl libraries.

When compiling the code, the user needs to pass the location of the header files for LASPATED, xtl, xtensor and gurobi, as well as the location for Gurobi libraries and their respective flags. xtl and xtensor require the C++14 standard and its flag must also be passed. The example below compiles an executable called laspated from a main.cpp that includes laspated.h, and uses the Gurobi solver.


$ g++ -o laspated main.cpp -std=c++14
    -I<gurobi_header_dir>
    -I<laspated_header_dir>
    -I<xtl_header_dir>
    -I<xtensor_header_dir>
    -L<gurobi_libs_dir>-lgurobi_c++ -lgurobi100

If Gurobi is not used, the calibration functions for the model without covariates are used by setting the flag -DUSE_GUROBI equal to zero. The following command compiles the code in such a case:


$ g++ -o laspated main.cpp -std=c++14
    -DUSE_GUROBI=0 -I<laspated_header_dir>
    -I<xtl_header_dir> -I<xtensor_header_dir>

We provide five test models in the source files test_problems.cpp and test_problems.h in the Model_Calibration directory. They were used to assert the quality of the projected gradient algorithm.

6.2 LASPATED C++ Application

We also provide a LASPATED binary app that allows running the calibration functions. The user must provide a set of files describing the model and a set of configuration options, either via a configuration file or command line. The options describe the algorithmic parameters, model attributes, and file locations. The valid options are the following:

  • double EPS: tolerance used in the projection algorithm;

  • double sigma: parameter used in the line search of the projected gradient method;

  • double accuracy: gap used as stopping criterion for the projected gradient method;

  • int max_iter: maximum number of iterations for the projected gradient method;

  • double lower_lambda: lower bound for decision variables in the projected gradient method;

  • double upper_lambda: upper bound for decision variables in the projected gradient method;

  • double beta_bar: initial step size for the projected gradient method;

  • double cv_proportion: proportion of samples used in each iteration of cross validation;

  • output_file: path where the LASPATED app will save the estimated intensities.

  • string model_type: the type of model being solved, must be either “reg” (for the model with covariates) or “no_reg” (for the model without covariates);

  • string method: the type of method being used. For the model with covariates, only “calibration” is supported (running the projected gradient algorithm once). For the model without covariates, can be either “calibration” or “cross_validation”;

  • string algorithm: the algorithm used. Can be either “feasible” for Armijo search along the feasible direction or “boundary” for Armijo search along the boundary. However “cross_validation” only supports the “feasible” option;

  • string info_file: path of file containing general information about the model. See below for a precise description of the corresponding file.

  • arrivals_file: path of file containing the samples of arrivals. See below for a precise description of the corresponding file.

  • neighbors_file: path of file containing the description of each zone, including its type, its covariates, and its neighbors. See below for a precise description of the corresponding file.

  • durations_file: path of file containing the durations for each time index. See below for a precise description of the corresponding file.

  • alpha_regions_file: path of file containing the space penalizations R×R matrix. See below for a precise description of the corresponding file.

  • time_groups_file: path of a file containing a description of time groups and the corresponding penalties in the regularized model from Section 2.1. See below for a precise description of the corresponding file.

  • double duration: array with the duration of each period.

  • cv_weights_file: path of a file containing the weights to be used in cross validation. See below for a precise description of the corresponding file.

  • relax_empirical_fix: flag that, when set, relaxes the constraint that makes the sum of estimated rates per class equal to the empirical rate by class.

Note that to use the model with covariates, the user only needs to specify the info, arrivals, neighbors, and duration files. Additionally, for the model without regressors, the user must specify the files alpha_regions_file and time_groups_file. When performing cross validation, the file cv_weights_file is also needed.

The file info_file must contain two lines. The first line must contain, in that order, separated by spaces, the number of periods T per day, the number of week days G, the number of zones R, the number of arrival types C, the number of covariates J and the number of holidays H for each year. The second line contains, for each day of the week and holiday, the number of observations Ng for that day or holiday. Values of index g from 0 to 6 are used for days of the week while holidays have indexes in {7,8,,7+H}.

The file arrivals_file contains the samples observed, where each line describes a sample. Each line contains, in that order, separated by spaces, the period t[0,T), the day g[0,G), the zone r[0,R), the arrival type c[0,C), the sample index j[0,Ng), the number of arrivals observed, and a flag indicating whether the day is a holiday or not.

The file neighbors_file contains the description of each zone. Each line contains, in that order, the zone index, two values representing the coordinates of the zone centroid, a number indicating the zone’s land type, J values corresponding to the values of all J covariates, followed by a set of pairs of values (index, distance) indicating the distances of the considered zone to its neighbors (identified by their indexes).

The file alpha_regions_file describes the space penalization parameters. It contains a R×R matrix (with entries separated by spaces) where entry (i,j) corresponds to the weight in the objective function of the model without covariates if zones i and j are neighbors.

The file time_groups_file contains the description of time groups and their corresponding penalties. The first line must have the number |G| of time groups. The subsequent DT lines must have the group index of each period. Then the subsequent G lines may contain the weight of each group. If the method is set to “cross_validation”, the reading of time weights is skipped.

File cv_weights_file contains the weights to be used in cross validation, separated by spaces. Each weight must be non-negative.

The durations file contains the duration of each time index, in hours. The first line contains, separated by spaces, the number of day indexes and the number of time indexes.

The LASPATED app is only supported on Linux operating systems. The user must have the GCC compiler and the Boost library. In order to use the model with covariates, the user must have Gurobi installed. The directory Model_Calibration/Cpp contains a Makefile that is used to compile the app with:


$ make GUROBI_LIB_VER= -lgurobi110
    GUROBI_HOME=/opt/gurobi1101/linux64
INCLUDE_BOOST=/usr/include/boost

The Makefile uses GUROBI_HOME to find Gurobi directory, GUROBI_LIB_VER to find the Gurobi C library version and INCLUDE_BOOST to find the Boost directory. The values displayed above are actually the default values set in the Makefile, so if Boost and Gurobi are installed in those locations, then the make command will compile the code. Once LASPATED app is successfully compiled, it can be run with command:


$ ./laspated --model_type=no_reg
    --method=calibration
    --info_file=info.txt
    --arrivals_file=arrivals.txt
    --neighbors_file=neighbors.txt
    --alpha_regions_file=alpha_regions.txt
    --time_groups_file=time_groups.txt
    --durations_file=durations.txt
    --output_file=output.txt

to calibrate the model without covariates with space penalizations given in file alpha_regions.txt (see above) and penalization between time groups given in file time_groups.txt (see above). The command


$ ./laspated
    --model_type=no_reg
    --method=cross_validation
    --info_file=info.txt
    --arrivals_file=arrivals.txt
    --neighbors_file=neighbors.txt
    --time_groups_file=time_groups.txt
    --durations_file=durations.txt
    --cv_weights_file=cv_weights.txt
    --output_file=output.txt

uses cross validation to calibrate the model without covariates (and therefore computes penalizations). Finally, the command


$ ./laspated
    --model_type=reg
    --method=calibration
    --info_file=info.txt
    --arrivals_file=arrivals.txt
    --neighbors_file=neighbors.txt
    --durations_file=durations.txt
    --output_file=output.txt

calibrates the model with covariates.

More precisely, the first example performs the model estimation for the model without covariates (option model_type=no_reg) and saves the model parameters in output.txt (option output_file). The second example performs the model estimation without covariates using cross validation (option method=cross_validation). The third example calibrates the model with covariates (model_type=reg). Users can also provide the options via configuration file with the option -f.

After running the LASPATED app, the output is saved in the path provided by option output_file. If the model without covariates is used, the output contains in each line the indexes c[0,C), r[0,R), t[0,DT), and the intensity λc,r,t estimated by LASPATED. If the model with covariates is used, then each line correspond to indexes c[0,C), d[0,D), t[0,T), j[0,J), and the parameter βc,d,t,j estimated by LASPATED.

6.3 Demo Scripts

LASPATED repository contains a directory with demo scripts for the main functionalities that can be run with


python demo_discretization.py
    <border> <geo_disc>

to test discretization functions.

The option <border> must be one of the following border types: rectangle, convex and custom. The option <geo_disc> must be one of the discretization types: rectangle, hexagon and custom. This demo creates, based on our medical emergencies’ dataset, the discretization <geo_disc> of the region defined by the border <border>, and saves the files that can be used by the model estimation application. After compiling the C++ application, the following demos run the model estimation functions:


python demo_calibration_regularized.py
python demo_calibration_covariates.py

These scripts create the model files and invoke the C++ application that performs the model estimation. The model parameters are saved into files in the calib_data_covariates and calib_data_regularized directories.

6.4 Replication Script

We also provide, in the repository https://github.com/vguigues/Laspated_Replication, a python script that uses LASPATED to reproduce the results from the Quality Control and Reuse Potential sections. Before running the script, the first step is to compile the C++ code. If you have a GCC compiler installed, this can be done by running the following commands from the Laspated_Replication root directory:


$ cd Replication
$ make -C cpp_tests

The cpp_tests directory contains a Makefile that can be edited by the user that compiles the C++ script. The Makefile inside directory cpp_tests accesses the user-defined environment variable $GUROBI_HOME. If it is set, then the code for the model with Covariates inside laspated.h is accessible. Otherwise, the script will not run the experiments that use covariates.

After the C++ code is successfully compiled, you can run the replication script with:


$ python replication_script.py

This command will generate the rectangular, hexagonal and by district discretizations using the LASPATED python module, run the experiments with the C++ code and process the results, generating the figures and tables presented in the Quality Control and Reuse Potential sections of this paper.

All results presented in the paper are saved in the directory replication_results, with subdirectories plots and tables. To access the raw data generated by C++, go to the directory cpp_tests/results, with subdirectories for each experiment made. Subdirectories ex1 and ex2 contain the results for the first and second model without covariates (Tests from sections 7.1.1 and 7.1.2). Subdirectory ex3 contains the results for the model with covariates (Table 2) and real_data contains the results for the experiments with real data from the Reuse Potential section.

Table 2

Mean relative error e. In column 1, m/n denotes Ni,t=m for non-holiday time periods t, and Ni,t=n for holiday time periods t.

SAMPLE SIZE Ni,tHOLIDAYCOVNO COV 1NO COV 2NO COV 3EMP
5200.0060.0120.0480.0480.048
52000.0020.0040.0150.0150.015
78000.0010.0030.0120.0120.012
51/110.0670.0630.1380.1380.154
510/1010.0270.0500.0650.0650.049
765/1510.0180.0380.0540.0540.040

Quality Control

LASPATED was tested on a Ubuntu Linux 22.04 OS. We also provide a Docker container that was tested in Ubuntu 22.04 and in macOS. The Docker is built based on Linux. The user manual (26) provides details on how to test and use all LASPATED supported features. We also implemented unit tests for the projected gradient algorithms, available in the source file Model_Calibration/Cpp/test_problems.cpp and its header test_problems.h. The user can compile these unit tests by running the following command:


cd Model_Calibration/Cpp make USE_GUROBI=1 tests

Note that these tests require a Gurobi installation. Next, we use the LASPATED calibration functions for several tests based on simulated data. In all tests, intensities of arrivals were calibrated using the projected gradient method with Armijo search along a feasible direction, as described in Section 2.3. Tests were performed using GCC version 11.4, and Python 3.10 in a AMD Ryzen 5 2600 processor with 20GB of RAM in an Ubuntu 22.04 OS.

7 Quality Control Tests

7.1 Quality Control Tests with Artificial Data without Covariates

In these tests, points arrive in 2-dimensional space and over time according to a periodic non-homogeneous Poisson process. There is only one type of point, thus |C|=1, and hence the type notation c is omitted. The region under consideration is S=[0,10]2, as shown in Figure 11.

The region S is partitioned into two subsets S=BR, with B=[0,5]×(5,10](5,10]×[0,5] and R=[0,5]×[0,5](5,10]×(5,10].

Figure 11

Test region S=[0,10]2. The intensity function λ is different in the blue and red subregions, but the user does not know about these subregions. For estimation purposes, the user discretizes S into 10×10=100 square zones.

7.1.1 Test 1

In this test, the rate function λ:S×[0,T]R+ is different on B and on R, and is periodic with period 2, as follows:

λ(s,t)={0.1ifsB and t(2k,2k+1] for some kN,0.5ifsB and t(2k1,2k] for some kN,0.5ifsR and t(2k,2k+1] for some kN,0.1ifsR and t(2k1,2k] for some kN.

This rate function is represented in Figure 12(a) (for time intervals that start at odd times) and Figure 12(b) (for time intervals that start at even times).

Figure 12

Intensities as a function of location, for time intervals that start at odd times and even times. (a) Time intervals that start at odd times. (b) Time intervals that start at even times.

The user knows the region S and that |C|=1, but does not know about the subregions B and R that affect the intensity function λ, and does not know that λ is periodic with period 2. For estimation purposes, the user discretizes S into 100 square zones of unit area each, as shown in Figure 11. Thus I=IBIR indexes two types of zones, but this is not known by the user:

  • IB indexes 50 blue zones (with blue circles in their centers in Figure 11); there are 25 blue zones in the bottom right and 25 blue zones in the upper left of the region;

  • IR indexes 50 red zones (with red squares in their centers in Figure 11); there are 25 red zones on the bottom left and 25 red zones in the upper right of the region.

Also, for estimation purposes, the user discretizes time into 28 time intervals of length 1 each. Thus, the estimates are denoted with λi,t for iI and tT:={1,,28}. Given arrival data Mi,t,n for iI, tT, and n=1,,Ni,t, the regularized loss function in (6) is used to estimate λi,t. The penalty coefficients are wi,t=w>0 when i,j are neighboring zones, and wi,t=0 otherwise, where w will be varied as described later. Two zones are neighbors if their borders share an edge.

We consider two partitions G2 and G4 of time intervals T in (6). For partition G2, the time groups are G0={2k:k=1,,14} and G1={2k+1:k=0,1,,13}. For partition G4, the time groups are G0={4k:k=1,,7}, G1={4k+1:k=0,1,,6}, G2={4k+2:k=0,1,,6}, and G3={4k+3:k=0,1,,6}. For both partitions, penalty coefficients WG=w for all groups G (note that all groups have the same cardinality so that it seems reasonable to choose the same weights for different groups). Also, ε=0.001 in (17).

For any value of the penalty parameter w, let λ^i,tw denote the estimator of λi,t produced by (8). Note that when the penalty parameter w=0, then λ^i,t0 reduces to the empirical estimator of the intensities, which is the mean rate of arrivals in zone i and time interval t. For a range of values of the penalty parameter w, we computed the estimates λ^i,tw, and Figure 13 shows the mean (over all zones i and time intervals t) relative error given by

1|I||T|iItT|λi,tλ^i,twλi,t|

as a function of penalty parameter w, for different values of Ni,t.Figure 13 shows the mean relative errors for the following four estimators: estimator with partition G4 of time intervals and with neighbor-based spatial regularization (legend “4 groups, neighbors” in the figure), estimator with partition G4 of time intervals and without spatial regularization (legend “4 groups, no neighbors” in the figure), estimator with partition G2 of time intervals and with neighbor-based spatial regularization (legend “2 groups, neighbors” in the figure), and estimator with partition G2 of time intervals and without spatial regularization (legend “2 groups, no neighbors” in the figure). Figure 13 presents results for four values of the sample size: Ni,t=1, Ni,t=10, Ni,t=50, and Ni,t=500. Figure 13 also shows, for the three larger sample sizes, the mean relative error obtained by choosing the penalty parameter w by cross validation as follows: The data are partitioned into 5 subsets. Then, for each of 5 replications we used one of the data subsets (a different subset for each replication, with 20% of data used for training) to compute λ^i,tw for a range of values of w, and we used the remaining data to compute the out-of-sample likelihood value for each value of w. Then we determined the penalty parameter w that maximizes the average out-of-sample likelihood value over the 5 replications. Figure 13 shows the mean relative error for the resulting cross validation estimator with partition G2 of time intervals and with neighbor-based spatial regularization using the penalty parameter w. Note that the empirical estimator, with w=0, does not depend on the partition of time intervals and the neighbor structure, and therefore is given by all four estimators described above at w=0. Table 1 shows the minimum mean relative errors over different values of penalty parameter w, as well as the values of w that attain the minimum, for each of the four estimators, plus the mean relative errors of the cross validation estimator (using the penalty parameter w) and the empirical estimator (w=0), for each of the four sample sizes considered in Figure 13.

Figure 13

Mean relative estimation errors 1|I||T|iItT|λi,tλ^i,twλi,t| as a function of the penalty parameter w, for four sample sizes and six estimators (including the empirical estimator at w=0).

Table 1

The column headings denote the estimators as follows: Reg 1: estimator with partition G4 of time intervals and with neighbor-based spatial regularization; Reg 2: estimator with partition G4 of time intervals and without spatial regularization; Reg 3: estimator with partition G2 of time intervals and with neighbor-based spatial regularization; Reg 4: estimator with partition G2 of time intervals and without spatial regularization; CV: cross validation; Emp: empirical estimator. For each sample size and for each estimator Reg 1, Reg 2, Reg 3, Reg 4, each cell of the table gives two numbers separated by a slash (/): the first number is the minimum mean relative error over different values of penalty parameter w, and the second number is the value of w that attains the minimum. For the cross validation estimator, the first number is the mean relative error using the penalty parameter w, and the second number is the value of w. For the empirical estimator, the first number is the mean relative error using the penalty parameter w=0.

SAMPLE SIZE Ni,tREG 1REG 2REG 3REG 4CVEMP
10.47/1.20.67/2.00.34/0.60.51/1.4-1.539/0
100.31/0.060.30/0.20.26/0.060.17/0.20.42/0.20.543/0
500.18/0.0080.12/0.040.15/0.0040.08/0.0360.37/0.040.256/0
5000.08/0.00.03/0.0040.08/0.00.02/0.00280.26/0.0020.07687/0

In Figure 13, note that the vertical and horizontal scales of the sub-figures are different. As expected, the estimation error is decreasing in the sample size Ni,t. Note that the mean relative errors shown in Figure 13, and the values of the penalty parameter w with the smallest mean relative errors (shown with diamonds), were based on using the correct values λi,t in the calculations, which are not known by the user. Even when regularization is not based on the correct subregions and partition of time intervals, it can result in better estimates than the empirical estimates (corresponding to w=0), as long as reasonable values are chosen for w. The results indicate that the improvement of the estimates using regularization is more pronounced when the number of observations is small: for Ni,t=1, the estimation error decreases from about 152% (for the empirical estimator) to about 35% for the best regularized estimator, and for Ni,t=10, the estimation error decreases from about 52% to about 19%. Therefore, when a small amount of data are available, the regularized estimator results in a smaller estimation error, even if the regularization is not based on the correct model structure, as long as relevant information and reasonable weights are used for the regularization.

Figure 14 shows the true intensities λ(s,t) and the estimates λ^i,tw obtained with partition G2 of time intervals and with neighbor-based spatial regularization using the cross validation penalty parameters w, for sR, zone 1IR, Ni,t=1 (top left plot), for sR, zone 1IR, Ni,t=10 (bottom left plot), for sB, zone 6IB, Ni,t=1 (top right plot), and for sB, zone 6IB, Ni,t=10 (bottom right plot). It can be seen that if little data are available, then the regularized estimates are closer to the true intensities than the empirical estimates.

Figure 14

Comparison of true, empirical, and regularized estimates of the Poisson process intensities. True intensities as shown in Figure 12.

7.1.2 Test 2

In this test, we consider the same region S and the same subregions B and R as in Test 1. The intensity function λ is also periodic, but not piecewise constant, as follows:

λ(x,y,t)={x+yif(x,y)B and t(2k,2k+1] for some kN,5(x+y)if(x,y)B and t(2k1,2k] for some kN,5(x+y)if(x,y)R and t(2k,2k+1] for some kN,x+yif(x,y)R and t(2k1,2k] for some kN.

This rate function is represented in Figure 15(a) (for time intervals that start at odd times) and Figure 15(b) (for time intervals that start at even times).

Figure 15

Intensities as a function of location, for time intervals that start at odd times and even times. (a) Time intervals that start at odd times. (b) Time intervals that start at even times.

As in Test 1, the user knows the region S and that |C|=1, but does not know about the subregions B and R that affect the intensity function λ, and does not know that λ is periodic with period 2. For estimation purposes, the user discretizes S into 100 square zones of unit area each. The user computes the estimators λ^i,tw for each iI and each tT, by solving optimization problem (16) using regularization with penalty parameter w and ε=0.001. Each estimator λ^i,tw now approximates the rate Riλ(x,y,t)d(x,y), where Ri denotes the square of unit area for the zone i. For example, for a zone i with Ri=(ai1,ai]×(bj1,bj] and λ(x,y,t)=x+y for (x,y)Ri, it holds that

Riλ(x,y,t)d(x,y)=ai1aibj1bj(x+y)dydx=ai+bj1=λ(xi,yi,t)=xi+yi

where (xi,yi)=(ai0.5,bj0.5) is the centroid of the zone i.

The mean relative error of estimator λ^i,tw is now given by

1|I||T|iItT|Riλ(x,y,t)d(x,y)λ^i,tw|Riλ(x,y,t)d(x,y)      =1|I||T|iItT|λ(xi,yi,t)λ^i,tw|λ(xi,yi,t).

Parameter estimates λ^i,tw were computed for a range of values of the penalty parameter w, for the same four estimators as in Test 1: estimator with partition G4 of time intervals and with neighbor-based spatial regularization (legend “4 groups, neighbors” in Figure 16), estimator with partition G4 of time intervals and without spatial regularization (legend “4 groups, no neighbors” in Figure 16), estimator with partition G2 of time intervals and with neighbor-based spatial regularization (legend “2 groups, neighbors” in Figure 16), and estimator with partition G2 of time intervals and without spatial regularization (legend “2 groups, no neighbors” in Figure 16). As before, four values were used for the sample size: Ni,t=1, Ni,t=10, Ni,t=50, and Ni,t=500.Figure 16 shows the mean relative error for these four estimators, as well as the estimator with partition G2 of time intervals and with neighbor-based spatial regularization using the penalty parameter w chosen with cross validation. As before, the empirical estimator corresponds to w=0. In this test intensities are very different between neighboring zones, and as a result space regularization is not helpful, but if little data are available then time regularization still provides better estimates than the empirical estimator.

Figure 16

Mean relative errors 1|I||T|tTiI|Riλ(x,y,t)d(x,y)λ^t,iw|Riλ(x,y,t)d(x,y) as a function of the penalty parameter w. Intensities λ(x,y,t) are as shown in Figure 15.

7.2 Quality Control Tests with Artificial Data with Covariates

As in the previous tests, points arrive in S=[0,10]2 and over time according to a periodic non-homogeneous Poisson process. The region S is partitioned into two subregions S=BR, with B=[0,5]×(5,10](5,10]×[0,5] and R=[0,5]×[0,5](5,10]×(5,10]. There is only one type of point, thus |C|=1, and hence the type notation c is omitted. Each point sS has three attributes, denoted x(s):=(x1(s),x2(s),x3(s)). For the tests, x(s) was generated as follows. Let Ujb, Ujr, j=1,,20, be independent random variables uniformly distributed on (0,1). For sB, let

x1(s)=j=110(12)j{U2j1b|sin(2πjs1/10)|+U2jb|sin(2πjs2/10)|},

and for sR, let

x1(s)=j=110(12)j{(U2j1r+1)|sin(2πjs1/10)|+(U2jr+1)|sin(2πjs2/10)|}.

Let x2(s)=0.25 and x3(s)=0.5 for sB, and x2(s)=0.5 and x3(s)=0.25 for sR. The graph of x1(s) as a function of the center of the zones is shown in Figure 17.

Figure 17

Graph of covariate function x1.

We consider 2 settings, one without a holiday effect, and one with a holiday effect. In both settings, the rate function λ is periodic with period 2.

7.2.1 Test 3

In the setting without a holiday effect, the rate function λ:S×[0,T]R+ is as follows:

λ(s,t)={β(0)x(s)ift(2k,2k+1] for some kN,β(1)x(s)ift(2k1,2k] for some kN

where

β1(0)=0β1(1)=0.05,β2(0)=6β2(1)=18,β3(0)=3β3(1)=6.

Thus, if E:=kN(2k,2k+1] denotes the even-indexed time intervals and O:=kN(2k1,2k] denotes the odd-indexed time intervals, and AS and D[0,), then the expected number of arrivals in A×D is given by DAλ(s,t)dsdt=|DE|β(0)Ax(s)ds+|DO|β(1)Ax(s)ds, where |DE|:=DEdt and |DO|:=DOdt.

7.2.2 Test 4

In the setting with a holiday effect, the rate function λ:{0,1}×S×[0,T]R+ is as follows:

λ(h,s,t)={β(h,0)x(s)ift(2k,2k+1] for some kN,β(h,1)x(s)ift(2k1,2k] for some kN

where h=1 if t falls in a holiday, and h=0 otherwise, and

β1(0,0)=0,β1(0,1)=0.05,β1(1,0)=0,β1(1,1)=0.1,β2(0,0)=6,β2(0,1)=18,β2(1,0)=12,β2(1,1)=36,β3(0,0)=3,β3(0,1)=6,β3(1,0)=6,β3(1,1)=12.

We consider 2 estimators for each of the 2 settings: one estimator knows and uses aggregated covariate data, and the other estimator does not use covariate data. Below, we describe the 2 estimators in more detail.

7.2.3 Estimators that Use Covariate Data

The user knows the region S and that |C|=1, but does not know that λ is periodic with period 2. In the setting with a holiday effect, the user knows that there is a holiday effect, but the user distinguishes 8 different holidays and allows them to have different parameters. For estimation purposes, S is discretized into 100 square zones of unit area each, as shown in Figure 11. Thus I=IBIR indexes two types of zones, but this is not known by the estimator. For each zone iI, the user observes only the aggregate value yi,l:=Rixl(s)ds of the covariate xl for the zone. For example, if a zone in IB is [i1,i)×(j1,j], then the aggregate value of the covariate x1 for the zone is

i1ij1jx1(s1,s2)ds2ds1=k=110(12)k{U2k1bi1i|sin(2πks1/10)|ds1+U2kbj1j|sin(2πks2/10)|ds2}.

Therefore, we need to compute integrals of form i1i|sin(2πks1/10)|ds1.

Note that, for 0s110, it holds that sin(2πks1/10)0 if

5ks15k(+1)and{0,2,,2k2} is even,

and sin(2πks1/10)0 if

5ks15k(+1)and{1,,2k1} is odd.

Also note that

5kk5(i1)ik5(i1)k5ik5(i1)k5i.

Therefore, if 5kk5(i1)i, then

i1i|sin(2πks1/10)|ds1=i15kk5(i1)|sin(2πks1/10)|ds1+=k5(i1)k5i15k5k(+1)|sin(2πks1/10)|ds1+5kk5ii|sin(2πks1/10)|ds1=5πk(1)k5(i1)[cos(πk5(i1))cos(πk5(i1))]+10πk(k5ik5(i1))5πk(1)k5i[cos(πk5i)cos(πk5i)]

and if 5kk5(i1)>i, then

i1i|sin(2πks1/10)|ds1=5πk(1)k5i[cos(πk5(i1))cos(πk5i)].

Also, yi,2:=Rix2(s)ds=0.25, and yi,3:=Rix3(s)ds=0.5 for iIB, and yi,2=0.5, and yi,3=0.25 for iIR.

As in the previous tests, the user discretizes time into 28 time intervals of length 1 each. The user’s model is the same as the model specified in Example 2.3, with |C|=1, |T|=28, K1=28, and |O|=3. Thus, in the setting without a holiday effect, the user’s intensity function λ^:I×TR+ given by

λ^(i,t)=β^(t)yi

estimates Ri(t1,t]λ(s,τ)dτds, where β^(t)=(β^1(t),β^2(t),β^3(t)). Thus, this estimated model has 28×3 parameters. In the setting with a holiday effect, the user’s intensity function λ^:{0,1,,8}×I×TR+ given by

λ^(h,i,t)=β^(h,t)yi

estimates Ri(t1,t]λ(h,s,τ)dτds, where h=0 if h=0 and h=1 if h{1,,8}, and β^(h,t)=(β^1(h,t),β^2(h,t),β^3(h,t)). Thus, this estimated model has 9×28×3 parameters.

7.2.4 Estimators that Do not Use Covariate Data

The user knows the region S and that |C|=1, but does not know the covariate values yi, and does not know that λ is periodic with period 2. In the setting with a holiday effect, the user knows that there is a holiday effect, but the user distinguishes 8 different holidays and allows them to have different parameters.

The estimators are similar to those in Section 7.1. In the setting without a holiday effect, the user’s intensity function λ^i,tw, computed by solving (8) with the penalty parameter w, estimates Ri(t1,t]λ(s,τ)dτds. In the setting with a holiday effect, the user’s intensity function λ^h,i,tw, computed by solving (8) with the penalty parameter w, estimates Ri(t1,t]λ(h,s,τ)dτds.

7.2.5 More quality control tests

Table 2 shows the mean relative errors of regularized estimators with best penalty parameter w without covariates from Section 2.1, and the estimator with covariates from Section 2.2 (without regularization). The column “Holiday” indicates whether the intensities used to generate the data are different on holidays or not. For the tests with holidays, in the “Sample size Ni,t” column, the first number is the number of observations for days which are not holidays and the second number is the number of observations for days which are holidays (for instance, for the first experiment with holidays, Ni,t=51 for periods t which are not on holidays and Ni,t=1 for periods t which are on holidays). The column “Cov” shows results for the estimator with covariates from Section 2.2. The table also shows results for three regularized estimators without covariates: an estimator that does not use space regularization (column “No Cov 1”), an estimator that uses space regularization with penalizing weights for neighbors of the same color (column “No Cov 2”), and an estimator that uses space regularization with penalizing weights for all neighbors regardless of their color (column “No Cov 3”). For each estimator, the cells in the table show the values of the mean relative error for the estimator and the instance (for the regularized estimators without covariates, the best mean relative error among all considered penalty weights is shown). For this experiment, the best model is the model with covariates.

(2) Availability

Operating system

LASPATED was tested on a Ubuntu Linux 22.04 OS and in a macOS via its Docker container.

Programming language

The discretization features are implemented in Python and is compatible with version Python 3.13. The calibration features are written in C++, compiled and tested with GCC version 11.4. We also provide a Python scripts that performs a basic workflow of the library, generating a space-time discretization and calling the calibration app on the discretized data and a replication script to generate the figures from the Quality Control section.

Additional system requirements

Dependencies

The discretization features depend on the following Python modules: numpy 1.25, pandas 2.0, geopandas 0.12, matplotlib, h3, geovoronoi, rtree, descartes. The LASPATED Python module named laspated is available via pip, that automatically installs these dependencies.

The C++ calibration features depend on Boost 1.74, xtl, xtensor and, optionally, on Gurobi 11.01. The xtl and xtensor are header-only libraries and we provide a copy of them with the source code. Boost is available at https://boost.org and Gurobi is available at https://gurobi.com.

We provide a Docker container that installs all modules and dependencies.

List of contributors

Only the authors of this paper have worked on the development of LASPATED software.

Software location

Archive

  • Name: Zenodo

  • Persistent identifier: https://doi.org/10.5281/zenodo.20723233

  • Licence: Creative Commons Attribution 4.0 International

  • Publisher: Vincent Guigues

  • Version published: 1.1.2

  • Date published: 06/15/2026

Code repository

Emulation environment

Language

English

(3) Reuse Potential

The paper describes how the software can be used by both researchers and practitioners, both for data processing functions such as time and space discretizations, and for the calibration of nonhomogeneous Poisson models using spatiotemporal data. The User Manual (26) for the software is available on arXiv. Potential users can also find Youtube videos https://t.ly/O8I3D explaining how to install and use the software with many examples.

Possible extensions of this software include developing and implementing methods to deal with missing data, such as arrivals with missing location data, and methods of adaptive discretization (data-dependent discretization).

Users that encounter an issue can post it online on the github page of the project as a github issue.

Author Contributions

All authors participated equally to the development of models and implementation of the software.

DOI: https://doi.org/10.5334/jors.544 | Journal eISSN: 2049-9647
Language: English
Page range: 51 - 51
Submitted on: Nov 15, 2024
Accepted on: Jun 24, 2026
Published on: Jul 8, 2026
Published by: Ubiquity Press
In partnership with: Paradigm Publishing Services

© 2026 Vincent Guigues, Anton Kleywegt, Giovanni Amorim, André Krauss, Victor Hugo Nascimento, published by Ubiquity Press
This work is licensed under the Creative Commons Attribution 4.0 License.