DiscreteVariable.closestLabel
- DiscreteVariable.closestLabel(val)
For numerical discrete variables (all except
pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.- Parameters:
val (
float) – the value for which we want to find the closest index- Returns:
the label of the closest value to
valin the variable’s domain- Return type:
str- Raises:
pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a
pyagrum.LabelizedVariable).
Example
import pyagrum as gum
v = gum.fastVariable("x{1|3|10}")
v.closestLabel(4.2)
# '3'
Used by
DiscreteVariable, DiscretizedVariable, LabelizedVariable, RangeVariable

Overridden in
IntegerVariable.closestLabel, NumericalDiscreteVariable.closestLabel