Segmentation
Segmentation of the parameters
biogeme.segmentation module
Class that provides some automatic specification for segmented parameters
- author:
Michel Bierlaire
- date:
Thu Feb 2 09:42:36 2023
- class biogeme.segmentation.DiscreteSegmentationTuple(variable, mapping, reference=None)[source]
Bases:
object
Characterization of a segmentation
- __init__(variable, mapping, reference=None)[source]
Ctor
- Parameters:
variable (biogeme.expressions.Variable) – socio-economic variable used for the segmentation
mapping (dict(int: str)) – maps the values of the variable with the name of a category
reference (str) – name of the reference category. If None, an arbitrary category is selected as reference. :type:
- Raises:
BiogemeError – if the name of the reference category does not appear in the list.
- class biogeme.segmentation.OneSegmentation(beta, segmentation_tuple)[source]
Bases:
object
Single segmentation of a parameter
- __init__(beta, segmentation_tuple)[source]
Ctor
- Parameters:
beta (biogeme.expressions.Beta) – parameter to be segmented
segmentation_tuple (DiscreteSegmentationTuple) – characterization of the segmentation
- beta_code(category, assignment)[source]
- Constructs the Python code for the expression of the
parameter associated with a specific category
- Parameters:
category (str) – name of the category
assignment (bool) – if True, the code includes the assigbnment to a variable.
- Returns:
the Python code
- Return type:
str
- beta_expression(category)[source]
- Constructs the expression for the parameter associated with
a specific category
- Parameters:
category (str) – name of the category
- Returns:
expression of the parameter for the category
- Return type:
- beta_name(category)[source]
Construct the name of the parameter associated with a specific category
- Parameters:
category (str) – name of the category
- Returns:
name of parameter for the category
- Return type:
str
- Raises:
BiogemeError – if the category is not listed in the mapping of the segmentation.
- list_of_code()[source]
- Create a list of Python codes for the expressions involved
in the segmentation of the parameter
- Returns:
list of codes
- Return type:
list(str)
- class biogeme.segmentation.Segmentation(beta, segmentation_tuples, prefix='segmented')[source]
Bases:
object
Segmentation of a parameter, possibly with multiple socio-economic variables
- __init__(beta, segmentation_tuples, prefix='segmented')[source]
Ctor
- Parameters:
beta (biogeme.expressions.Beta) – parameter to be segmented
segmentation_tuples (list(DiscreteSegmentationTuple)) – characterization of the segmentations
prefix (str) – prefix to be used to generated the name of the segmented parameter
- beta_code()[source]
Constructs the Python code for the parameter
- Returns:
Python code
- Return type:
str