Segmentation

Segmentation of the parameters

biogeme.segmentation module

Class that provides some automatic specification for segmented parameters

author

Michel Bierlaire

date

Fri Dec 31 10:41:33 2021

class biogeme.segmentation.DiscreteSegmentationTuple(variable, mapping)

Bases: tuple

mapping

Alias for field number 1

variable

Alias for field number 0

biogeme.segmentation.code_to_combine_segmented_expressions(variable, mapping_of_expressions, prefix)[source]

Create the Python code for an expressions that combines all the segments

Parameters
  • variable (biogeme.expressions.Variable) – variable that characterizes the segmentation

  • mapping_of_expressions (dict(int: biogeme.expressions.Expression)) – dictionary that maps each value of the variable with the Python code of the expression for the corresponding segment.

  • prefix (str) – name of the current expression, used as prefix

Returns

code for the combined expression

Return type

str

biogeme.segmentation.code_to_segment_parameter(parameter, list_of_discrete_segmentations, prefix='')[source]

Generate the Python code to segment a parameter along several dimensions of segmentation

Parameters
  • parameter (biogeme.expressions.Beta) – parameter to segment

  • list_of_discrete_segmentations – each element of the list is a tuple with the variable characterizing the segmentation, and a dictionary mapping the values with the names of the segments.

  • prefix (str) – name of the current expression, used as prefix

Returns

code for the segmentation

Return type

str

biogeme.segmentation.combine_segmented_expressions(variable, mapping_of_expressions)[source]

Create an expressions that combines all the segments

Parameters
  • variable (biogeme.expressions.Variable) – variable that characterizes the segmentation

  • mapping_of_expressions (dict(int: biogeme.expressions.Expression)) – dictionary that maps each value of the variable with the expression for the corresponding segment.

Returns

combined expression

Return type

biogeme.expressions.bioMultSum

biogeme.segmentation.create_segmented_parameter(parameter, mapping)[source]

Create a version of the parameter for each segment

Parameters
  • parameter (biogeme.expressions.Beta) – parameter

  • mapping (dict(int: str)) – dictionary that maps each segment id with the name of the segment.

Returns

a dictionary that maps each segment id with the created parameters

Return type

dict(int: biogeme.expressions.Beta)

biogeme.segmentation.segment_parameter(parameter, list_of_discrete_segmentations, combinatorial=False)[source]

Segment a parameter expression along several dimensions of segmentation

Parameters
  • parameter (biogeme.expressions.Beta) – parameter to segment

  • list_of_discrete_segmentations – each element of the list is a tuple with the variable characterizing the segmentation, and a dictionary mapping the values with the names of the segments.

  • combinatorial – if True, a parameter is associated with each combination of values for the discrete segmentations. If \(N_s\) is the number of values for segmentation s, the total numper of parameters is \(\prod_s N_s\). If False, for each segmentation in the list, a parameter is associated with each value of this segmentation. If :math:`N_s is the number of values for segmentation s, the total number of parameters is \(\sum_s N_s\). :type combinatorial: bool

Returns

expression involving all the segments

Return type

biogeme.expressions.Expression