'Adds L2 regularization for parameters which have it turned on.
Args:
cost: float cost before regularization.
Returns:
Updated cost optionally including regularization.'

def add_regularizer(self, cost):

    if (self.network is None):
        return cost
    regularized_weights = self.network.get_l2_regularized_weights()
    if (not regularized_weights):
        return cost
    l2_coeff = self.master.hyperparams.l2_regularization_coefficient
    if (l2_coeff == 0.0):
        return cost
    tf.logging.info('[%s]    Regularizing    parameters:    %s', self.name, [w.name for w in regularized_weights])
    l2_costs = [tf.nn.l2_loss(p) for p in regularized_weights]
    return tf.add(cost, (l2_coeff * tf.add_n(l2_costs)), name='regularizer')
