calculation
check_properties(*args)
¶
Check if all the arguments have values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
list
|
All the arguments. |
()
|
Returns:
Name | Type | Description |
---|---|---|
float |
The mean of arguments that have values. |
Source code in nebula/addons/trustworthiness/calculation.py
191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
get_avg_loss_accuracy(loss_files, accuracy_files)
¶
Calculates the mean accuracy and loss models of the nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss_files
|
list
|
Files that contain the loss of the models of the nodes. |
required |
accuracy_files
|
list
|
Files that contain the acurracies of the models of the nodes. |
required |
Returns:
Type | Description |
---|---|
3-tupla: The mean loss of the models, the mean accuracies of the models, the standard deviation of the accuracies of the models. |
Source code in nebula/addons/trustworthiness/calculation.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
get_bytes_models(models_files)
¶
Calculates the mean bytes of the final models of the nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
models_files
|
list
|
List of final models. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The mean bytes of the models. |
Source code in nebula/addons/trustworthiness/calculation.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
get_bytes_sent_recv(bytes_sent_files, bytes_recv_files)
¶
Calculates the mean bytes sent and received of the nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bytes_sent_files
|
list
|
Files that contain the bytes sent of the nodes. |
required |
bytes_recv_files
|
list
|
Files that contain the bytes received of the nodes. |
required |
Returns:
Type | Description |
---|---|
4-tupla: The total bytes sent, the total bytes received, the mean bytes sent and the mean bytes received of the nodes. |
Source code in nebula/addons/trustworthiness/calculation.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
get_clever_score(model, test_sample, nb_classes, learning_rate)
¶
Calculates the CLEVER score.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
object
|
The model. |
required |
test_sample
|
object
|
One test sample to calculate the CLEVER score. |
required |
nb_classes
|
int
|
The nb_classes of the model. |
required |
learning_rate
|
float
|
The learning rate of the model. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The CLEVER score. |
Source code in nebula/addons/trustworthiness/calculation.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
get_cv(list=None, std=None, mean=None)
¶
Get the coefficient of variation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list
|
list
|
List in which the coefficient of variation will be calculated. |
None
|
std
|
float
|
Standard deviation of a list. |
None
|
mean
|
float
|
Mean of a list. |
None
|
Returns:
Name | Type | Description |
---|---|---|
float |
The coefficient of variation calculated. |
Source code in nebula/addons/trustworthiness/calculation.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
get_elapsed_time(scenario)
¶
Calculates the elapsed time during the execution of the scenario.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scenario
|
object
|
Scenario required. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The elapsed time. |
Source code in nebula/addons/trustworthiness/calculation.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
get_feature_importance_cv(model, test_sample)
¶
Calculates the coefficient of variation of the feature importance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
object
|
The model. |
required |
test_sample
|
object
|
One test sample to calculate the feature importance. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The coefficient of variation of the feature importance. |
Source code in nebula/addons/trustworthiness/calculation.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
get_global_privacy_risk(dp, epsilon, n)
¶
Calculates the global privacy risk by epsilon and the number of clients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dp
|
bool
|
Indicates if differential privacy is used or not. |
required |
epsilon
|
int
|
The epsilon value. |
required |
n
|
int
|
The number of clients in the scenario. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The global privacy risk. |
Source code in nebula/addons/trustworthiness/calculation.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
get_map_value_score(score_key, score_map)
¶
Finds the score by the score_key in the score_map and returns the value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score_key
|
string
|
The key to look up in the score_map. |
required |
score_map
|
dict
|
The score map defined in the eval_metrics.json file. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The score obtained in the score_map. |
Source code in nebula/addons/trustworthiness/calculation.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
get_mapped_score(score_key, score_map)
¶
Finds the score by the score_key in the score_map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score_key
|
string
|
The key to look up in the score_map. |
required |
score_map
|
dict
|
The score map defined in the eval_metrics.json file. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The normalized score of [0, 1]. |
Source code in nebula/addons/trustworthiness/calculation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
get_normalized_scores(scores)
¶
Calculates the normalized scores of a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scores
|
list
|
The values that will be normalized. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
The normalized list. |
Source code in nebula/addons/trustworthiness/calculation.py
52 53 54 55 56 57 58 59 60 61 62 63 |
|
get_range_score(value, ranges, direction='asc')
¶
Maps the value to a range and gets the score by the range and direction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int
|
The input score. |
required |
ranges
|
list
|
The ranges defined. |
required |
direction
|
string
|
Asc means the higher the range the higher the score, desc means otherwise. |
'asc'
|
Returns:
Name | Type | Description |
---|---|---|
float |
The normalized score of [0, 1]. |
Source code in nebula/addons/trustworthiness/calculation.py
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 |
|
get_scaled_score(value, scale, direction)
¶
Maps a score of a specific scale into the scale between zero and one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int or float
|
The raw value of the metric. |
required |
scale
|
list
|
List containing the minimum and maximum value the value can fall in between. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The normalized score of [0, 1]. |
Source code in nebula/addons/trustworthiness/calculation.py
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 |
|
get_true_score(value, direction)
¶
Returns the negative of the value if direction is 'desc', otherwise returns value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int
|
The input score. |
required |
direction
|
string
|
Asc means the higher the range the higher the score, desc means otherwise. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The score obtained. |
Source code in nebula/addons/trustworthiness/calculation.py
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 |
|
get_value(value)
¶
Get the value of a metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
float
|
The value of the metric. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The value of the metric. |
Source code in nebula/addons/trustworthiness/calculation.py
177 178 179 180 181 182 183 184 185 186 187 188 |
|
stop_emissions_tracking_and_save(tracker, outdir, emissions_file, role, workload, sample_size=0)
¶
Stops emissions tracking object from CodeCarbon and saves relevant information to emissions.csv file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tracker
|
object
|
The emissions tracker object holding information. |
required |
outdir
|
str
|
The path of the output directory of the experiment. |
required |
emissions_file
|
str
|
The path to the emissions file. |
required |
role
|
str
|
Either client or server depending on the role. |
required |
workload
|
str
|
Either aggregation or training depending on the workload. |
required |
sample_size
|
int
|
The number of samples used for training, if aggregation 0. |
0
|
Source code in nebula/addons/trustworthiness/calculation.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|