25 template<
typename Real_t>
 
   26 Real_t TReference<Real_t>::L1Regularization(
const TMatrixT<Real_t> & W)
 
   34    for (
size_t i = 0; i < m; i++) {
 
   35       for (
size_t j = 0; j < n; j++) {
 
   36          result += std::abs(W(i,j));
 
   43 template<
typename Real_t>
 
   44 void TReference<Real_t>::AddL1RegularizationGradients(TMatrixT<Real_t> & A,
 
   45                                                      const TMatrixT<Real_t> & W,
 
   54    for (
size_t i = 0; i < m; i++) {
 
   55       for (
size_t j = 0; j < n; j++) {
 
   56          sign = (W(i,j) > 0.0) ? 1.0 : -1.0;
 
   57          A(i,j) += sign * weightDecay;
 
   63 template<
typename Real_t>
 
   64 Real_t TReference<Real_t>::L2Regularization(
const TMatrixT<Real_t> & W)
 
   72    for (
size_t i = 0; i < m; i++) {
 
   73       for (
size_t j = 0; j < n; j++) {
 
   74          result += W(i,j) * W(i,j);
 
   81 template<
typename Real_t>
 
   82 void TReference<Real_t>::AddL2RegularizationGradients(TMatrixT<Real_t> & A,
 
   83                                                      const TMatrixT<Real_t> & W,
 
   90    for (
size_t i = 0; i < m; i++) {
 
   91       for (
size_t j = 0; j < n; j++) {
 
   92          A(i,j) += weightDecay * 2.0 * W(i,j);