PositivePrior

Adds a positive constraint on the weights of a Linear layer.

If the Linear layer has intercepts, the constraint won't apply to them.

This is implemented as a proximal operator during SGD.

class PositivePrior : ProxyLinearPrior {
size_t _ind_start;
float _eps;
}

Examples

1 // force weights to be positive:
2 auto l1 = Linear(5).prior(PositivePrior());
3 
4 // force weights to be above 1e-3:
5 auto l2 = Linear(10).prior(PositivePrior(1e-3));

Meta