utils
AvgrageMeter
Bases: object
Computes and stores the average and current value.
Source code in src/autora/theorist/darts/utils.py
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 |
|
__init__()
Initializes the average meter.
Source code in src/autora/theorist/darts/utils.py
214 215 216 217 218 |
|
reset()
Resets the average meter.
Source code in src/autora/theorist/darts/utils.py
220 221 222 223 224 225 226 |
|
update(val, n=1)
Updates the average meter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
float
|
value to update the average meter with |
required |
n |
int
|
number of times to update the average meter |
1
|
Source code in src/autora/theorist/darts/utils.py
228 229 230 231 232 233 234 235 236 237 238 |
|
accuracy(output, target, topk=(1))
Computes the accuracy over the k top predictions for the specified values of k.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output |
torch.Tensor
|
output of the model |
required |
target |
torch.Tensor
|
target of the model |
required |
topk |
Tuple
|
values of k to compute the accuracy at |
(1)
|
Source code in src/autora/theorist/darts/utils.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
assign_slurm_instance(slurm_id, arch_weight_decay_list, num_node_list, seed_list)
Determines the meta-search parameters based on the slum job id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slurm_id |
int
|
slurm job id |
required |
arch_weight_decay_list |
List
|
list of weight decay values |
required |
num_node_list |
List
|
list of number of nodes |
required |
seed_list |
List
|
list of seeds |
required |
Source code in src/autora/theorist/darts/utils.py
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 |
|
compute_BIC(output_type, model, input, target)
Returns the Bayesian information criterion for a DARTS model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_type |
ValueType
|
output type of the dependent variable |
required |
model |
torch.nn.Module
|
model to compute the BIC for |
required |
input |
torch.Tensor
|
input of the model |
required |
target |
torch.Tensor
|
target of the model |
required |
Source code in src/autora/theorist/darts/utils.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 |
|
compute_BIC_AIC(soft_targets, soft_prediction, model)
Returns the Bayesian information criterion (BIC) as well as the Aikaike information criterion (AIC) for a DARTS model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
soft_targets |
np.array
|
soft target of the model |
required |
soft_prediction |
np.array
|
soft prediction of the model |
required |
model |
Network
|
model to compute the BIC and AIC for |
required |
Source code in src/autora/theorist/darts/utils.py
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 |
|
count_parameters_in_MB(model)
Returns the number of parameters for a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Network
|
model to count the parameters for |
required |
Source code in src/autora/theorist/darts/utils.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
create_exp_dir(path, scripts_to_save=None, parent_folder='exps', results_folder=None)
Creates an experiment directory and saves all necessary scripts and files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
path to save the experiment directory to |
required |
scripts_to_save |
Optional[List]
|
list of scripts to save |
None
|
parent_folder |
str
|
parent folder for the experiment directory |
'exps'
|
results_folder |
Optional[str]
|
folder for the results of the experiment |
None
|
Source code in src/autora/theorist/darts/utils.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
create_output_file_name(file_prefix, log_version=None, weight_decay=None, k=None, seed=None, theorist=None)
Creates a file name for the output file of a theorist study.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_prefix |
str
|
prefix of the file name |
required |
log_version |
Optional[int]
|
log version of the theorist run |
None
|
weight_decay |
Optional[float]
|
weight decay of the model |
None
|
k |
Optional[int]
|
number of nodes in the model |
None
|
seed |
Optional[int]
|
seed of the model |
None
|
theorist |
Optional[str]
|
name of the DARTS variant |
None
|
Source code in src/autora/theorist/darts/utils.py
15 16 17 18 19 20 21 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 |
|
cross_entropy(pred, soft_targets)
Returns the cross entropy loss for a soft target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pred |
torch.Tensor
|
prediction of the model |
required |
soft_targets |
torch.Tensor
|
soft target of the model |
required |
Source code in src/autora/theorist/darts/utils.py
195 196 197 198 199 200 201 202 203 204 205 206 |
|
format_input_target(input, target, criterion)
Formats the input and target for the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
torch.tensor
|
input to the model |
required |
target |
torch.tensor
|
target of the model |
required |
criterion |
Callable
|
criterion to use for the model |
required |
Returns:
Name | Type | Description |
---|---|---|
input |
Tuple[torch.tensor, torch.tensor]
|
formatted input and target for the model |
Source code in src/autora/theorist/darts/utils.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
get_best_fitting_models(model_name_list, loss_list, BIC_list, topk)
Returns the topk best fitting models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name_list |
List
|
list of model names |
required |
loss_list |
List
|
list of loss values |
required |
BIC_list |
List
|
list of BIC values |
required |
topk |
int
|
number of topk models to return |
required |
Source code in src/autora/theorist/darts/utils.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
get_loss_function(outputType)
Returns the loss function for the given output type of a dependent variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputType |
ValueType
|
output type of the dependent variable |
required |
Source code in src/autora/theorist/darts/utils.py
440 441 442 443 444 445 446 447 448 |
|
get_output_format(outputType)
Returns the output format (activation function of the final output layer) for the given output type of a dependent variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputType |
ValueType
|
output type of the dependent variable |
required |
Source code in src/autora/theorist/darts/utils.py
461 462 463 464 465 466 467 468 469 470 |
|
get_output_str(outputType)
Returns the output string for the given output type of a dependent variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputType |
ValueType
|
output type of the dependent variable |
required |
Source code in src/autora/theorist/darts/utils.py
483 484 485 486 487 488 489 490 491 |
|
load(model, model_path)
Loads a model from a file.
Source code in src/autora/theorist/darts/utils.py
297 298 299 300 301 |
|
read_log_files(results_path, winning_architecture_only=False)
Reads the log files from an experiment directory and returns the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results_path |
str
|
path to the experiment results directory |
required |
winning_architecture_only |
bool
|
if True, only the winning architecture is returned |
False
|
Source code in src/autora/theorist/darts/utils.py
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 377 378 |
|
save(model, model_path, exp_folder=None)
Saves a model to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
torch.nn.Module
|
model to save |
required |
model_path |
str
|
path to save the model to |
required |
exp_folder |
Optional[str]
|
general experiment directory to save the model to |
None
|
Source code in src/autora/theorist/darts/utils.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
sigmid_mse(output, target)
Returns the MSE loss for a sigmoid output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output |
torch.Tensor
|
output of the model |
required |
target |
torch.Tensor
|
target of the model |
required |
Source code in src/autora/theorist/darts/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 |
|