L2Prior

Adds L2 regularization to a Linear layer.

Constructors

this
this(float lambda)
Undocumented in source.
this
this(float lambda, float[][] W_prior_)
Undocumented in source.
this
this(float[] lambdas)
Undocumented in source.
this
this(float[] lambdas, float[][] W_prior_)
Undocumented in source.

Members

Functions

_acc_grad_scal
void _acc_grad_scal()
Undocumented in source. Be warned that the author may not have intended to support it.
_acc_grad_scal
void _acc_grad_scal()
Undocumented in source. Be warned that the author may not have intended to support it.
_acc_grad_vec
void _acc_grad_vec()
Undocumented in source. Be warned that the author may not have intended to support it.
_acc_grad_vec
void _acc_grad_vec()
Undocumented in source. Be warned that the author may not have intended to support it.
accumulate_grad
void accumulate_grad()
Undocumented in source. Be warned that the author may not have intended to support it.
dup
AdditiveLinearPrior dup()
Undocumented in source. Be warned that the author may not have intended to support it.
register
void register(Linear layer)
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin opCallNew
Undocumented in source.

Static functions

l2op_scal
void l2op_scal(float a, float[] x, float[] x2, float[] y, size_t start)
Undocumented in source. Be warned that the author may not have intended to support it.
l2op_vec
void l2op_vec(float[] a, float[] x, float[] x2, float[] y, size_t start)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

W_prior
float[][] W_prior;
Undocumented in source.
_accumulate_grad
void delegate() _accumulate_grad;
Undocumented in source.
_ind_start
size_t _ind_start;
Undocumented in source.
_lambda
float _lambda;
Undocumented in source.
_lambdas
float[] _lambdas;
Undocumented in source.

Mixed In Members

From mixin opCallNew

opCall
auto opCall(T args)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From AdditiveLinearPrior

accumulate_grad
void accumulate_grad()
Undocumented in source.
dup
AdditiveLinearPrior dup()
Undocumented in source.

Examples

// basic L2 regularization: loss = (0.03 / 2) * || W ||^2
auto l1 = Linear(5).prior(L2Prior(0.03));

// same, but centered around a non-zero matrix: loss = (0.03 / 2) * || W - W_p ||^2
auto l2 = Linear(5).prior(L2Prior(0.03, W_p));

// L2 regularization with 1 lambda per feature (diagonal Hessian 0-centered prior).
// Example when input dim is 5:
auto l3 = Linear(10).prior(L2Prior([0.01f, 0.02f, 0.01f, 0.015f, 0.005f]));

// L2 regularization with 1 lambda per feature, centered around a non-zero matrix.
// Example when input dim is 5:
auto l4 = Linear(10).prior(L2Prior([0.01f, 0.02f, 0.01f, 0.015f, 0.005f], W_p));

Meta