tanat.metric.entity.type.l2_metric package#

Submodules#

tanat.metric.entity.type.l2_metric.metric module#

L2EntityMetric: numerical feature distance by L2 distance.

class tanat.metric.entity.type.l2_metric.metric.L2EntityMetric(entity_feature: str | None = None, nan_cost: float = 1.0, normalize: bool = True)[source]#

Bases: EntityMetric

Numerical distance between two entities evaluated as the squared difference of values (no square root applied).

Returns the L2 distance between feature values when both are defined, and nan_cost value in case there is a NaN.

If no entity_feature provided when the metric is created, a feature will be defined automatically as the first numerical attribute found when the metric is applied a first time to an entity. The updated feature name is then frozen for future usages. If there is no numerical attribute, an error is raised.

Example:

metric = L2EntityMetric(
    entity_feature="value",
    nan_cost=0.8,
)
metric(ent_a, ent_b)

The normalized version of the L2 metric evaluate the quantity $ rac{(f_1-f_2)^2}{f_1^2+f_2^2}$ that is between 0 (when $f_1$ equals $f_2$) and 1 (when $f_1$ is null for instance).

NUMBA_OPTIM: bool = False[source]#

Subclasses that provide prepare_batch_data / distance_kernel / prepare_cross_batch_data set this to True to opt into the Numba fast path.

SETTINGS_CLASS[source]#

alias of L2Settings

__init__(entity_feature: str | None = None, nan_cost: float = 1.0, normalize: bool = True) None[source]#
validate_entity(ent_a: Entity, ent_b: Entity | None = None) None[source]#

Verify the configured feature exists and is numerical.

class tanat.metric.entity.type.l2_metric.metric.L2Settings(*, entity_feature: str | None = None, nan_cost: float = 1.0, normalize: bool = True)[source]#

Bases: EntityMetricSettings

Settings for L2EntityMetric.

Parameters:
  • entity_feature – Name of the numerical feature to compare. None - first entity feature from the pool/entity metadata.

  • nan_cost – Default cost applied when at least one value is NaN (default: 1.0).

  • normalize – Compute the absolute relative difference of the values to ensure to have a value between 0 and 1.

__init__(*args: Any, **kwargs: Any) None[source]#
entity_feature: str | None = None[source]#
model_dump(*, mode='python', **dump_kwargs)[source]#

Dump settings to a dict via Pydantic serialization.

nan_cost: float = 1.0[source]#
normalize: bool = True[source]#

Module contents#

L2EntityMetric package.

class tanat.metric.entity.type.l2_metric.L2EntityMetric(entity_feature: str | None = None, nan_cost: float = 1.0, normalize: bool = True)[source]#

Bases: EntityMetric

Numerical distance between two entities evaluated as the squared difference of values (no square root applied).

Returns the L2 distance between feature values when both are defined, and nan_cost value in case there is a NaN.

If no entity_feature provided when the metric is created, a feature will be defined automatically as the first numerical attribute found when the metric is applied a first time to an entity. The updated feature name is then frozen for future usages. If there is no numerical attribute, an error is raised.

Example:

metric = L2EntityMetric(
    entity_feature="value",
    nan_cost=0.8,
)
metric(ent_a, ent_b)

The normalized version of the L2 metric evaluate the quantity $ rac{(f_1-f_2)^2}{f_1^2+f_2^2}$ that is between 0 (when $f_1$ equals $f_2$) and 1 (when $f_1$ is null for instance).

NUMBA_OPTIM: bool = False[source]#

Subclasses that provide prepare_batch_data / distance_kernel / prepare_cross_batch_data set this to True to opt into the Numba fast path.

SETTINGS_CLASS[source]#

alias of L2Settings

__init__(entity_feature: str | None = None, nan_cost: float = 1.0, normalize: bool = True) None[source]#
validate_entity(ent_a: Entity, ent_b: Entity | None = None) None[source]#

Verify the configured feature exists and is numerical.

class tanat.metric.entity.type.l2_metric.L2Settings(*, entity_feature: str | None = None, nan_cost: float = 1.0, normalize: bool = True)[source]#

Bases: EntityMetricSettings

Settings for L2EntityMetric.

Parameters:
  • entity_feature – Name of the numerical feature to compare. None - first entity feature from the pool/entity metadata.

  • nan_cost – Default cost applied when at least one value is NaN (default: 1.0).

  • normalize – Compute the absolute relative difference of the values to ensure to have a value between 0 and 1.

__init__(*args: Any, **kwargs: Any) None[source]#
entity_feature: str | None = None[source]#
model_dump(*, mode='python', **dump_kwargs)[source]#

Dump settings to a dict via Pydantic serialization.

nan_cost: float = 1.0[source]#
normalize: bool = True[source]#