Skip to content

abstract

  • Name: cognitivefactory.interactive_clustering.constraints.abstract
  • Description: The abstract class used to define constraints managing algorithms.
  • Author: Erwan SCHILD
  • Created: 17/03/2021
  • Licence: CeCILL-C License v1.0 (https://cecill.info/licences.fr.html)

AbstractConstraintsManager

Bases: ABC

Abstract class that is used to define constraints manager. The main inherited methods are about data IDs management, constraints management and constraints exploration.

References
  • Constraints in clustering: Wagstaff, K. et C. Cardie (2000). Clustering with Instance-level Constraints. Proceedings of the Seventeenth International Conference on Machine Learning, 1103–1110.
Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
 22
 23
 24
 25
 26
 27
 28
 29
 30
 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
 56
 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
 84
 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
110
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
201
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
class AbstractConstraintsManager(ABC):
    """
    Abstract class that is used to define constraints manager.
    The main inherited methods are about data IDs management, constraints management and constraints exploration.

    References:
        - Constraints in clustering: `Wagstaff, K. et C. Cardie (2000). Clustering with Instance-level Constraints. Proceedings of the Seventeenth International Conference on Machine Learning, 1103–1110.`
    """

    # ==============================================================================
    # ABSTRACT METHOD - DATA_ID MANAGEMENT
    # ==============================================================================
    @abstractmethod
    def add_data_ID(
        self,
        data_ID: str,
    ) -> bool:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to add a new data ID to manage.

        Args:
            data_ID (str): The data ID to manage.

        Raises:
            ValueError: if `data_ID` is already managed.

        Returns:
            bool: `True` if the addition is done.
        """

    @abstractmethod
    def delete_data_ID(
        self,
        data_ID: str,
    ) -> bool:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to delete a data ID to no longer manage.

        Args:
            data_ID (str): The data ID to no longer manage.

        Raises:
            ValueError: if `data_ID` is not managed.

        Returns:
            bool: `True` if the deletion is done.
        """

    @abstractmethod
    def get_list_of_managed_data_IDs(
        self,
    ) -> List[str]:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to get the list of data IDs that are managed.

        Returns:
            List[str]: The list of data IDs that are managed.
        """

    # ==============================================================================
    # ABSTRACT METHOD - CONSTRAINTS MANAGEMENT
    # ==============================================================================
    @abstractmethod
    def add_constraint(
        self,
        data_ID1: str,
        data_ID2: str,
        constraint_type: str,
        constraint_value: float = 1.0,
    ) -> bool:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to add a constraint between two data IDs.

        Args:
            data_ID1 (str): The first data ID that is concerned for this constraint addition.
            data_ID2 (str): The second data ID that is concerned for this constraint addition.
            constraint_type (str): The type of the constraint to add. The type have to be `"MUST_LINK"` or `"CANNOT_LINK"`.
            constraint_value (float, optional): The value of the constraint to add. The value have to be in range `[0.0, 1.0]`. Defaults to 1.0.

        Raises:
            ValueError: if `data_ID1`, `data_ID2`, `constraint_type` are not managed, or if a conflict is detected with constraints inference.

        Returns:
            bool: `True` if the addition is done, `False` is the constraint can't be added.
        """

    @abstractmethod
    def delete_constraint(
        self,
        data_ID1: str,
        data_ID2: str,
    ) -> bool:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to delete the constraint between two data IDs.

        Args:
            data_ID1 (str): The first data ID that is concerned for this constraint deletion.
            data_ID2 (str): The second data ID that is concerned for this constraint deletion.

        Raises:
            ValueError: if `data_ID1` or `data_ID2` are not managed.

        Returns:
            bool: `True` if the deletion is done.
        """

    @abstractmethod
    def get_added_constraint(
        self,
        data_ID1: str,
        data_ID2: str,
    ) -> Optional[Tuple[str, float]]:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to get the constraint added between the two data IDs.
        Do not take into account the constraints transitivity, just look at constraints that are explicitly added.

        Args:
            data_ID1 (str): The first data ID that is concerned for this constraint.
            data_ID2 (str): The second data ID that is concerned for this constraint.

        Raises:
            ValueError: if `data_ID1` or `data_ID2` are not managed.

        Returns:
            Optional[Tuple[str, float]]: `None` if no constraint, `(constraint_type, constraint_value)` otherwise.
        """

    # ==============================================================================
    # ABSTRACT METHOD - CONSTRAINTS EXPLORATION
    # ==============================================================================
    @abstractmethod
    def get_inferred_constraint(
        self,
        data_ID1: str,
        data_ID2: str,
        threshold: float = 1.0,
    ) -> Optional[str]:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to check if the constraint inferred by transitivity between the two data IDs.
        The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

        Args:
            data_ID1 (str): The first data ID that is concerned for this constraint.
            data_ID2 (str): The second data ID that is concerned for this constraint.
            threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

        Raises:
            ValueError: if `data_ID1`, `data_ID2` or `threshold` are not managed.

        Returns:
            Optional[str]: The type of the inferred constraint. The type can be `None`, `"MUST_LINK"` or `"CANNOT_LINK"`.
        """

    @abstractmethod
    def get_connected_components(
        self,
        threshold: float = 1.0,
    ) -> List[List[str]]:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to get the possible lists of data IDs that are connected by a `"MUST_LINK"` constraints.
        Each list forms a component of the constraints transitivity graph, and it forms a partition of the managed data IDs.
        The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

        Args:
            threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

        Raises:
            ValueError: if `threshold` is not managed.

        Returns:
            List[List[int]]: The list of lists of data IDs that represent a component of the constraints transitivity graph.
        """

    @abstractmethod
    def check_completude_of_constraints(
        self,
        threshold: float = 1.0,
    ) -> bool:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to check if all possible constraints are known (not necessarily annotated because of the transitivity).
        The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

        Args:
            threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

        Raises:
            ValueError: if `threshold` is not managed.

        Returns:
            bool: Return `True` if all constraints are known, `False` otherwise.
        """

    @abstractmethod
    def get_min_and_max_number_of_clusters(
        self,
        threshold: float = 1.0,
    ) -> Tuple[int, int]:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to get determine, for a clustering model that would not violate any constraints, the range of the possible clusters number.
        The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

        Args:
            threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

        Raises:
            ValueError: if `threshold` is not managed.

        Returns:
            Tuple[int,int]: The minimum and the maximum possible clusters numbers (for a clustering model that would not violate any constraints).
        """

    # ==============================================================================
    # ABSTRACT METHOD - CONSTRAINTS CONFLICT
    # ==============================================================================

    @abstractmethod
    def get_list_of_involved_data_IDs_in_a_constraint_conflict(
        self,
        data_ID1: str,
        data_ID2: str,
        constraint_type: str,
    ) -> Optional[List[str]]:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to get all data IDs involved in a constraints conflict.

        Args:
            data_ID1 (str): The first data ID involved in the constraint_conflit.
            data_ID2 (str): The second data ID involved in the constraint_conflit.
            constraint_type (str): The constraint that create a conflict. The constraints can be `"MUST_LINK"` or `"CANNOT_LINK"`.

        Raises:
            ValueError: if `data_ID1`, `data_ID2`, `constraint_type` are not managed.

        Returns:
            Optional[List[str]]: The list of data IDs that are involved in the conflict. It matches data IDs from connected components of `data_ID1` and `data_ID2`.
        """

    # ==============================================================================
    # ABSTRACT METHOD - SERIALIZATION
    # ==============================================================================
    @abstractmethod
    def to_json(
        self,
        filepath: str,
    ) -> bool:
        """
        (ABSTRACT METHOD)
        An abstract method that represents the main method used to serialize the constraints manager object into a JSON file.

        Args:
            filepath (str): The path where to serialize the constraints manager  object.

        Returns:
            bool: `True` if the serialization is done.
        """

add_constraint(data_ID1, data_ID2, constraint_type, constraint_value=1.0) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to add a constraint between two data IDs.

Parameters:

Name Type Description Default
data_ID1 str

The first data ID that is concerned for this constraint addition.

required
data_ID2 str

The second data ID that is concerned for this constraint addition.

required
constraint_type str

The type of the constraint to add. The type have to be "MUST_LINK" or "CANNOT_LINK".

required
constraint_value float

The value of the constraint to add. The value have to be in range [0.0, 1.0]. Defaults to 1.0.

1.0

Raises:

Type Description
ValueError

if data_ID1, data_ID2, constraint_type are not managed, or if a conflict is detected with constraints inference.

Returns:

Name Type Description
bool bool

True if the addition is done, False is the constraint can't be added.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
@abstractmethod
def add_constraint(
    self,
    data_ID1: str,
    data_ID2: str,
    constraint_type: str,
    constraint_value: float = 1.0,
) -> bool:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to add a constraint between two data IDs.

    Args:
        data_ID1 (str): The first data ID that is concerned for this constraint addition.
        data_ID2 (str): The second data ID that is concerned for this constraint addition.
        constraint_type (str): The type of the constraint to add. The type have to be `"MUST_LINK"` or `"CANNOT_LINK"`.
        constraint_value (float, optional): The value of the constraint to add. The value have to be in range `[0.0, 1.0]`. Defaults to 1.0.

    Raises:
        ValueError: if `data_ID1`, `data_ID2`, `constraint_type` are not managed, or if a conflict is detected with constraints inference.

    Returns:
        bool: `True` if the addition is done, `False` is the constraint can't be added.
    """

add_data_ID(data_ID) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to add a new data ID to manage.

Parameters:

Name Type Description Default
data_ID str

The data ID to manage.

required

Raises:

Type Description
ValueError

if data_ID is already managed.

Returns:

Name Type Description
bool bool

True if the addition is done.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@abstractmethod
def add_data_ID(
    self,
    data_ID: str,
) -> bool:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to add a new data ID to manage.

    Args:
        data_ID (str): The data ID to manage.

    Raises:
        ValueError: if `data_ID` is already managed.

    Returns:
        bool: `True` if the addition is done.
    """

check_completude_of_constraints(threshold=1.0) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to check if all possible constraints are known (not necessarily annotated because of the transitivity). The transitivity is taken into account, and the threshold parameter is used to evaluate the impact of constraints transitivity.

Parameters:

Name Type Description Default
threshold float

The threshold used to evaluate the impact of constraints transitivity link. Defaults to 1.0.

1.0

Raises:

Type Description
ValueError

if threshold is not managed.

Returns:

Name Type Description
bool bool

Return True if all constraints are known, False otherwise.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@abstractmethod
def check_completude_of_constraints(
    self,
    threshold: float = 1.0,
) -> bool:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to check if all possible constraints are known (not necessarily annotated because of the transitivity).
    The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

    Args:
        threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

    Raises:
        ValueError: if `threshold` is not managed.

    Returns:
        bool: Return `True` if all constraints are known, `False` otherwise.
    """

delete_constraint(data_ID1, data_ID2) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to delete the constraint between two data IDs.

Parameters:

Name Type Description Default
data_ID1 str

The first data ID that is concerned for this constraint deletion.

required
data_ID2 str

The second data ID that is concerned for this constraint deletion.

required

Raises:

Type Description
ValueError

if data_ID1 or data_ID2 are not managed.

Returns:

Name Type Description
bool bool

True if the deletion is done.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@abstractmethod
def delete_constraint(
    self,
    data_ID1: str,
    data_ID2: str,
) -> bool:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to delete the constraint between two data IDs.

    Args:
        data_ID1 (str): The first data ID that is concerned for this constraint deletion.
        data_ID2 (str): The second data ID that is concerned for this constraint deletion.

    Raises:
        ValueError: if `data_ID1` or `data_ID2` are not managed.

    Returns:
        bool: `True` if the deletion is done.
    """

delete_data_ID(data_ID) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to delete a data ID to no longer manage.

Parameters:

Name Type Description Default
data_ID str

The data ID to no longer manage.

required

Raises:

Type Description
ValueError

if data_ID is not managed.

Returns:

Name Type Description
bool bool

True if the deletion is done.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@abstractmethod
def delete_data_ID(
    self,
    data_ID: str,
) -> bool:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to delete a data ID to no longer manage.

    Args:
        data_ID (str): The data ID to no longer manage.

    Raises:
        ValueError: if `data_ID` is not managed.

    Returns:
        bool: `True` if the deletion is done.
    """

get_added_constraint(data_ID1, data_ID2) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to get the constraint added between the two data IDs. Do not take into account the constraints transitivity, just look at constraints that are explicitly added.

Parameters:

Name Type Description Default
data_ID1 str

The first data ID that is concerned for this constraint.

required
data_ID2 str

The second data ID that is concerned for this constraint.

required

Raises:

Type Description
ValueError

if data_ID1 or data_ID2 are not managed.

Returns:

Type Description
Optional[Tuple[str, float]]

Optional[Tuple[str, float]]: None if no constraint, (constraint_type, constraint_value) otherwise.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
@abstractmethod
def get_added_constraint(
    self,
    data_ID1: str,
    data_ID2: str,
) -> Optional[Tuple[str, float]]:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to get the constraint added between the two data IDs.
    Do not take into account the constraints transitivity, just look at constraints that are explicitly added.

    Args:
        data_ID1 (str): The first data ID that is concerned for this constraint.
        data_ID2 (str): The second data ID that is concerned for this constraint.

    Raises:
        ValueError: if `data_ID1` or `data_ID2` are not managed.

    Returns:
        Optional[Tuple[str, float]]: `None` if no constraint, `(constraint_type, constraint_value)` otherwise.
    """

get_connected_components(threshold=1.0) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to get the possible lists of data IDs that are connected by a "MUST_LINK" constraints. Each list forms a component of the constraints transitivity graph, and it forms a partition of the managed data IDs. The transitivity is taken into account, and the threshold parameter is used to evaluate the impact of constraints transitivity.

Parameters:

Name Type Description Default
threshold float

The threshold used to evaluate the impact of constraints transitivity link. Defaults to 1.0.

1.0

Raises:

Type Description
ValueError

if threshold is not managed.

Returns:

Type Description
List[List[str]]

List[List[int]]: The list of lists of data IDs that represent a component of the constraints transitivity graph.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@abstractmethod
def get_connected_components(
    self,
    threshold: float = 1.0,
) -> List[List[str]]:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to get the possible lists of data IDs that are connected by a `"MUST_LINK"` constraints.
    Each list forms a component of the constraints transitivity graph, and it forms a partition of the managed data IDs.
    The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

    Args:
        threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

    Raises:
        ValueError: if `threshold` is not managed.

    Returns:
        List[List[int]]: The list of lists of data IDs that represent a component of the constraints transitivity graph.
    """

get_inferred_constraint(data_ID1, data_ID2, threshold=1.0) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to check if the constraint inferred by transitivity between the two data IDs. The transitivity is taken into account, and the threshold parameter is used to evaluate the impact of constraints transitivity.

Parameters:

Name Type Description Default
data_ID1 str

The first data ID that is concerned for this constraint.

required
data_ID2 str

The second data ID that is concerned for this constraint.

required
threshold float

The threshold used to evaluate the impact of constraints transitivity link. Defaults to 1.0.

1.0

Raises:

Type Description
ValueError

if data_ID1, data_ID2 or threshold are not managed.

Returns:

Type Description
Optional[str]

Optional[str]: The type of the inferred constraint. The type can be None, "MUST_LINK" or "CANNOT_LINK".

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@abstractmethod
def get_inferred_constraint(
    self,
    data_ID1: str,
    data_ID2: str,
    threshold: float = 1.0,
) -> Optional[str]:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to check if the constraint inferred by transitivity between the two data IDs.
    The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

    Args:
        data_ID1 (str): The first data ID that is concerned for this constraint.
        data_ID2 (str): The second data ID that is concerned for this constraint.
        threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

    Raises:
        ValueError: if `data_ID1`, `data_ID2` or `threshold` are not managed.

    Returns:
        Optional[str]: The type of the inferred constraint. The type can be `None`, `"MUST_LINK"` or `"CANNOT_LINK"`.
    """

get_list_of_involved_data_IDs_in_a_constraint_conflict(data_ID1, data_ID2, constraint_type) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to get all data IDs involved in a constraints conflict.

Parameters:

Name Type Description Default
data_ID1 str

The first data ID involved in the constraint_conflit.

required
data_ID2 str

The second data ID involved in the constraint_conflit.

required
constraint_type str

The constraint that create a conflict. The constraints can be "MUST_LINK" or "CANNOT_LINK".

required

Raises:

Type Description
ValueError

if data_ID1, data_ID2, constraint_type are not managed.

Returns:

Type Description
Optional[List[str]]

Optional[List[str]]: The list of data IDs that are involved in the conflict. It matches data IDs from connected components of data_ID1 and data_ID2.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
@abstractmethod
def get_list_of_involved_data_IDs_in_a_constraint_conflict(
    self,
    data_ID1: str,
    data_ID2: str,
    constraint_type: str,
) -> Optional[List[str]]:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to get all data IDs involved in a constraints conflict.

    Args:
        data_ID1 (str): The first data ID involved in the constraint_conflit.
        data_ID2 (str): The second data ID involved in the constraint_conflit.
        constraint_type (str): The constraint that create a conflict. The constraints can be `"MUST_LINK"` or `"CANNOT_LINK"`.

    Raises:
        ValueError: if `data_ID1`, `data_ID2`, `constraint_type` are not managed.

    Returns:
        Optional[List[str]]: The list of data IDs that are involved in the conflict. It matches data IDs from connected components of `data_ID1` and `data_ID2`.
    """

get_list_of_managed_data_IDs() abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to get the list of data IDs that are managed.

Returns:

Type Description
List[str]

List[str]: The list of data IDs that are managed.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
72
73
74
75
76
77
78
79
80
81
82
@abstractmethod
def get_list_of_managed_data_IDs(
    self,
) -> List[str]:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to get the list of data IDs that are managed.

    Returns:
        List[str]: The list of data IDs that are managed.
    """

get_min_and_max_number_of_clusters(threshold=1.0) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to get determine, for a clustering model that would not violate any constraints, the range of the possible clusters number. The transitivity is taken into account, and the threshold parameter is used to evaluate the impact of constraints transitivity.

Parameters:

Name Type Description Default
threshold float

The threshold used to evaluate the impact of constraints transitivity link. Defaults to 1.0.

1.0

Raises:

Type Description
ValueError

if threshold is not managed.

Returns:

Type Description
Tuple[int, int]

Tuple[int,int]: The minimum and the maximum possible clusters numbers (for a clustering model that would not violate any constraints).

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
@abstractmethod
def get_min_and_max_number_of_clusters(
    self,
    threshold: float = 1.0,
) -> Tuple[int, int]:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to get determine, for a clustering model that would not violate any constraints, the range of the possible clusters number.
    The transitivity is taken into account, and the `threshold` parameter is used to evaluate the impact of constraints transitivity.

    Args:
        threshold (float, optional): The threshold used to evaluate the impact of constraints transitivity link. Defaults to `1.0`.

    Raises:
        ValueError: if `threshold` is not managed.

    Returns:
        Tuple[int,int]: The minimum and the maximum possible clusters numbers (for a clustering model that would not violate any constraints).
    """

to_json(filepath) abstractmethod

(ABSTRACT METHOD) An abstract method that represents the main method used to serialize the constraints manager object into a JSON file.

Parameters:

Name Type Description Default
filepath str

The path where to serialize the constraints manager object.

required

Returns:

Name Type Description
bool bool

True if the serialization is done.

Source code in src\cognitivefactory\interactive_clustering\constraints\abstract.py
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
@abstractmethod
def to_json(
    self,
    filepath: str,
) -> bool:
    """
    (ABSTRACT METHOD)
    An abstract method that represents the main method used to serialize the constraints manager object into a JSON file.

    Args:
        filepath (str): The path where to serialize the constraints manager  object.

    Returns:
        bool: `True` if the serialization is done.
    """