functions

This module gathers all classes used to define functions.

class AdditiveValueFunctions(functions, in_scales=None, out_scales=None, aggregator_scale=None, in_stype=None, **kwargs)

Bases: CriteriaFunctions[I_S, QuantitativeScale]

This class represents multi-attribute additive value functions.

Parameters
Raises

TypeError

  • if in_stype is not consistent with at least one criterion function

  • if out_stype is not consistent with at least one criterion function

Note

functions are defined for the provided scales, so when applying functions you must provide correctly scaled values

__call__(x)

Apply scale functions to input.

Parameters

x (Union[Series, Values[I_S], DataFrame, PerformanceTable[I_S], PartialValueMatrix[I_S]]) – input

Returns

result

Return type

Union[Series, Values[O_S], DataFrame, PerformanceTable[O_S], PartialValueMatrix[O_S]]

aggregate(data, *args, **kwargs)

Apply aggregation method to input data.

Parameters

data (Union[PartialValueMatrix[QuantitativeScale], IValueMatrix[QuantitativeScale], DataFrame, Series, Values[QuantitativeScale]]) –

Returns

aggregation result

Return type

Union[Any, Series, CommensurableValues[QuantitativeScale], AdjacencyValueMatrix[QuantitativeScale]]

Note

aggregation is applied for each row in case of tabular data

within_in_scales(data)

Check potential input is inside input scales.

Parameters

data (Union[Series, Values[I_S], DataFrame, PerformanceTable[I_S], PartialValueMatrix[I_S]]) –

Returns

True if data is within in_scales

Return type

bool

class AffineFunction(slope=0, constant=0, segment=None)

Bases: object

This class defines a callable affine function.

Parameters
  • slope (float) –

  • constant (float) –

  • segment (Optional[List[List]]) – a list of two points on the affine function line, each point being a list with at least abscissa and ordinate

Note

segment supersedes slope and constant if provided

Attr slope

Attr constant

Parameters
  • slope (float) –

  • constant (float) –

  • segment (Optional[List[List]]) –

__call__(x)

Call affine function.

Parameters

x (float) –

Returns

result

Return type

float

class CriteriaFunctions(functions, in_scales=None, out_scales=None, in_stype=None, out_stype=None, **kwargs)

Bases: Generic[I_S, O_S]

This class represents a multi-attribute scale functions.

Parameters
  • functions (Mapping[Any, CriterionFunction[I_S, O_S] | Function]) – either CriterionFunction or functions

  • in_scales (Mapping[Any, I_S] | I_S | None) – input scales (ignored if CriterionFunction supplied)

  • out_scales (Mapping[Any, O_S] | O_S | None) – output scales (ignored if CriterionFunction supplied)

  • in_stype (Type[I_S] | None) –

  • out_stype (Type[O_S] | None) –

Raises

TypeError

  • if in_stype is not consistent with at least one criterion function

  • if out_stype is not consistent with at least one criterion function

Attr functions

criterion functions

Note

functions are defined for the provided scales, so when applying functions you must provide correctly scaled values

__call__(x)

Apply scale functions to input.

Parameters

x (Union[Series, Values[I_S], DataFrame, PerformanceTable[I_S], PartialValueMatrix[I_S]]) – input

Returns

result

Return type

Union[Series, Values[O_S], DataFrame, PerformanceTable[O_S], PartialValueMatrix[O_S]]

within_in_scales(data)

Check potential input is inside input scales.

Parameters

data (Union[Series, Values[I_S], DataFrame, PerformanceTable[I_S], PartialValueMatrix[I_S]]) –

Returns

True if data is within in_scales

Return type

bool

class CriterionFunction(function, in_scale=None, out_scale=None, in_stype=None, out_stype=None)

Bases: Generic[I_S, O_S]

This class defines a function and its input/output scale.

Parameters
  • function (Function) –

  • in_scale (Union[I_S, None]) – input scale (if not provided, inferred from input)

  • out_scale (Union[O_S, None]) – output scale (if not provided, inferred from output)

  • in_stype (Union[Type[I_S], None]) – input scale type (if not provided, inferred from input)

  • out_stype (Union[Type[O_S], None]) – output scale type (if not provided, inferred from output)

Raises

TypeError

  • if in_scale is not an instance of in_stype (and both are set)

  • if out_scale is not an instance of out_stype (and both are set)

__call__(x)

Apply scale function to input.

Parameters

x (Union[Any, Series, CommensurableValues[I_S]]) – either a single value or a series/criterion values

Returns

result

Return type

Union[Any, Series, CommensurableValues[O_S]]

within_in_scale(data)

Check potential input is inside input scale.

Parameters

