Skip to content

Class swarmauri_core.similarities.ISimilarity.ISimilarity

swarmauri_core.similarities.ISimilarity.ISimilarity

Bases: ABC

Interface for abstract similarity measures.

This interface defines methods for computing similarity and dissimilarity between various data types including vectors, matrices, sequences, and callable objects. It supports both direction-based and bounded comparisons.

Similarity measures quantify how alike two objects are, with higher values indicating greater similarity. Dissimilarity measures represent the opposite.

similarity abstractmethod

similarity(x, y)

Calculate the similarity between two objects.

Parameters

x : ComparableType First object to compare y : ComparableType Second object to compare

Returns

float Similarity score between x and y

Raises

ValueError If the objects are incomparable or have incompatible dimensions TypeError If the input types are not supported

Source code in swarmauri_core/similarities/ISimilarity.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@abstractmethod
def similarity(self, x: ComparableType, y: ComparableType) -> float:
    """
    Calculate the similarity between two objects.

    Parameters
    ----------
    x : ComparableType
        First object to compare
    y : ComparableType
        Second object to compare

    Returns
    -------
    float
        Similarity score between x and y

    Raises
    ------
    ValueError
        If the objects are incomparable or have incompatible dimensions
    TypeError
        If the input types are not supported
    """
    pass

similarities abstractmethod

similarities(x, ys)

Calculate similarities between one object and multiple other objects.

Parameters

x : ComparableType Reference object ys : Sequence[ComparableType] Sequence of objects to compare against the reference

Returns

List[float] List of similarity scores between x and each element in ys

Raises

ValueError If any objects are incomparable or have incompatible dimensions TypeError If any input types are not supported

Source code in swarmauri_core/similarities/ISimilarity.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@abstractmethod
def similarities(
    self, x: ComparableType, ys: Sequence[ComparableType]
) -> List[float]:
    """
    Calculate similarities between one object and multiple other objects.

    Parameters
    ----------
    x : ComparableType
        Reference object
    ys : Sequence[ComparableType]
        Sequence of objects to compare against the reference

    Returns
    -------
    List[float]
        List of similarity scores between x and each element in ys

    Raises
    ------
    ValueError
        If any objects are incomparable or have incompatible dimensions
    TypeError
        If any input types are not supported
    """
    pass

dissimilarity abstractmethod

dissimilarity(x, y)

Calculate the dissimilarity between two objects.

Parameters

x : ComparableType First object to compare y : ComparableType Second object to compare

Returns

float Dissimilarity score between x and y

Raises

ValueError If the objects are incomparable or have incompatible dimensions TypeError If the input types are not supported

Source code in swarmauri_core/similarities/ISimilarity.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
@abstractmethod
def dissimilarity(self, x: ComparableType, y: ComparableType) -> float:
    """
    Calculate the dissimilarity between two objects.

    Parameters
    ----------
    x : ComparableType
        First object to compare
    y : ComparableType
        Second object to compare

    Returns
    -------
    float
        Dissimilarity score between x and y

    Raises
    ------
    ValueError
        If the objects are incomparable or have incompatible dimensions
    TypeError
        If the input types are not supported
    """
    pass

dissimilarities abstractmethod

dissimilarities(x, ys)

Calculate dissimilarities between one object and multiple other objects.

Parameters

x : ComparableType Reference object ys : Sequence[ComparableType] Sequence of objects to compare against the reference

Returns

List[float] List of dissimilarity scores between x and each element in ys

Raises

ValueError If any objects are incomparable or have incompatible dimensions TypeError If any input types are not supported

Source code in swarmauri_core/similarities/ISimilarity.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@abstractmethod
def dissimilarities(
    self, x: ComparableType, ys: Sequence[ComparableType]
) -> List[float]:
    """
    Calculate dissimilarities between one object and multiple other objects.

    Parameters
    ----------
    x : ComparableType
        Reference object
    ys : Sequence[ComparableType]
        Sequence of objects to compare against the reference

    Returns
    -------
    List[float]
        List of dissimilarity scores between x and each element in ys

    Raises
    ------
    ValueError
        If any objects are incomparable or have incompatible dimensions
    TypeError
        If any input types are not supported
    """
    pass

check_bounded abstractmethod

check_bounded()

Check if the similarity measure is bounded.

A bounded similarity measure has values within a fixed range, typically [0,1] for similarities.

Returns

bool True if the similarity measure is bounded, False otherwise

Source code in swarmauri_core/similarities/ISimilarity.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@abstractmethod
def check_bounded(self) -> bool:
    """
    Check if the similarity measure is bounded.

    A bounded similarity measure has values within a fixed range,
    typically [0,1] for similarities.

    Returns
    -------
    bool
        True if the similarity measure is bounded, False otherwise
    """
    pass

check_reflexivity abstractmethod

check_reflexivity(x)

Check if the similarity measure is reflexive: s(x,x) = 1.

Parameters

x : ComparableType Object to check reflexivity with

Returns

bool True if s(x,x) = 1, False otherwise

Raises

TypeError If the input type is not supported

Source code in swarmauri_core/similarities/ISimilarity.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@abstractmethod
def check_reflexivity(self, x: ComparableType) -> bool:
    """
    Check if the similarity measure is reflexive: s(x,x) = 1.

    Parameters
    ----------
    x : ComparableType
        Object to check reflexivity with

    Returns
    -------
    bool
        True if s(x,x) = 1, False otherwise

    Raises
    ------
    TypeError
        If the input type is not supported
    """
    pass

check_symmetry abstractmethod

check_symmetry(x, y)

Check if the similarity measure is symmetric: s(x,y) = s(y,x).

Parameters

x : ComparableType First object to compare y : ComparableType Second object to compare

Returns

bool True if s(x,y) = s(y,x), False otherwise

Raises

ValueError If the objects are incomparable or have incompatible dimensions TypeError If the input types are not supported

Source code in swarmauri_core/similarities/ISimilarity.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
@abstractmethod
def check_symmetry(self, x: ComparableType, y: ComparableType) -> bool:
    """
    Check if the similarity measure is symmetric: s(x,y) = s(y,x).

    Parameters
    ----------
    x : ComparableType
        First object to compare
    y : ComparableType
        Second object to compare

    Returns
    -------
    bool
        True if s(x,y) = s(y,x), False otherwise

    Raises
    ------
    ValueError
        If the objects are incomparable or have incompatible dimensions
    TypeError
        If the input types are not supported
    """
    pass

check_identity_of_discernibles abstractmethod

check_identity_of_discernibles(x, y)

Check if the similarity measure satisfies the identity of discernibles: s(x,y) = 1 ⟺ x = y.

Parameters

x : ComparableType First object to compare y : ComparableType Second object to compare

Returns

bool True if the identity of discernibles property holds, False otherwise

Raises

ValueError If the objects are incomparable or have incompatible dimensions TypeError If the input types are not supported

Source code in swarmauri_core/similarities/ISimilarity.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@abstractmethod
def check_identity_of_discernibles(
    self, x: ComparableType, y: ComparableType
) -> bool:
    """
    Check if the similarity measure satisfies the identity of discernibles: s(x,y) = 1 ⟺ x = y.

    Parameters
    ----------
    x : ComparableType
        First object to compare
    y : ComparableType
        Second object to compare

    Returns
    -------
    bool
        True if the identity of discernibles property holds, False otherwise

    Raises
    ------
    ValueError
        If the objects are incomparable or have incompatible dimensions
    TypeError
        If the input types are not supported
    """
    pass