dgld.models.CoLA.colautils
- dgld.models.CoLA.colautils.loss_fun(pos_scores, neg_scores, criterion, device)
calculate loss function in Binary CrossEntropy Loss
- Parameters
pos_scores (torch.Tensor) – anomaly score of positive sample
neg_scores (torch.Tensor) – anomaly score of negative sample
criterion (torch.nn.Module) – loss function calculation funciton
device (str) – device for calculation
- Returns
loss_accum – loss of single epoch
- Return type
torch.Tensor
- dgld.models.CoLA.colautils.loss_fun_BCE(pos_scores, neg_scores, criterion, device)[source]
calculate loss function in Binary CrossEntropy Loss
- Parameters
pos_scores (torch.Tensor) – anomaly score of positive sample
neg_scores (torch.Tensor) – anomaly score of negative sample
criterion (torch.nn.Module) – loss function calculation funciton
device (str) – device for calculation
- Returns
loss_accum – loss of single epoch
- Return type
torch.Tensor
- dgld.models.CoLA.colautils.loss_fun_BPR(pos_scores, neg_scores, criterion, device)[source]
calculate loss function in Bayesian Personalized Ranking
- Parameters
pos_scores (torch.Tensor) – anomaly score of positive sample
neg_scores (torch.Tensor) – anomaly score of negative sample
criterion (torch.nn.Module) – loss function calculation funciton
device (str) – device for calculation
- Returns
loss_accum – loss of single epoch
- Return type
torch.Tensor
- dgld.models.CoLA.colautils.set_subargs(parser)[source]
get hyperparameter by parser from command line
- Returns
final_args_dict – dict of args parser
- Return type
dictionary
- dgld.models.CoLA.colautils.test_epoch(epoch, loader, net, device, criterion)[source]
test_epoch, test model in one epoch
- Parameters
epoch (int) – epoch number during testin
loader (torch.nn.DataLoader) – dataloader for testing
net (torch.nn.Module) – model
device (str) – device for testing
criterion (torch.nn.Module) – loss, the same as the loss during training
- Returns
predict_scores – anomaly score
- Return type
numpy.ndarray
- dgld.models.CoLA.colautils.train_epoch(epoch, loader, net, device, criterion, optimizer)[source]
train_epoch, train model in one epoch
- Parameters
epoch (int) – epoch number during training
loader (torch.nn.DataLoader) – dataloader for training
net (torch.nn.Module) – model
device (str) – device for training
criterion (type) – loss
optimizer (torch.optim.Adam) – optimizer for training
- Returns
loss_accum – loss of single epoch
- Return type
torch.Tensor