# Path: morph_net/op_regularizers/group_lasso_regularizer.py
# class GroupLassoRegularizer(generic_regularizers.OpRegularizer):
#   def __init__(self, weight_tensor, reduce_dims, threshold, l1_fraction=0.0):
#   def regularization_vector(self):
#   def alive_vector(self):


from absl.testing import parameterized
from morph_net.op_regularizers import group_lasso_regularizer
from tensorflow.contrib import framework as contrib_framework
from tensorflow.contrib import layers as contrib_layers
import numpy as np
import tensorflow.compat.v1 as tf
    tf.reset_default_graph()
    tf.set_random_seed(7907)
    with contrib_framework.arg_scope(
        [layers.fully_connected],
        weights_initializer=tf.random_normal_initializer):
      # Build the model.
      input_data = tf.constant(0.0, shape=[1, 3])
      layers.fully_connected(input_data, 4, scope='fc')
    with self.cached_session():
      tf.global_variables_initializer().run()

  @parameterized.named_parameters(('_fully_connected_no_l1', 0.0),
                                  ('_fully_connected_l1_0.5', 0.5))
  def testMatMulOp(self, l1_fraction):
    op = tf.get_default_graph().get_operation_by_name('fc/MatMul')
    with self.cached_session():
      weights = op.inputs[1].eval()
    l1_reg_vector = np.mean(np.abs(weights), axis=0)
    l2_reg_vector = np.sqrt(np.mean(weights**2, axis=0))
    expected_reg_vector = (
        l1_fraction * l1_reg_vector + (1.0 - l1_fraction) * l2_reg_vector)
    # We choose the threshold at the expectation value, so that some activations
    # end up above threshold and others end up below. The weights are normally
    # distributed, so the L2 norm is 1.0, and the L1 norm is sqrt(2/pi).
    # With a general l1_fraction, we compute a weighted average of the two:
    threshold = (1.0 - l1_fraction) + l1_fraction * np.sqrt(2 / np.pi)
    expected_alive = expected_reg_vector > threshold
    assert_not_all_are_alive_or_dead(expected_alive)

    matmul_reg = (

# Path: morph_net/op_regularizers/group_lasso_regularizer.py
# class GroupLassoRegularizer(generic_regularizers.OpRegularizer):
#   def __init__(self, weight_tensor, reduce_dims, threshold, l1_fraction=0.0):
#   def regularization_vector(self):
#   def alive_vector(self):


# Path: morph_net/op_regularizers/group_lasso_regularizer_test.py
from absl.testing import parameterized
from morph_net.op_regularizers import group_lasso_regularizer
from tensorflow.contrib import framework as contrib_framework
from tensorflow.contrib import layers as contrib_layers
import numpy as np
import tensorflow.compat.v1 as tf

    tf.reset_default_graph()
    tf.set_random_seed(7907)
    with contrib_framework.arg_scope(
        [layers.fully_connected],
        weights_initializer=tf.random_normal_initializer):
      # Build the model.
      input_data = tf.constant(0.0, shape=[1, 3])
      layers.fully_connected(input_data, 4, scope='fc')
    with self.cached_session():
      tf.global_variables_initializer().run()

  @parameterized.named_parameters(('_fully_connected_no_l1', 0.0),
                                  ('_fully_connected_l1_0.5', 0.5))
  def testMatMulOp(self, l1_fraction):
    op = tf.get_default_graph().get_operation_by_name('fc/MatMul')
    with self.cached_session():
      weights = op.inputs[1].eval()
    l1_reg_vector = np.mean(np.abs(weights), axis=0)
    l2_reg_vector = np.sqrt(np.mean(weights**2, axis=0))
    expected_reg_vector = (
        l1_fraction * l1_reg_vector + (1.0 - l1_fraction) * l2_reg_vector)
    # We choose the threshold at the expectation value, so that some activations
    # end up above threshold and others end up below. The weights are normally
    # distributed, so the L2 norm is 1.0, and the L1 norm is sqrt(2/pi).
    # With a general l1_fraction, we compute a weighted average of the two:
    threshold = (1.0 - l1_fraction) + l1_fraction * np.sqrt(2 / np.pi)
    expected_alive = expected_reg_vector > threshold
    assert_not_all_are_alive_or_dead(expected_alive)

    matmul_reg = (

        group_lasso_regularizer.GroupLassoRegularizer(