-
Notifications
You must be signed in to change notification settings - Fork 0
normalization.py
Code: normalization.py
Python script "normalization.py" implements the following procedures:
def zscore(
# a dictionary containing values of a determinant factor, values are identified by offer identifiers as keys
offers: Mapping,
# binary value indicating whether resulting weights need to be flipped (i.e. substracted from 1)
flipped = False) -> Mapping:
The procedure implements calculation of the z-score weights for a determinant factor across all offers. To define mathematically how the values of the z-score are calculated, we introduce the following notation:
- - number of offers with known values of a determinant factor belonging to a mobility request,
- - value of a determinant factor associated with offer ,
- - mean of the values for ,
- - standard deviation of the values for .
If flipped = 0, the value of the z-score, , for the determinant factor associated with the offer is calculated following the formula , otherwise (i.e. if flipped = 1) .
def minmaxscore(
# a dictionary containing values of a determinant factor, values are identified by offer identifiers as keys
offers: Mapping,
# binary value indicating whether resulting weights need to be flipped (i.e. subtracted from 1)
flipped = False) -> Mapping:
The procedure implements calculation of the minmax-score weights for a determinant factor across all offers. To define mathematically how the values of the minmax-score are calculated, we introduce the following notation:
- - number of offers with known values of a determinant factor belonging to a mobility request,
- - value of a determinant factor associated with offer ,
- - minimum value of a determinant factor,
- - maximum value of a determinant factor.
If flipped = 0, the value of the minmax-score, , for the determinant factor associated with the offer is calculated following the formula , otherwise (i.e. if flipped = 1) .
def aggregate_a_quantity_over_triplegs(
# array of trip leg identifiers to be aggregated
tripleg_ids,
# a dictionary containing weights identified by keys (trip leg key identifiers) that are used as weights
# in the aggregation. Typically, the duration of trip legs is used as a weight.
weights,
# a dictionary containing values of a determinant factor (identified by trip leg identifiers) to be aggregated
quantity)
The procedure implements aggregation of values of a determinant factor for an offer over trip legs belonging to the offer. To define mathematically how the values of the minmax-score are calculated, we introduce the following notation:
- - number of trip legs with known values of a determinant factor belonging to an offer.
- - value of a weigth determining the importance of trip leg (typically, in calculations the duration of a trip leg is used as a weight),
- - value of a determinant factor associated with the trip leg .
The aggregated value, , of the determinant factor is calculated as .