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)
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:strISO format date string denoting the first day of data to include
-
stop:strISO format date string denoting the last day of data to include
-
spatial_unit:typing.Union[flowmachine.core.spatial_unit.LonLatSpatialUnit, NoneType], defaultNoneSpatial 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], default0.1Either 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]], defaultallThe hours of the day to include activity in
-
method:str, defaultlastMethod used to resolve a daily location
-
table:typing.Union[str, typing.List[str]], defaultallSpecify 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, defaultmsisdnEither msisdn, or imei, the column that identifies the subscriber.
-
subscriber_subset:typing.Union[flowmachine.core.query.Query, NoneType], defaultNoneIf 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¶
-
boolTrue is caching is switched on.
column_names¶
column_names
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
Get the column names as a comma separated list
Returns¶
-
strComma separated list of column names
dependencies¶
dependencies
Returns¶
-
setThe 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¶
-
strString form of the table's fqn
index_cols¶
index_cols
A list of columns to use as indexes when storing this query.
Returns¶
-
ixen:listBy 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¶
-
boolTrue 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¶
-
strquery_id hash string
query_state¶
query_state
Return the current query state.
Returns¶
-
QueryStateThe current query state
query_state_str¶
query_state_str
Return the current query state as a string
Returns¶
-
strThe 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¶
-
strString 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 ↩