Skip to content

Class swarmauri_core.metrics.IMetric.IMetric

swarmauri_core.metrics.IMetric.IMetric

Bases: ABC

Interface for proper metric spaces.

This interface defines the contract enforcing the full metric axioms: - Non-negativity: d(x,y) ≥ 0 - Identity of indiscernibles (point separation): d(x,y) = 0 if and only if x = y - Symmetry: d(x,y) = d(y,x) - Triangle inequality: d(x,z) ≤ d(x,y) + d(y,z)

Implementations must support various input types including vectors, matrices, sequences, strings, and callables.

distance abstractmethod

distance(x, y)

Calculate the distance between two points.

Parameters

x : MetricInput First point y : MetricInput Second point

Returns

float The distance between x and y

Raises

ValueError If inputs are incompatible with the metric TypeError If input types are not supported

Source code in swarmauri_core/metrics/IMetric.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@abstractmethod
def distance(self, x: MetricInput, y: MetricInput) -> float:
    """
    Calculate the distance between two points.

    Parameters
    ----------
    x : MetricInput
        First point
    y : MetricInput
        Second point

    Returns
    -------
    float
        The distance between x and y

    Raises
    ------
    ValueError
        If inputs are incompatible with the metric
    TypeError
        If input types are not supported
    """
    pass

distances abstractmethod

distances(x, y)

Calculate distances between collections of points.

Parameters

x : Union[MetricInput, MetricInputCollection] First collection of points y : Union[MetricInput, MetricInputCollection] Second collection of points

Returns

Union[List[float], IVector, IMatrix] Matrix or vector of distances between points in x and y

Raises

ValueError If inputs are incompatible with the metric TypeError If input types are not supported

Source code in swarmauri_core/metrics/IMetric.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@abstractmethod
def distances(
    self,
    x: Union[MetricInput, MetricInputCollection],
    y: Union[MetricInput, MetricInputCollection],
) -> Union[List[float], IVector, IMatrix]:
    """
    Calculate distances between collections of points.

    Parameters
    ----------
    x : Union[MetricInput, MetricInputCollection]
        First collection of points
    y : Union[MetricInput, MetricInputCollection]
        Second collection of points

    Returns
    -------
    Union[List[float], IVector, IMatrix]
        Matrix or vector of distances between points in x and y

    Raises
    ------
    ValueError
        If inputs are incompatible with the metric
    TypeError
        If input types are not supported
    """
    pass

check_non_negativity abstractmethod

check_non_negativity(x, y)

Check if the metric satisfies the non-negativity axiom: d(x,y) ≥ 0.

Parameters

x : MetricInput First point y : MetricInput Second point

Returns

bool True if the axiom is satisfied, False otherwise

Source code in swarmauri_core/metrics/IMetric.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@abstractmethod
def check_non_negativity(self, x: MetricInput, y: MetricInput) -> bool:
    """
    Check if the metric satisfies the non-negativity axiom: d(x,y) ≥ 0.

    Parameters
    ----------
    x : MetricInput
        First point
    y : MetricInput
        Second point

    Returns
    -------
    bool
        True if the axiom is satisfied, False otherwise
    """
    pass

check_identity_of_indiscernibles abstractmethod

check_identity_of_indiscernibles(x, y)

Check if the metric satisfies the identity of indiscernibles axiom: d(x,y) = 0 if and only if x = y.

Parameters

x : MetricInput First point y : MetricInput Second point

Returns

bool True if the axiom is satisfied, False otherwise

Source code in swarmauri_core/metrics/IMetric.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@abstractmethod
def check_identity_of_indiscernibles(self, x: MetricInput, y: MetricInput) -> bool:
    """
    Check if the metric satisfies the identity of indiscernibles axiom:
    d(x,y) = 0 if and only if x = y.

    Parameters
    ----------
    x : MetricInput
        First point
    y : MetricInput
        Second point

    Returns
    -------
    bool
        True if the axiom is satisfied, False otherwise
    """
    pass

check_symmetry abstractmethod

check_symmetry(x, y)

Check if the metric satisfies the symmetry axiom: d(x,y) = d(y,x).

Parameters

x : MetricInput First point y : MetricInput Second point

Returns

bool True if the axiom is satisfied, False otherwise

Source code in swarmauri_core/metrics/IMetric.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@abstractmethod
def check_symmetry(self, x: MetricInput, y: MetricInput) -> bool:
    """
    Check if the metric satisfies the symmetry axiom: d(x,y) = d(y,x).

    Parameters
    ----------
    x : MetricInput
        First point
    y : MetricInput
        Second point

    Returns
    -------
    bool
        True if the axiom is satisfied, False otherwise
    """
    pass

check_triangle_inequality abstractmethod

check_triangle_inequality(x, y, z)

Check if the metric satisfies the triangle inequality axiom: d(x,z) ≤ d(x,y) + d(y,z).

Parameters

x : MetricInput First point y : MetricInput Second point z : MetricInput Third point

Returns

bool True if the axiom is satisfied, False otherwise

Source code in swarmauri_core/metrics/IMetric.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@abstractmethod
def check_triangle_inequality(
    self, x: MetricInput, y: MetricInput, z: MetricInput
) -> bool:
    """
    Check if the metric satisfies the triangle inequality axiom:
    d(x,z) ≤ d(x,y) + d(y,z).

    Parameters
    ----------
    x : MetricInput
        First point
    y : MetricInput
        Second point
    z : MetricInput
        Third point

    Returns
    -------
    bool
        True if the axiom is satisfied, False otherwise
    """
    pass