Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Shared validators and converters for container attrs classes.

Functions:

NameDescription
convert_corr_to_dictConvert correlation specification to dictionary format.
is_choice_strBuild a validator for a string constrained to a fixed set of choices.
is_conf_levelValidate that a value is a normalized confidence level in (0, 1).
is_ndarrayValidate that a value is a numpy ndarray.
is_nonnegative_intValidate that a value is a non-negative integer.
is_optional_conf_levelValidate that a value is a normalized confidence level or None.
is_optional_intValidate that a value is an int or None.
is_optional_ndarrayValidate that a value is a numpy ndarray or None.
is_optional_positive_intValidate that a value is a positive integer or None.
is_optional_sparse_cscValidate that a value is a scipy.sparse.csc_matrix or None.
is_optional_strValidate that a value is a string or None.
is_optional_str_key_dictValidate that a value is a dict with string keys or None.
is_optional_tuple_of_strValidate that a value is a tuple of strings or None.
is_positive_intValidate that a value is a positive integer.
is_tuple_of_strValidate that a value is a tuple of strings.
normalize_conf_levelNormalize conf_level to a float in (0, 1).
normalize_optional_conf_levelNormalize an optional confidence level.
to_factor_dictConvert factor dict values from lists to tuples.
to_frozen_dictEnsure dict values are tuples where applicable.
to_optional_tupleConvert an optional list of strings to a tuple.
to_tupleConvert list to tuple for immutability.
to_tuple_of_tuplesConvert dict values to tuples for immutability.
validate_correlationsValidate correlation values are in [-1, 1].
validate_sigmaValidate sigma is non-negative.
validate_slope_sdsValidate slope SDs are non-negative.

Functions

convert_corr_to_dict

convert_corr_to_dict(corr: float | dict[tuple[str, str], float], slope_sds: dict[str, float]) -> dict[tuple[str, str], float]

Convert correlation specification to dictionary format.

Parameters:

NameTypeDescriptionDefault
corrfloat | dict[tuple[str, str], float]Correlation as single value or dict.required
slope_sdsdict[str, float]Dictionary of slope SDs (to determine term names).required

Returns:

TypeDescription
dict[tuple[str, str], float]Dictionary mapping term pairs to correlations.

is_choice_str

is_choice_str(choices: tuple[str, ...])

Build a validator for a string constrained to a fixed set of choices.

is_conf_level

is_conf_level(instance: object, attribute: object, value: object) -> None

Validate that a value is a normalized confidence level in (0, 1).

is_ndarray

is_ndarray(instance: object, attribute: object, value: object) -> None

Validate that a value is a numpy ndarray.

is_nonnegative_int

is_nonnegative_int(instance: object, attribute: object, value: object) -> None

Validate that a value is a non-negative integer.

is_optional_conf_level

is_optional_conf_level(instance: object, attribute: object, value: object) -> None

Validate that a value is a normalized confidence level or None.

is_optional_int

is_optional_int(instance: object, attribute: object, value: object) -> None

Validate that a value is an int or None.

is_optional_ndarray

is_optional_ndarray(instance: object, attribute: object, value: object) -> None

Validate that a value is a numpy ndarray or None.

is_optional_positive_int

is_optional_positive_int(instance: object, attribute: object, value: object) -> None

Validate that a value is a positive integer or None.

is_optional_sparse_csc

is_optional_sparse_csc(instance: object, attribute: object, value: object) -> None

Validate that a value is a scipy.sparse.csc_matrix or None.

is_optional_str

is_optional_str(instance: object, attribute: object, value: object) -> None

Validate that a value is a string or None.

is_optional_str_key_dict

is_optional_str_key_dict(instance: object, attribute: object, value: object) -> None

Validate that a value is a dict with string keys or None.

is_optional_tuple_of_str

is_optional_tuple_of_str(instance: object, attribute: object, value: object) -> None

Validate that a value is a tuple of strings or None.

is_positive_int

is_positive_int(instance: object, attribute: object, value: object) -> None

Validate that a value is a positive integer.

is_tuple_of_str

is_tuple_of_str(instance: object, attribute: object, value: object) -> None

Validate that a value is a tuple of strings.

normalize_conf_level

normalize_conf_level(conf_level: float | int | str) -> float

Normalize conf_level to a float in (0, 1).

Parameters:

NameTypeDescriptionDefault
conf_levelfloat | int | strConfidence level in any supported format.required

Returns:

TypeDescription
floatConfidence level as a float strictly between 0 and 1 (exclusive).

normalize_optional_conf_level

normalize_optional_conf_level(conf_level: float | int | str | None) -> float | None

Normalize an optional confidence level.

to_factor_dict

to_factor_dict(val: Any) -> dict[str, tuple[str, ...]]

Convert factor dict values from lists to tuples.

to_frozen_dict

to_frozen_dict(val: Any) -> dict

Ensure dict values are tuples where applicable.

to_optional_tuple

to_optional_tuple(value: tuple[str, ...] | list[str] | None) -> tuple[str, ...] | None

Convert an optional list of strings to a tuple.

to_tuple

to_tuple(value: tuple[str, ...] | list[str]) -> tuple[str, ...]

Convert list to tuple for immutability.

to_tuple_of_tuples

to_tuple_of_tuples(value: dict[str, tuple[str, ...] | list[str]] | None) -> dict[str, tuple[str, ...]]

Convert dict values to tuples for immutability.

validate_correlations

validate_correlations(instance: Any, attribute: Any, value: dict[tuple[str, str], float]) -> None

Validate correlation values are in [-1, 1].

validate_sigma

validate_sigma(instance: Any, attribute: Any, value: float) -> None

Validate sigma is non-negative.

validate_slope_sds

validate_slope_sds(instance: Any, attribute: Any, value: dict[str, float]) -> None

Validate slope SDs are non-negative.