tanat.metric.entity.type.combined package#

Submodules#

tanat.metric.entity.type.combined.metric module#

CombinedEntityMetric: a metric that combines several other metrics.

class tanat.metric.entity.type.combined.metric.CombinedEntityMetric(metrics_config: list[dict[str, Any]], weights: list | None = None, agg: str = 'sum')[source]#

Bases: EntityMetric

Metric between entities that involves several entity metrics to aggregate. The entity metrics can involve several entity features but also combine different manner to compare the same entity feature.

Parameters:
  • metrics_config – List of metric configuration (dictionaries). see the example below to define easily the configuration from other existing classes.

  • agg – Aggregate function name (default: ‘sum’). At the time, we only implemented the sum aggregate function.

  • weights – List of weights for the aggregation function (optional, default: None). If defined, this list must contains as much real values as the number of metrics

Example:

metric = CombinedEntityMetric(
    metrics_config=[
        L2EntityMetric(entity_feature="value").to_config(),
        HammingEntityMetric(entity_feature="status").to_config(),
    ],
    weights=[0.7, 0.3],
)

metric(ent_a, ent_b)

warning:

It is not possible to use the combined entity metric as an element of the
metrics to combine.
This prevent recursive definition of metrics that may be problematics.
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 CombinedEntityMetricSettings

__init__(metrics_config: list[dict[str, Any]], weights: list | None = None, agg: str = 'sum') None[source]#
validate_entity(ent_a: Entity, ent_b: Entity | None = None) None[source]#

Verify the configured feature exists and validate the requirements for each underlined metrics.

class tanat.metric.entity.type.combined.metric.CombinedEntityMetricSettings(*, metrics_config: list = <factory>, weights: list | None = None, agg: str = 'sum')[source]#

Bases: EntityMetricSettings

Settings for CombinedEntityMetric. The settings defines the metrics, their weights and how to aggregate them.

Parameters:
  • metrics_config – List of metric configuration (dictionaries). see the example below to define easily the configuration from other existing classes.

  • agg – Aggregate function name (default: ‘sum’). At the time, we only implemented the sum aggregate function.

  • weights – List of weights for the aggregation function (optional, default: None). If defined, this list must contains as much real values as the number of metrics

Example:

settings = CombinedEntityMetricSettings(
    metrics_config=[
        L2EntityMetric(entity_feature="value").to_config(),
        HammingEntityMetric(entity_feature="status").to_config(),
    ],
    weights=[0.7, 0.3],
)

warning:

It is not possible to use the combined entity metric as an element of the
metrics to combine.
This prevent recursive definition of metrics that may be problematics.
__init__(*args: Any, **kwargs: Any) None[source]#
agg: str = 'sum'[source]#
metrics_config: list[source]#
model_dump(*, mode='python', **dump_kwargs)[source]#

Dump settings to a dict via Pydantic serialization.

weights: list | None = None[source]#

Module contents#

L2EntityMetric package.

class tanat.metric.entity.type.combined.CombinedEntityMetric(metrics_config: list[dict[str, Any]], weights: list | None = None, agg: str = 'sum')[source]#

Bases: EntityMetric

Metric between entities that involves several entity metrics to aggregate. The entity metrics can involve several entity features but also combine different manner to compare the same entity feature.

Parameters:
  • metrics_config – List of metric configuration (dictionaries). see the example below to define easily the configuration from other existing classes.

  • agg – Aggregate function name (default: ‘sum’). At the time, we only implemented the sum aggregate function.

  • weights – List of weights for the aggregation function (optional, default: None). If defined, this list must contains as much real values as the number of metrics

Example:

metric = CombinedEntityMetric(
    metrics_config=[
        L2EntityMetric(entity_feature="value").to_config(),
        HammingEntityMetric(entity_feature="status").to_config(),
    ],
    weights=[0.7, 0.3],
)

metric(ent_a, ent_b)

warning:

It is not possible to use the combined entity metric as an element of the
metrics to combine.
This prevent recursive definition of metrics that may be problematics.
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 CombinedEntityMetricSettings

__init__(metrics_config: list[dict[str, Any]], weights: list | None = None, agg: str = 'sum') None[source]#
validate_entity(ent_a: Entity, ent_b: Entity | None = None) None[source]#

Verify the configured feature exists and validate the requirements for each underlined metrics.

class tanat.metric.entity.type.combined.CombinedEntityMetricSettings(*, metrics_config: list = <factory>, weights: list | None = None, agg: str = 'sum')[source]#

Bases: EntityMetricSettings

Settings for CombinedEntityMetric. The settings defines the metrics, their weights and how to aggregate them.

Parameters:
  • metrics_config – List of metric configuration (dictionaries). see the example below to define easily the configuration from other existing classes.

  • agg – Aggregate function name (default: ‘sum’). At the time, we only implemented the sum aggregate function.

  • weights – List of weights for the aggregation function (optional, default: None). If defined, this list must contains as much real values as the number of metrics

Example:

settings = CombinedEntityMetricSettings(
    metrics_config=[
        L2EntityMetric(entity_feature="value").to_config(),
        HammingEntityMetric(entity_feature="status").to_config(),
    ],
    weights=[0.7, 0.3],
)

warning:

It is not possible to use the combined entity metric as an element of the
metrics to combine.
This prevent recursive definition of metrics that may be problematics.
__init__(*args: Any, **kwargs: Any) None[source]#
agg: str = 'sum'[source]#
metrics_config: list[source]#
model_dump(*, mode='python', **dump_kwargs)[source]#

Dump settings to a dict via Pydantic serialization.

weights: list | None = None[source]#