# Margins

For every Vali, there is the option of adding a positive and a negative margin. These are always defined relative to the value of the Vali, as a percentage.

For a Vali which is not using any other Valis in its formula, the values including margin are called 'worst case' and are calculated as follows:

`worstcase_plus = value * (1 + margin_plus / 100)`

`worstcase_minus = value * (1 - margin_minus / 100)`

For Valis which do use other Valis in their formulas, the margins of these used Valis are taken into account for the worst-case calculation. Two methods of margin propagation are currently supported, as explained below.

The 'total margin' represents the resulting ratio of the worst case over the actual value. For a Vali which does not use any other Valis, the total margin is the same as the positive and negative margin defined. The calculation is as follows:

`totalmargin_plus = (worstcase_plus / value - 1) * 100`

`totalmargin_minus = (worstcase_minus / value + 1) * 100`

The margin calculation is fully compatible with the unit conversion, connected copies, modes and other Valispace features.

## Margin propagation

Margin propagation between Valis that are using other Valis can be done using two algorithms: absolute worst-case propagation and linear error propagation. A configuration setting is used to change between the two (on Valispace deployment level, can be set by the administrator).

### Absolute worst case propagation (standard setting)

The absolute worst-case propagation evaluates the formula with the worst-case values of all the Valis it uses and adds the margin of the Vali itself. For negative operations in the formula, such as subtraction and division, the worst negative value is used to achieve the absolute worst case. If the same Vali is used multiple times in the same formula, the different cases are evaluated and compared to avoid overly extreme calculations (e.g. using worst-case plus in the numerator and worst-case minus in the denominator).

Vali name | Formula | Value | Margin plus | Margin minus | Worst case plus | Worst case minus |
---|---|---|---|---|---|---|

a | 10 | 10 | 10% | 10% | 11 | 9 |

b | 5 | 5 | 20% | 0% | 6 | 5 |

c | a - b | 5 | 10% | 10% | (11 - 5) * 1.1 = 6.6 | (9 - 6) * 0.9 = 2.7 |

### Linear error propagation

This option uses the Python uncertainties package, which supports uncertainty propagation following the linear error propagation theory. It assumes that all values can be represented as symmetrical Gaussian distributions. In Valispace, the centre value is considered as the average of the worst-case plus and worst-case minus values, and the uncertainty value is the distance between the centre value and the worst cases. After the propagation of the lower-level margins, the margin at the Vali level itself is added.

This way of propagating the uncertainties in general results in smaller total margins than the absolute worst-case algorithm, corresponding to a more realistic representation of the statistical probability of extreme cases. With the same inputs as the example above, this would result in a worst-case plus of 5.73 instead of 6.6, and a worst-case minus of 3.27 instead of 2.7.