# Path: disentanglement_lib/data/ground_truth/dummy_data.py
# class IdentityObservationsData(ground_truth_data.GroundTruthData):
# class DummyData(ground_truth_data.GroundTruthData):
#   def num_factors(self):
#   def observation_shape(self):
#   def factors_num_values(self):
#   def sample_factors(self, num, random_state):
#   def sample_observations_from_factors(self, factors, random_state):
#   def factor_names(self):
#   def num_factors(self):
#   def factors_num_values(self):
#   def observation_shape(self):
#   def sample_factors(self, num, random_state):
#   def sample_observations_from_factors(self, factors, random_state):
# 
# Path: disentanglement_lib/evaluation/metrics/modularity_explicitness.py
# def compute_modularity_explicitness(ground_truth_data,
#                                     representation_function,
#                                     random_state,
#                                     artifact_dir=None,
#                                     num_train=gin.REQUIRED,
#                                     num_test=gin.REQUIRED,
#                                     batch_size=16):
# def explicitness_per_factor(mus_train, y_train, mus_test, y_test):
# def modularity(mutual_information):


from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import modularity_explicitness
from six.moves import range
import numpy as np
import gin.tf
    gin.bind_parameter("discretizer.num_bins", 10)
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: np.array(x, dtype=np.float64)
    random_state = np.random.RandomState(0)
    scores = modularity_explicitness.compute_modularity_explicitness(
        ground_truth_data, representation_function, random_state, None, 3000,
        3000)
    self.assertBetween(scores["modularity_score"], 0.9, 1.0)

  def test_bad_metric(self):
    gin.bind_parameter("discretizer.discretizer_fn", _identity_discretizer)
    gin.bind_parameter("discretizer.num_bins", 10)
    ground_truth_data = dummy_data.IdentityObservationsData()
    random_state_rep = np.random.RandomState(0)
    # The representation which randomly permutes the factors, should have equal
    # non-zero MI which should give a low modularity score.
    def representation_function(x):
      code = np.array(x, dtype=np.float64)
      for i in range(code.shape[0]):
        code[i, :] = random_state_rep.permutation(code[i, :])
      return code
    random_state = np.random.RandomState(0)
    scores = modularity_explicitness.compute_modularity_explicitness(
        ground_truth_data, representation_function, random_state, None, 20000,
        20000)
    self.assertBetween(scores["modularity_score"], 0.0, 0.2)

  def test_duplicated_latent_space(self):
    gin.bind_parameter("discretizer.discretizer_fn", _identity_discretizer)
    gin.bind_parameter("discretizer.num_bins", 10)

# Path: disentanglement_lib/data/ground_truth/dummy_data.py
# class IdentityObservationsData(ground_truth_data.GroundTruthData):
# class DummyData(ground_truth_data.GroundTruthData):
#   def num_factors(self):
#   def observation_shape(self):
#   def factors_num_values(self):
#   def sample_factors(self, num, random_state):
#   def sample_observations_from_factors(self, factors, random_state):
#   def factor_names(self):
#   def num_factors(self):
#   def factors_num_values(self):
#   def observation_shape(self):
#   def sample_factors(self, num, random_state):
#   def sample_observations_from_factors(self, factors, random_state):
# 
# Path: disentanglement_lib/evaluation/metrics/modularity_explicitness.py
# def compute_modularity_explicitness(ground_truth_data,
#                                     representation_function,
#                                     random_state,
#                                     artifact_dir=None,
#                                     num_train=gin.REQUIRED,
#                                     num_test=gin.REQUIRED,
#                                     batch_size=16):
# def explicitness_per_factor(mus_train, y_train, mus_test, y_test):
# def modularity(mutual_information):


# Path: disentanglement_lib/evaluation/metrics/modularity_explicitness_test.py
from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import modularity_explicitness
from six.moves import range
import numpy as np
import gin.tf

    gin.bind_parameter("discretizer.num_bins", 10)
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: np.array(x, dtype=np.float64)
    random_state = np.random.RandomState(0)
    scores = modularity_explicitness.compute_modularity_explicitness(
        ground_truth_data, representation_function, random_state, None, 3000,
        3000)
    self.assertBetween(scores["modularity_score"], 0.9, 1.0)

  def test_bad_metric(self):
    gin.bind_parameter("discretizer.discretizer_fn", _identity_discretizer)
    gin.bind_parameter("discretizer.num_bins", 10)
    ground_truth_data = dummy_data.IdentityObservationsData()
    random_state_rep = np.random.RandomState(0)
    # The representation which randomly permutes the factors, should have equal
    # non-zero MI which should give a low modularity score.
    def representation_function(x):
      code = np.array(x, dtype=np.float64)
      for i in range(code.shape[0]):
        code[i, :] = random_state_rep.permutation(code[i, :])
      return code
    random_state = np.random.RandomState(0)
    scores = modularity_explicitness.compute_modularity_explicitness(
        ground_truth_data, representation_function, random_state, None, 20000,
        20000)
    self.assertBetween(scores["modularity_score"], 0.0, 0.2)

  def test_duplicated_latent_space(self):
    gin.bind_parameter("discretizer.discretizer_fn", _identity_discretizer)
    gin.bind_parameter("discretizer.num_bins", 10)

    ground_truth_data = dummy_data.IdentityObservationsData()