data (Union[Any, Series, CommensurableValues[I_S]]) –

Returns

True if data is within in_scale

Return type

bool

class DiscreteFunction(values)

Bases: object

This class implements discrete function.

Parameters

values (Dict[Any, Any]) – function description, abscissa as keys, ordinates as values

__call__(x)

Apply function to single value.

Parameters

x (Any) –

Returns

Raises

IndexError – if x is not in values

Return type

Any

class FuzzyNumber(abscissa)

Bases: PieceWiseFunction

This class implements a trapezoidal fuzzy number.

A fuzzy number is described by its 4 abscissa in increasing order. Its ordinates are fixed at [0, 1, 1, 0].

Triangular fuzzy number can be represented by having two consecutive abscissa equals.

Parameters

abscissa (List[float]) – list of abscissa defining a trapezoidal fuzzy number

Raises

ValueError

  • if abscissa has not exactly 4 values

  • if abscissa are not in increasing order

__call__(x)

Apply function to single value.

Parameters

x (float) –

Raises

ValueError – if x is not inside an interval

Returns

Return type

float

property area: float

Returns the area under the fuzzy number curve.

Returns

property average: float

Computes the average of all intervals boundaries.

Returns

property centre_of_gravity: float

Computes the centre of gravity of this fuzzy set (COG).

Returns

the x value of COG

property centre_of_maximum: float

Returns the centre of maximum of this fuzzy set (COM).

Returns

property continuous: bool

Check intervals and functions are ordered and continuous.

Returns

property intervals: List[Interval]
class GaussianFunction(s)

Bases: object

This class implements the gaussian preference function.

Parameters

s (float) – standard deviation

__call__(x)

Return preference degree on a criterion of two alternatives.

Parameters

x (float) – criteria values difference

Returns

Return type

float

class Interval(dmin, dmax, min_in=True, max_in=True)

Bases: object

This class describes a numeric interval.

Parameters
  • dmin (float) – min boundary of interval

  • dmax (float) – max boundary of interval

  • min_in (bool) – is min boundary inside interval or not

  • max_in (bool) – is max boundary inside interval or not

Raises

ValueError – if dmin bigger than dmax

continuous(other)

Check continuity with following interval.

Parameters

other (Interval) –

Returns

Return type

bool

Note

Strict continuity is checked (i.e if the intervals touches without overlapping). In other words : dmax equal to other’s dmin

denormalize(x)

Denormalize normalized value inside interval.

Parameters

x (float) –

Returns

Return type

Any

intersect(other)

Compute intersection between two intervals.

Parameters

other (Interval) –

Returns

Return type

Interval or None

property is_empty: bool

Check if interval is empty.

Returns

True if interval is empty, False otherwise.

join(other)

Compute maximal junction between two intervals.

Biggest interval containing both intervals.

Parameters

other (Interval) –

Returns

Return type

Interval

normalize(x)

Normalize value inside interval.

Parameters

x (Any) –

Returns

Return type

float

union(other)

Compute union of two intervals.

Parameters

other (Interval) –

Returns

Return type

Interval

Note

Returns None if intervals don’t coïncide

class LevelFunction(p, q)

Bases: object

This class implements the level preference function.

Parameters
  • p (float) – preference threshold

  • q (float) – indifference threshold

__call__(x)

Return preference degree on a criterion of two alternatives.

Parameters

x (float) – criteria values difference

Returns

Return type

float

class PieceWiseFunction(functions=None, segments=None)

Bases: object

This class implements piecewise MCDA function.

Parameters
  • functions (Optional[Dict[Interval, Callable[[float], float]]]) –

  • segments (Optional[List[List[List]]]) – list of segments defining piecewise linear functions

Note

  • first matching interval is used to return result

  • each segment of segments is a list of two points, each point a sequence of numeric abscissa, a numeric ordinate and a bool indicating if the point is included in the underlying interval

__call__(x)

Apply function to single value.

Parameters

x (float) –

Raises

ValueError – if x is not inside an interval

Returns

Return type

float

property continuous: bool

Check intervals and functions are ordered and continuous.

Returns

property intervals: List[Interval]
class UShapeFunction(p=0)

Bases: object

This class implements the u-shape preference function.

Parameters
  • q – the indifference threshold

  • p (float) –

__call__(x)

Return preference degree on a criterion of two alternatives.

Parameters

x (float) – criteria values difference

Returns

Return type

float

class VShapeFunction(p, q=0)

Bases: object

This class implements the linear level preference function.

Parameters
  • p (float) – preference threshold

  • q (float) – indifference threshold

__call__(x)

Return preference degree on a criterion of two alternatives.

Parameters

x (float) – criteria values difference

Returns

Return type

float