lir.util module
- class lir.util.Bind[source]
Bases:
partialWrap partial to support the ellipsis (…) as a placeholder.
Can be used to fix parameters not at the end of the list of parameters (which is a limitation of partial).
- class lir.util.LR(lr, p0, p1)
Bases:
tuple- lr
Alias for field number 0
- p0
Alias for field number 1
- p1
Alias for field number 2
- lir.util.Xn_to_Xy(*Xn: ndarray) tuple[ndarray, ndarray][source]
Convert Xn to Xy format.
- Parameters:
*Xn (np.ndarray) – Variable number of arrays, where each array corresponds to a class and contains the samples for that class.
- Returns:
A tuple containing: - X: A 2D array where all samples from the input arrays are concatenated together. - y: A 1D array of the same length as the number of samples in X, where each element indicates the class label.
- Return type:
tuple[np.ndarray, np.ndarray]
- lir.util.Xy_to_Xn(X: ndarray, y: ndarray, classes: list[int] | None = None) list[ndarray][source]
Convert Xy to Xn format.
- Parameters:
X (np.ndarray) – A 2D array where rows correspond to samples and columns correspond to features.
y (np.ndarray) – A 1D array of the same length as the number of samples in X, where each element indicates the class label.
classes (list[int] | None, optional) – An optional list of class labels to be used for splitting the data. If not provided, the unique values in y will be used as class labels.
- Returns:
A list of arrays, where each array corresponds to a class and contains the samples for that class.
- Return type:
list[np.ndarray]
- lir.util.check_type(type_class: type[AnyType], v: Any, message: str | None = None) AnyType[source]
Check if a given input is of the expected, specified type. If so, return the input value.
- Parameters:
type_class (type) – The expected type of the input value.
v (Any) – The input value to be checked against the expected type.
message (str, optional) – An optional message to be included in the error if the type check fails. If not provided, a default message indicating the expected type will be used.
- Returns:
The input value v if it is of the expected type.
- Return type:
AnyType
- lir.util.get_classes_from_Xy(X: ndarray, y: ndarray, classes: list[Any] | None = None) ndarray[source]
Get the classification classes from labeled data.
- Parameters:
X (np.ndarray) – The input data array, where rows correspond to samples and columns correspond to features.
y (np.ndarray) – The target labels corresponding to each sample in X. This should be a 1-dimensional array.
classes (list[Any] | None, optional) – An optional list of classes to be used. If not provided, the unique values in y will be used.
- Returns:
An array of unique classes found in y if classes is None; otherwise, an array of the provided classes.
- Return type:
np.ndarray
- lir.util.ln_to_log10(ln_data: FloatOrArray) FloatOrArray[source]
Convert natural logarithm to 10-base logarithm.
- Parameters:
ln_data (FloatOrArray) – Data in natural logarithm form to be converted to 10-base logarithm.
- Returns:
The input data converted from natural logarithm to 10-base logarithm.
- Return type:
FloatOrArray
- lir.util.logodds_to_odds(log_odds: FloatOrArray) FloatOrArray[source]
Convert 10-base logarithm odds to odds.
- Parameters:
log_odds (FloatOrArray) – The 10-base logarithm of odds to be converted to odds.
- Returns:
The input 10-base logarithm of odds converted to odds.
- Return type:
FloatOrArray
- lir.util.logodds_to_probability(log_odds: FloatOrArray) FloatOrArray[source]
Convert 10-base logarithm of odds to probability.
- Parameters:
log_odds (FloatOrArray) – The 10-base logarithm of odds to be converted to probability.
- Returns:
The input 10-base logarithm of odds converted to probability.
- Return type:
FloatOrArray
- lir.util.odds_to_logodds(odds: FloatOrArray) FloatOrArray[source]
Convert odds to 10-base logarithm odds.
- Parameters:
odds (FloatOrArray) – The odds to be converted to 10-base logarithm odds.
- Returns:
The input odds converted to 10-base logarithm odds.
- Return type:
FloatOrArray
- lir.util.odds_to_probability(odds: FloatOrArray) FloatOrArray[source]
Convert odds to a probability.
- Parameters:
odds (FloatOrArray) – The odds to be converted to probability.
- Returns:
The input odds converted to probability. This is 1 if the input odds is infinity, and otherwise calculated as odds / (1 + odds).
- Return type:
FloatOrArray
- lir.util.probability_to_logodds(p: FloatOrArray) FloatOrArray[source]
Convert probability values to their log odds with base 10.
- Parameters:
p (FloatOrArray) – The probability values to be converted to log odds.
- Returns:
The input probability values converted to log odds with base 10.
- Return type:
FloatOrArray
- lir.util.probability_to_odds(p: FloatOrArray) FloatOrArray[source]
Convert a probability to odds.
- Parameters:
p (FloatOrArray) – The probability to be converted to odds.
- Returns:
The input probability converted to odds. This is infinity if the input probability is 1, and otherwise calculated as p / (1 - p).
- Return type:
FloatOrArray
- lir.util.to_native_dict(cfg: Any) Any[source]
Recursively convert confidence Configuration objects to native Python dicts/lists.
Accesses each value through cfg[key] to trigger reference resolution. The confidence ibrary doesn’t have a built-in method for this, so we manually traverse and resolve.
Similary to lir.config.base._expand, but this method returns native dicts/lists instead of ContextAwareDict/ContextAwareList.
- Parameters:
cfg (Any) – The input configuration object, which can be a confidence Configuration, ConfigurationSequence, dict, list, or any other type.
- Returns:
The input Configuration object converted to a native Python dict or list.
- Return type:
Any
- lir.util.validate_yaml(yaml_path: Path) None[source]
Validate a YAML file against the schema.
- Parameters:
yaml_path (Path) – The path to the YAML file to be validated.
- Raises:
FileNotFoundError – If the YAML file or the schema file does not exist.
yaml.YAMLError – If the YAML file is not valid YAML.
ValidationError – If the YAML file does not conform to the schema.