slisemap.diagnostics
These are diagnostics for identifying potential issues with SLISEMAP solutions.
Typical usage:
sm = Slisemap(...)
sm.optimise()
diagnostics = diagnose(sm)
print_diagnostics(diagnostics)
plot_diagnostics(sm, diagnostics)
global_model_losses(sm, indices=None, **kwargs)
Train a global model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Slisemap object. |
required |
indices |
Optional[ndarray]
|
Optional subsampling indices. Defaults to None. |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs |
Any
|
Optional keyword arguments to LBFGS. |
Returns:
Type | Description |
---|---|
Tensor
|
Vector of individual losses for a global model. |
Source code in slisemap/diagnostics.py
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 |
|
print_diagnostics(diagnostics, summary=False)
Print diagnostic results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diagnostics |
Dict[str, ndarray]
|
Dictionary of diagnostic results. |
required |
summary |
bool
|
Print only one summary for all the diagnostics. Defaults to False. |
False
|
Source code in slisemap/diagnostics.py
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 |
|
plot_diagnostics(Z, diagnostics, summary=False, title='Slisemap Diagnostics', show=True, **kwargs)
Plot diagnostic results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Z |
Union[Slisemap, ndarray]
|
The Slisemap object, or embedding matrix. |
required |
diagnostics |
Dict[str, ndarray]
|
Dictionary of diagnostic results. |
required |
summary |
bool
|
Combine multiple diagnostics into one plot. Defaults to False. |
False
|
title |
str
|
Title of the plot. Defaults to "Slisemap Diagnostics". |
'Slisemap Diagnostics'
|
show |
bool
|
Show the plot. Defaults to True. |
True
|
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs |
Any
|
Additional parameters to |
Returns:
Type | Description |
---|---|
Optional[FacetGrid]
|
|
Source code in slisemap/diagnostics.py
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 |
|
distant_diagnostic(sm, max_distance=10.0)
Check if any data item in the embedding is too far way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
max_distance |
float
|
Maximum distance from origo in the embedding. Defaults to 10.0. |
10.0
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
177 178 179 180 181 182 183 184 185 186 187 |
|
heavyweight_diagnostic(sm, min_size=0.1)
Check if any data item has a self-weight that is too large.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
min_size |
Union[float, int]
|
Miniumum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.1. |
0.1
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
lightweight_diagnostic(sm, max_size=0.5)
Check if any data item has a self-weight that is too small.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
max_size |
Union[float, int]
|
Maximum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.5. |
0.5
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
weight_neighbourhood_diagnostic(sm, min_size=0.1, max_size=0.5)
Check if any data item has a neighbourhood that is too small/large by counting the number of non-lightweight neighbours.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
min_size |
Union[float, int]
|
Miniumum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.1. |
0.1
|
max_size |
Union[float, int]
|
Maximum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.5. |
0.5
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
loss_neighbourhood_diagnostic(sm, min_size=0.1, smoothing=True, median=False)
Check if any data item has a neighbourhood that is too small/large by comparing local losses to global losses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
min_size |
Union[float, int]
|
Miniumum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.1. |
0.1
|
smoothing |
bool
|
Smooth the sorted losses to avoid sensitivity to outliers. Defaults to True. |
True
|
median |
bool
|
Compare against the median global loss instead of the mean global loss. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
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 |
|
global_loss_diagnostic(sm, bootstrap=10, sd=1.0)
Check if any local model is actually a global model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
bootstrap |
int
|
Number of (bootstrap) global models to train. Defaults to 10. |
10
|
sd |
float
|
Number of standard deviations from the mean (of global models losses) to consider a local model global. Defaults to 1.0. |
1.0
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
quantile_loss_diagnostic(sm, quantile=0.4)
Check if any fidelity is worse than a quantile of all losses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
quantile |
float
|
The quantile percentage. Defaults to 0.4. |
0.4
|
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
optics_diagnostic(sm, min_size=0.1, **kwargs)
Use a clustering method (sklearn.cluster.OPTICS
) to check for problematic data items in the embedding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
min_size |
Union[float, int]
|
Miniumum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.1. |
0.1
|
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs |
Any
|
forwaded to OPTICS. |
Returns:
Type | Description |
---|---|
ndarray
|
Boolean mask of problematic data items. |
Source code in slisemap/diagnostics.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
diagnose(sm, min_size=0.1, max_size=0.5, max_distance=10.0, conservative=False)
Run multiple diagnostics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Slisemap
|
Trained Slisemap solution. |
required |
min_size |
Union[float, int]
|
Miniumum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.1. |
0.1
|
max_size |
Union[float, int]
|
Maximum neighbourhood/cluster size (as a fraction or absolute number). Defaults to 0.5. |
0.5
|
max_distance |
float
|
Maximum distance from origo in the embedding. Defaults to 10.0. |
10.0
|
conservative |
bool
|
Only run the most conservative diagnostics. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Dict[str, ndarray]
|
Dictionary of the the diagnostics results. |
Source code in slisemap/diagnostics.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|