l2_reg: L2_reg

View source: R/optimizers.R

l2_regR Documentation

L2_reg

Description

L2 regularization as adding 'wd*p' to 'p$grad'

Usage

l2_reg(p, lr, wd, do_wd = TRUE, ...)

Arguments

p

p

lr

learning rate

wd

weight decay

do_wd

do_wd

...

additional arguments to pass

Value

None

Examples


## Not run: 

tst_param = function(val, grad = NULL) {
  "Create a tensor with `val` and a gradient of `grad` for testing"
  res = tensor(val) %>% float()

  if(is.null(grad)) {
    grad = tensor(val / 10)
  } else {
    grad = tensor(grad)
  }

  res$grad = grad %>% float()
  res
}
p = tst_param(1., 0.1)
l2_reg(p, 1., 0.1)


## End(Not run)


fastai documentation built on June 22, 2024, 11:15 a.m.