IntegerVariable.closestLabel

IntegerVariable.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 val in 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

n = gum.IntegerVariable("n", "n", [1, 3, 10])
n.closestLabel(7)
# '10'

Class

IntegerVariable