Skip to content

flowmachine.features.location.pwo

Source: flowmachine/features/location/pwo.py

The population-weighted opportunities model uses population distributions for predicting the probability of movement between populated areas. The model computes the attraction between populated centers relative to the distance between each origin and destination locations and also to all other equidistant locations from the destination. The model works similarly to the Radiation Model. The original publication suggests that its ideal usage is in cities.

Class PopulationWeightedOpportunities

PopulationWeightedOpportunities(start: str, stop: str, *, spatial_unit: Union[flowmachine.core.spatial_unit.LonLatSpatialUnit, NoneType] = None, departure_rate: Union[pandas.core.frame.DataFrame, float] = 0.1, hours: Union[str, Tuple[int, int]] = 'all', method: str = 'last', table: Union[str, List[str]] = 'all', subscriber_identifier: str = 'msisdn', subscriber_subset: Union[flowmachine.core.query.Query, NoneType] = None)
Source: flowmachine/features/location/pwo.py

Population-weighted opportunities model 1. The model predicts the mobility between populated areas in cities based only on the population densities of those areas, their spatial distribution, and the number of people that depart a certain area. This model is useful for studying mobility pattern in cities.

Attributes

Parameters

  • start: str

    ISO format date string denoting the first day of data to include

  • stop: str

    ISO format date string denoting the last day of data to include

  • spatial_unit: typing.Union[flowmachine.core.spatial_unit.LonLatSpatialUnit, NoneType], default None

    Spatial unit to which subscriber locations will be mapped. See the docstring of make_spatial_unit for more information.

  • departure_rate: typing.Union[pandas.core.frame.DataFrame, float], default 0.1

    Either one uniform departure rate, or a dataframe with a rate column and columns matching those of the spatial unit. If the latter, results are only returned for locations in this dataframe

  • hours: typing.Union[str, typing.Tuple[int, int]], default all

    The hours of the day to include activity in

  • method: str, default last

    Method used to resolve a daily location

  • table: typing.Union[str, typing.List[str]], default all

    Specify which event types to include. 'all', all available event types are included. Otherwise, should be a (schema qualified) list of events tables.

  • subscriber_identifier: str, default msisdn

    Either msisdn, or imei, the column that identifies the subscriber.

  • subscriber_subset: typing.Union[flowmachine.core.query.Query, NoneType], default None

    If provided, a query or table which has a column with a named subscriber to limit results to.

Examples

p = PopulationWeightedOpportunities('2016-01-01', '2016-01-07', departure_rate=pd.Dataframe([{"site_id":'0xqNDj', "rate":0.9}]))
One can also run the model with uniform departure rates for all locations as follows:
PopulationWeightedOpportunities('2016-01-01', '2016-01-07', departure_rate=0.5).head()
    origin  destination  prediction  probability
0  0xqNDj        8wPojr    0.384117     0.010670
1  0xqNDj        B8OaG5    0.344384     0.009566
2  0xqNDj        DonxkP    0.715311     0.019870
3  0xqNDj        zdNQx2    0.267854     0.007440
Where prediction is the absolute number of people that move from one location to another. (This should be interpreted as a integer, but floats are provided for evaluating results in a continuous scale.) And probability is the predicted value over the total population leaving the origin (T_i). That is, how likely it is that a person leaving the origin will be found in a given destination.

Methods

cache

cache
Source: flowmachine/core/query.py

Returns
  • bool

    True is caching is switched on.

column_names

column_names
Source: flowmachine/features/location/pwo.py

Returns the column names.

Returns
  • typing.List[str]

    List of the column names of this query.

column_names_as_string_list

column_names_as_string_list
Source: flowmachine/core/query.py

Get the column names as a comma separated list

Returns
  • str

    Comma separated list of column names

dependencies

dependencies
Source: flowmachine/core/query.py

Returns
  • set

    The set of queries which this one is directly dependent on.

fully_qualified_table_name

fully_qualified_table_name
Source: flowmachine/core/query.py

Returns a unique fully qualified name for the query to be stored as under the cache schema, based on a hash of the parameters, class, and subqueries.

Returns
  • str

    String form of the table's fqn

index_cols

index_cols
Source: flowmachine/core/query.py

A list of columns to use as indexes when storing this query.

Returns
  • ixen: list

    By default, returns the location columns if they are present and self.spatial_unit is defined, and the subscriber column.

Examples
daily_location("2016-01-01").index_cols
[['name'], '"subscriber"']

is_stored

is_stored
Source: flowmachine/core/query.py

Returns
  • bool

    True if the table is stored, and False otherwise.

query_id

query_id
Source: flowmachine/core/query.py

Generate a uniquely identifying hash of this query, based on the parameters of it and the subqueries it is composed of.

Returns
  • str

    query_id hash string

query_state

query_state
Source: flowmachine/core/query.py

Return the current query state.

Returns
  • QueryState

    The current query state

query_state_str

query_state_str
Source: flowmachine/core/query.py

Return the current query state as a string

Returns
  • str

    The current query state. The possible values are the ones defined in flowmachine.core.query_state.QueryState.

table_name

table_name
Source: flowmachine/core/query.py

Returns a uniquename for the query to be stored as, based on a hash of the parameters, class, and subqueries.

Returns
  • str

    String form of the table's fqn


  1. Yan X-Y, Zhao C, Fan Y, Di Z, Wang W-X. 2014 "Universal predictability of mobility patterns in cities". J. R. Soc. Interface 11: 20140834. http://dx.doi.org/10.1098/rsif.2014.0834