DSL
import metametric.dsl as mm
Auto¶
mm.auto[X] derives an automatic metric for type X. This is the default behavior of the @metametric decorator.
Discrete similarity¶
mm.discrete[X] constructs a discrete similarity metric for type X. That is, given that type X has method __eq__,
the metric returns 1.0 if two objects of type X are equal, and 0.0 otherwise.
Custom similarity¶
mm.from_func(f) constructs a metric from a function f: Callable[[X, X], float] that takes two arguments of the same
type and returns a float.
With preprocessing¶
mm.preprocess(g, M) is a metric that first applies a preprocessing function g: Callable[[X], Y] to both arguments,
then applies a metric f: Metric[Y] to the results.
This is the contramap operation of the metric type.
Product (dataclass) similarity¶
mm.dataclass[X](M) constructs a metric for a dataclass X by taking the product of the metrics for each of its fields
defined in M: Dict[str, Metric[Any]].
Sum (union) similarity¶
mm.union[X](M) constructs a metric for a union type X by a dictionary of each case of the union defined
in M: Dict[type, Metric[Any]].
Set matching similarity¶
mm.set_matching[X, ◇, N](f) constructs a set matching metric between two objects of type Set[X],
with \(\diamond \in \{\leftrightarrow, \to, \leftarrow, \sim\}\) as the matching constraint, and N as the normalizer.
See here for a description of matching constraints.
Latent set matching similarity¶
mm.latet_set_matching[X, ◇, N](f) constructs a latent set matching metric between two objects of type Set[X] where X has Variables.
where \(M^\diamond\) is a matching between \(X\) and \(Y\) according to the specified matching constraint, and \(M^\leftrightarrow_V\) is a one-to-one matching between the variables in \(X\) and \(Y\).
mm.latet_set_matching[X, ◇, N](f) constructs a latent set matching metric between two objects of type Set[X]
where X has Variables.
where \(M^\diamond\) is a matching between \(X\) and \(Y\) according to the specified matching constraint, and \(M^\leftrightarrow_V\) is a one-to-one matching between the variables in \(X\) and \(Y\).
Sequence matching similarity¶
Coming soon!
Graph matching similarity¶
Coming soon!