Arcana Losses
Submodules
arcana.losses.loss module
Custom loss module.
- class arcana.losses.loss.CombinedHPLoss(*args: Any, **kwargs: Any)
Bases:
Module
Combined huberized pinball loss for quantile regression.
- forward(predicted, target, mask=None)
Compute the combined huberized quantile loss.
- Parameters:
predicted (torch.Tensor or np.ndarray) – predicted values
target (torch.Tensor or np.ndarray) – target values
mask (torch.Tensor or np.ndarray) – mask to apply to the loss (optional. Default: None)
- Returns:
torch.Tensor or np.ndarray – mean loss
- class arcana.losses.loss.CombinedLPLoss(*args: Any, **kwargs: Any)
Bases:
Module
Combined logcosh pinball loss for quantile regression.
- forward(predicted, target)
Compute the combined logcosh quantile loss.
- Parameters:
predicted (torch.Tensor or np.ndarray) – predicted values
target (torch.Tensor or np.ndarray) – target values
- Returns:
torch.Tensor or np.ndarray – mean loss
- class arcana.losses.loss.HuberLoss(delta=1.0)
Bases:
object
Huber loss for quantile regression.
- class arcana.losses.loss.LogCoshLoss(*args: Any, **kwargs: Any)
Bases:
Module
Log-cosh loss for quantile regression.
- forward(predicted, target)
Compute the log-cosh loss.
- Parameters:
predicted (torch.Tensor or np.ndarray) – predicted values
target (torch.Tensor or np.ndarray) – target values
- Returns:
torch.Tensor or np.ndarray – mean loss
- class arcana.losses.loss.LossFactory
Bases:
object
Factory class for losses.
- static create_loss(config)
Create a loss.
- Parameters:
config (ModelConfig) – model config
- Returns:
torch.nn.Module – loss function
- class arcana.losses.loss.MSELoss
Bases:
object
Mean squared error loss.
- class arcana.losses.loss.PinballLoss(*args: Any, **kwargs: Any)
Bases:
Module
Pinball loss for quantile regression.
- forward(predicted, target, mask=None)
Compute the pinball loss.
- Parameters:
predicted (torch.Tensor or np.ndarray) – predicted values
target (torch.Tensor or np.ndarray) – target values
mask (torch.Tensor or np.ndarray) – mask to apply to the loss (optional. Default: None)
- Returns:
torch.Tensor or np.ndarray – mean loss
- pinball_loss_numpy(predicted, target, quantiles=None)
Compute the pinball loss.
- class arcana.losses.loss.QuantileLoss(*args: Any, **kwargs: Any)
Bases:
Module
Quantile loss for quantile regression.
- forward(predicted, target)
Compute the quantile loss.
- Parameters:
predicted (torch.Tensor or np.ndarray) – predicted values
target (torch.Tensor or np.ndarray) – target values
- Returns:
torch.Tensor or np.ndarray – mean loss
- arcana.losses.loss.is_numpy(x_vector)
Check if x is a numpy array.
- Parameters:
x_vector (torch.Tensor or np.ndarray) – input vector
- Returns:
bool – True if x is a numpy array, False otherwise
- arcana.losses.loss.is_tensor(x_vector)
Check if x is a tensor.
- Parameters:
x_vector (torch.Tensor or np.ndarray) – input vector
- Returns:
bool – True if x is a tensor, False otherwise
- arcana.losses.loss.to_numpy(x_vector)
Convert x to a numpy array. If x is a tensor, detach it from the graph and move it to the cpu.
- Parameters:
x_vector (torch.Tensor or np.ndarray) – input vector
- Returns:
np.ndarray – numpy array
- arcana.losses.loss.to_tensor(x_vector, device=None)
Convert x to a tensor.
- Parameters:
x_vector (torch.Tensor or np.ndarray) – input vector
device (torch.device) – device to move the tensor to
- Returns:
torch.Tensor – tensor
arcana.losses.loss_trace module
Class to trace the loss
- class arcana.losses.loss_trace.LossTrace(output_dim)
Bases:
object
Class to trace the loss of the model during training and validation
- calculate_batch_loss_train(train_loss)
Calculate the loss for each batch and add it to the loss_trace
- Parameters:
train_loss (torch.Tensor) – loss for each batch
- calculate_batch_loss_validation(validation_loss)
Calculate the validation loss for each batch and add it to the loss_trace
- Parameters:
validation_loss (torch.Tensor) – validation loss for each batch
- calculate_epoch_loss(train_loader, val_loader)
Calculate the average loss for each epoch and add it to the loss_trace
- Parameters:
train_loader (torch.utils.data.DataLoader) – training data loader
val_loader (torch.utils.data.DataLoader) – validation data loader
- reset_temp_loss_trace()
Reset the temporary loss trace