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

Parameters:
  • variable (Variable | str)

  • mapping (dict[int, str])

  • reference (str | None)

class biogeme.segmentation.OneSegmentation(beta, segmentation_tuple)[source]

Bases: object

Single segmentation of a parameter

Parameters:
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 assignment 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

Return type:

Beta

Returns:

expression of the parameter for the category

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)

list_of_expressions()[source]

Create a list of expressions involved in the segmentation of the parameter

Returns:

list of expressions

Return type:

list(biogeme.expressions.Expression)

class biogeme.segmentation.Segmentation(beta, segmentation_tuples, prefix='segmented')[source]

Bases: object

Segmentation of a parameter, possibly with multiple socio-economic variables

Parameters:
beta_code()[source]

Constructs the Python code for the parameter

Returns:

Python code

Return type:

str

segmented_beta()[source]

Create an expressions that combines all the segments

Returns:

combined expression

Return type:

biogeme.expressions.Expression

segmented_code()[source]

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

Returns:

Python code for the combined expression

Return type:

str

biogeme.segmentation.segment_parameter(beta, segmentation_tuples, prefix='segmented')[source]

Warning

This function is deprecated. Use segmented_beta() instead.

Parameters:
biogeme.segmentation.segmented_beta(beta, segmentation_tuples, prefix='segmented')[source]

Obtain the segmented Beta from a unique function call

Parameters:
  • beta (Beta) – parameter to be segmented

  • segmentation_tuples (Iterable[DiscreteSegmentationTuple]) – characterization of the segmentations

  • prefix (str) – prefix to be used to generated the name of the segmented parameter

Returns:

expression of the segmented Beta