LabelizedVariable.closestIndex
- LabelizedVariable.closestIndex(val)
For numerical discrete variables (all except
pyagrum.LabelizedVariable), this method returns the index 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 index of the closest value to
valuein the variable’s domain- Return type:
int- Raises:
pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a
pyagrum.LabelizedVariable).
Example
import pyagrum as gum
c = gum.LabelizedVariable("c", "color", ["red", "green", "blue"])
c.isNumerical() # closestIndex is meaningful only for numerical variables
# False
try:
c.closestIndex(1.5)
msg = ""
except gum.NotImplementedYet as e:
msg = str(e)
msg
# '[pyAgrum] Not implemented yet: closestIndex has no meaning for LabelizedVariable'
Class