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: Optional[flowmachine.core.spatial_unit.LonLatSpatialUnit] = 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: Optional[flowmachine.core.query.Query] = None)
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.Optional
, defaultNone
Spatial unit to which subscriber locations will be mapped. See the docstring of make_spatial_unit for more information.
-
departure_rate
:typing.Union
, default0.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
, defaultall
The hours of the day to include activity in
-
method
:str
, defaultlast
Method used to resolve a daily location
-
table
:typing.Union
, defaultall
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
, defaultmsisdn
Either msisdn, or imei, the column that identifies the subscriber.
-
subscriber_subset
:typing.Optional
, defaultNone
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}]))
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
Methods¶
cache¶
cache
Returns¶
-
bool
True is caching is switched on.
column_names¶
column_names
Returns the column names.
Returns¶
-
typing.List
List of the column names of this query.
column_names_as_string_list¶
column_names_as_string_list
Get the column names as a comma separated list
Returns¶
-
str
Comma separated list of column names
dependencies¶
dependencies
Returns¶
-
set
The set of queries which this one is directly dependent on.
fully_qualified_table_name¶
fully_qualified_table_name
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
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
Returns¶
-
bool
True if the table is stored, and False otherwise.
query_id¶
query_id
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
Return the current query state.
Returns¶
-
QueryState
The current query state
query_state_str¶
query_state_str
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
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
-
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 ↩