Mappers¶
Various mapper implementations. Mappers are functions that map possible feature value’s to the interval [-1, 1]. In Creamas, they are used by individual agent’s to represent agent’s preferences over features values.
-
class
creamas.mappers.
BooleanMapper
(mode='10')[source]¶ Boolean mapper that has four different modes.
Depending on the mode, True and False are mapped either to 1, 0, or -1.
mode
True
False
‘10’
1.0
0.0
‘01’
0.0
1.0
‘1-1’
1.0
-1.0
‘-11’
-1.0
1.0
-
map
(value)[source]¶ Map given value to the interval [-1, 1].
This base implementation maps each value to itself, capping to [-1, 1].
- Parameters
value – Value to map
- Returns
Value mapped to the interval [-1, 1]
- Rtype float
-
property
mode
¶ Mode of the mapper.
-
property
value_set
¶ Acceptable input types for the mapper.
-
-
class
creamas.mappers.
LinearMapper
(lo, hi, mode='01')[source]¶ Mapper that maps values in given interval linearly.
Can be used for features that return either ‘int’ or ‘float’ values.
Based on its mode, maps lo and hi to different end points and values between them to a straight line. Depending on the mode, lo and hi have following end points:
mode
lo
hi
‘10’
1.0
0.0
‘01’
0.0
1.0
‘1-1’
1.0
-1.0
‘-11’
-1.0
1.0
-
map
(value)[source]¶ Map given value to the interval [-1, 1].
This base implementation maps each value to itself, capping to [-1, 1].
- Parameters
value – Value to map
- Returns
Value mapped to the interval [-1, 1]
- Rtype float
-
property
mode
¶ Mode of the mapper.
-
property
value_set
¶ Accepted value types, i.e. this mapper can be used for the features that return these types of values.
-
-
class
creamas.mappers.
DoubleLinearMapper
(lo, mid, hi, mode='01')[source]¶ Mapper that concatenates two linear mappers.
Can be used for features that return either ‘int’ or ‘float’ values.
First line is created from lo to mid and second line from mid to hi. Depending on the mode, lo, mid and hi are mapped to following end points.
mode
lo
mid
hi
‘10’
1.0
0.0
1.0
‘01’
0.0
1.0
0.0
‘1-1’
1.0
-1.0
1.0
‘-11’
-1.0
1.0
-1.0
-
map
(value)[source]¶ Map given value to the interval [-1, 1].
This base implementation maps each value to itself, capping to [-1, 1].
- Parameters
value – Value to map
- Returns
Value mapped to the interval [-1, 1]
- Rtype float
-
property
mode
¶ Mode of the mapper.
-
property
value_set
¶ Accepted value types, i.e. this mapper can be used for the features that return these types of values.
-
-
class
creamas.mappers.
GaussianMapper
(mean, std, mode='01')[source]¶ Gaussian distribution mapper.
The mapped value is relative to given Gaussian distribution’s maximum point (pmax, evaluated at point loc) and the probability density function’s value at given evaluation point (pval).
The actual value calculation changes with the mode of the mapper:
mode
mapped value
‘10’
\(1.0 - (pval / pmax)\)
‘01’
\(pval / pmax\)
‘1-1’
\(1.0 - 2(pval / pmax)\)
‘-11’
\(-1.0 + 2(pval / pmax)\)
- Parameters
-
map
(value)[source]¶ Map given value to the interval [-1, 1].
This base implementation maps each value to itself, capping to [-1, 1].
- Parameters
value – Value to map
- Returns
Value mapped to the interval [-1, 1]
- Rtype float
-
property
mode
¶ Mode of the mapper.
-
property
value_set
¶ Acceptable input types for the mapper.
-
class
creamas.mappers.
LogisticMapper
(x0, k, mode='01')[source]¶ Logistic function mapper.
The mapped value is relative to the logistic function’s value in the mapping point. Depending on the mode, some transformations (mirroring, shifting), might be applied to the mapped value.
- Parameters
-
map
(value)[source]¶ Map given value to the interval [-1, 1].
This base implementation maps each value to itself, capping to [-1, 1].
- Parameters
value – Value to map
- Returns
Value mapped to the interval [-1, 1]
- Rtype float
-
property
mode
¶ Mode of the mapper.
-
property
value_set
¶ Acceptable input types for the mapper.