Custom Optimizers
- flood_forecast.custom.custom_opt.warmup_constant(x, warmup=0.002)[source]
Linearly increases learning rate over warmup`*`t_total (as provided to BertAdam) training steps.
Learning rate is 1. afterwards.
- flood_forecast.custom.custom_opt.warmup_linear(x, warmup=0.002)[source]
Specifies a triangular learning rate schedule where peak is reached at warmup`*`t_total-th (as provided to BertAdam) training step.
After t_total-th training step, learning rate is zero.
- class flood_forecast.custom.custom_opt.MASELoss(baseline_method)[source]
- __init__(baseline_method)[source]
This implements the MASE loss function (e.g. MAE_MODEL/MAE_NAIEVE)
- forward(target: Tensor, output: Tensor, train_data: Tensor, m=1) Tensor [source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.custom.custom_opt.RMSELoss(variance_penalty=0.0)[source]
Returns RMSE using:
target -> True y output -> Prediction by model source: https://discuss.pytorch.org/t/rmse-loss-function/16540/3
- __init__(variance_penalty=0.0)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(output: Tensor, target: Tensor)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.custom.custom_opt.MAPELoss(variance_penalty=0.0)[source]
Returns MAPE using:
target -> True y output -> Predtion by model
- __init__(variance_penalty=0.0)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(output: Tensor, target: Tensor)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.custom.custom_opt.PenalizedMSELoss(variance_penalty=0.0)[source]
Returns MSE using:
target -> True y output -> Predtion by model source: https://discuss.pytorch.org/t/rmse-loss-function/16540/3
- __init__(variance_penalty=0.0)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(output: Tensor, target: Tensor)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.custom.custom_opt.GaussianLoss(mu=0, sigma=0)[source]
- __init__(mu=0, sigma=0)[source]
Compute the negative log likelihood of Gaussian Distribution From https://arxiv.org/abs/1907.00235.
- forward(x: Tensor)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.custom.custom_opt.QuantileLoss(quantiles)[source]
From https://medium.com/the-artificial-impostor/quantile-regression-part-2-6fdbc26b2629.
- __init__(quantiles)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(preds, target)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.custom.custom_opt.BertAdam(params, lr=<required parameter>, warmup=-1, t_total=-1, schedule='warmup_linear', b1=0.9, b2=0.999, e=1e-06, weight_decay=0.01, max_grad_norm=1.0)[source]
Implements BERT version of Adam algorithm with weight decay fix.
- Params:
lr: learning rate warmup: portion of t_total for the warmup, -1 means no warmup. Default: -1 t_total: total number of training steps for the learning
rate schedule, -1 means constant learning rate. Default: -1
schedule: schedule to use for the warmup (see above). Default: ‘warmup_linear’ b1: Adams b1. Default: 0.9 b2: Adams b2. Default: 0.999 e: Adams epsilon. Default: 1e-6 weight_decay: Weight decay. Default: 0.01 max_grad_norm: Maximum norm for the gradients (-1 means no clipping). Default: 1.0
- class flood_forecast.custom.custom_opt.NegativeLogLikelihood[source]
target -> True y output -> predicted distribution.
- flood_forecast.custom.custom_opt.l1_regularizer(model, lambda_l1=0.01)[source]
source: https://stackoverflow.com/questions/58172188/how-to-add-l1-regularization-to-pytorch-nn-model
- flood_forecast.custom.custom_opt.orth_regularizer(model, lambda_orth=0.01)[source]
source: https://stackoverflow.com/questions/58172188/how-to-add-l1-regularization-to-pytorch-nn-model