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 |
|
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 |
required |
constraint_value |
float
|
The value of the constraint to add. The value have to be in range |
1.0
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
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 |
|
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 |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
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 |
|
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
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Return |
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 |
|
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 |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
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 |
|
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 |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
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 |
|
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 |
Returns:
Type | Description |
---|---|
Optional[Tuple[str, float]]
|
Optional[Tuple[str, float]]: |
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 |
|
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
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
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 |
|
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
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The type of the inferred constraint. The type can be |
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 |
|
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 |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if |
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 |
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 |
|
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 |
|
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
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
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 |
|
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
|
|
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 |
|