open_cp.prohotspot¶
prohotspot¶
Implements the “prospective hotspotting” technique from:
- Bowers, Johnson, Pease, “Prospective hot-spotting: The future of crime mapping?”, Brit. J. Criminol. (2004) 44 641–658. doi:10.1093/bjc/azh036
- Johnson et al., “Prospective crime mapping in operational context”, Home Office Online Report 19/07 Police online library
The underlying idea is to start with a kernel / weight defined in space and positive time. This typically has finite extent, and might be related to discretised space and/or time. Weights used in the literature tend to be of the form \(1/(1+d)\).
The classical algorithm assigns all events to cells in a gridding of space, and a “grid” of time (typically the number of whole weeks before the current time). Only events which are close enough in space and time to the grid cell of interest are used. For these, the weight is evaluated on each one, and then the sum taken.
It is important to note the coupling between the grid size used and the weight, because it is the distance between grid cells which is used. Exactly what “distance” here means is unclear, and we have provided a number of options.
Alternatively, we can just use the weight / kernel in a continuous kernel density estimate scheme.
-
class
open_cp.prohotspot.
ClassicWeight
¶ Bases:
open_cp.prohotspot.Weight
The classical weight, \((1/(1+d))(1/(1+t))\) where \(d\) is distance and \(t\) is time. Default units are “grid cells” and “weeks”, respectively.
Parameters: - space_bandwidth – Distances greater than or equal to this set the weight to 0.
- time_bandwidth – Times greater than or equal to this set the weight to 0.
-
class
open_cp.prohotspot.
DistanceDiagonalsDifferent
¶ Bases:
open_cp.prohotspot.GridDistance
Distance in the grid. Now diagonal distances are two, so (1,1) and (2,2) are two grid cells apart. This equates to using an \(\ell^1\) norm.
-
class
open_cp.prohotspot.
DistanceDiagonalsSame
¶ Bases:
open_cp.prohotspot.GridDistance
Distance in the grid. Diagonal distances are one, so (1,1) and (2,2) are adjacent points. This equates to using an \(\ell^\infty\) norm.
-
class
open_cp.prohotspot.
GridDistance
¶ Bases:
object
Abstract base class to calculate the distance between grid cells
-
class
open_cp.prohotspot.
ProspectiveHotSpot
(region, grid_size=50, time_unit=numpy.timedelta64(1, 'W'))¶ Bases:
open_cp.predictors.DataTrainer
Implements the classical, grid based algorithm. To calculate distances, we consider the grid cell we are computing the risk intensity for, the grid cell the event falls into, and then delegate to an instance of :class GridDistance: to compute the distance. To compute time, we look at the time difference between the prediction time and the timestamp of the event and then divide by the
time_unit
, then round down to the nearest whole number. So 6 days divided by 1 week is 0 whole units.Set
distance
to change the computation of distance between grid cells. Setweight
to change the weight used.Parameters: - region – The
RectangularRegion
the data is in. - grid_size – The size of the grid to place the data into.
- time_unit – A
numpy.timedelta64
instance giving the time unit.
-
predict
(cutoff_time, predict_time)¶ Calculate a grid based prediction.
Parameters: - cutoff_time – Ignore data with a timestamp after this time.
- predict_time – Timestamp of the prediction. Used to calculate the time difference between events and “now”. Typically the same as cutoff_time.
Returns: An instance of
GridPredictionArray
- region – The
-
class
open_cp.prohotspot.
ProspectiveHotSpotContinuous
(grid_size=50, time_unit=numpy.timedelta64(1, 'W'))¶ Bases:
open_cp.predictors.DataTrainer
Implements the prospective hotspot algorithm as a kernel density estimation. A copy of the space/time kernel / weight is laid down over each event and the result is summed. To allow compatibility with the grid based method, we set a time unit and a grid size, but these are purely used to scale the data appropriately.
-
predict
(cutoff_time, predict_time)¶ Calculate a continuous prediction.
Parameters: - cutoff_time – Ignore data with a timestamp after this time.
- predict_time – Timestamp of the prediction. Used to calculate the time difference between events and “now”. Typically the same as cutoff_time.
Returns: An instance of
ContinuousPrediction
-
-
class
open_cp.prohotspot.
Weight
¶ Bases:
object
Base class for weights / kernels. Classes implementing this algorithm are responsible purely for providing weights. We leave the details of possibly discretising data to other classes.