MGMCostDistribution#
- class caf.distribute.gravity_model.multi_area.MGMCostDistribution(name, cost_distribution, zones, function_params)#
Bases:
objectDataclass for storing needed info for a MultiCostDistribution model.
- Parameters:
name (str) – The name of the distribution (this will usually identify the area applicable e.g. City, Rural)
cost_distribution (cost_utils.CostDistribution) – A cost distribution in a CostDistribution class from toolkit. This will often be a trip-length distribution but cost can be in any units as long as they match the cost matrix
zones (np.ndarray) – The zones this distribution applies to. This is NOT zone number, or zone ID but the indices of the relevant zones in your cost matrix/target_rows
function_params (dict[str,str]) – Initial parameters for your cost function to start guessing at. There is a method included for choosing these which hasn’t yet been implemented.
Attributes Summary
Methods Summary
from_pandas(category, ordered_zones, tld, ...)Build using pandas dataframes and series.
Attributes Documentation
- cost_distribution: CostDistribution = <dataclasses._MISSING_TYPE object>#
- function_params: dict[str, float] = <dataclasses._MISSING_TYPE object>#
- name: str = <dataclasses._MISSING_TYPE object>#
- zones: ndarray = <dataclasses._MISSING_TYPE object>#
Methods Documentation
- classmethod from_pandas(category, ordered_zones, tld, cat_zone_correspondence, func_params, *, tld_cat_col='category', tld_min_col='from', tld_max_col='to', tld_avg_col='av_distance', tld_trips_col='trips', lookup_cat_col='category', lookup_zone_col='zone_id')#
Build using pandas dataframes and series.
- Parameters:
category (str) – distribution category, used to label gravity model run
ordered_zones (pd.Series) – zones ordered in the same way as other inputs
tld (pd.DataFrame) – tld data - should contain the tlds for each distribution labeled by the tld_cat_col
cat_zone_correspondence (pd.DataFrame) – lookup between categories values within tld and zones which use the corresponding distribution
func_params (dict[int | str, dict[str, float]]) – starting/run cost function params to use for each distribution key: distribution category, value: dict[param name, param value]
tld_cat_col (str, optional) – column name for the category column in tld, by default “category”
tld_min_col (str, optional) – column name for the min bin edge column in tld, by default “from”
tld_max_col (str, optional) – column name for the max bin edge column in tld, by default “to”
tld_avg_col (str, optional) – column name for the average distance column in tld, by default “av_distance”
tld_trips_col (str, optional) – column name for the trips column in tld, by default “trips”
lookup_cat_col (str, optional) – column name for the category column in cat_zone_correspondence, by default “category”
lookup_zone_col (str, optional) – column name for the zone column in cat_zone_correspondence, by default “zone_id”
- Return type:
- Raises:
ValueError – if zones in cat_zone_correspondence are not present in ordered_zones