# 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/dci.py
# def compute_dci(ground_truth_data, representation_function, random_state,
#                 artifact_dir=None,
#                 num_train=gin.REQUIRED,
#                 num_test=gin.REQUIRED,
#                 batch_size=16):
# def _compute_dci(mus_train, ys_train, mus_test, ys_test):
# def compute_dci_on_fixed_data(observations, labels, representation_function,
#                               train_percentage=gin.REQUIRED, batch_size=100):
# def compute_importance_gbt(x_train, y_train, x_test, y_test):
# def disentanglement_per_code(importance_matrix):
# def disentanglement(importance_matrix):
# def completeness_per_factor(importance_matrix):
# def completeness(importance_matrix):


from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import dci
from six.moves import range
import numpy as np
    importance_matrix = np.diag(5.*np.ones(5))
    importance_matrix = np.vstack([importance_matrix, importance_matrix])
    result = dci.completeness(importance_matrix)
    np.testing.assert_allclose(result, 1. - np.log(2)/np.log(10))

  def test_missed_factors(self):
    importance_matrix = np.diag(5.*np.ones(5))
    result = dci.completeness(importance_matrix[:2, :])
    np.testing.assert_allclose(result, 1.0)

  def test_one_code_two_factors(self):
    importance_matrix = np.diag(5.*np.ones(5))
    importance_matrix = np.hstack([importance_matrix, importance_matrix])
    result = dci.completeness(importance_matrix)
    np.testing.assert_allclose(result, 1.)


class DCITest(absltest.TestCase):

  def test_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: np.array(x, dtype=np.float64)
    random_state = np.random.RandomState(0)
    scores = dci.compute_dci(
        ground_truth_data, representation_function, random_state, None, 1000,
        1000)
    self.assertBetween(scores["disentanglement"], 0.9, 1.0)
    self.assertBetween(scores["completeness"], 0.9, 1.0)

  def test_bad_metric(self):

# 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/dci.py
# def compute_dci(ground_truth_data, representation_function, random_state,
#                 artifact_dir=None,
#                 num_train=gin.REQUIRED,
#                 num_test=gin.REQUIRED,
#                 batch_size=16):
# def _compute_dci(mus_train, ys_train, mus_test, ys_test):
# def compute_dci_on_fixed_data(observations, labels, representation_function,
#                               train_percentage=gin.REQUIRED, batch_size=100):
# def compute_importance_gbt(x_train, y_train, x_test, y_test):
# def disentanglement_per_code(importance_matrix):
# def disentanglement(importance_matrix):
# def completeness_per_factor(importance_matrix):
# def completeness(importance_matrix):


# Path: disentanglement_lib/evaluation/metrics/dci_test.py
from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import dci
from six.moves import range
import numpy as np

    importance_matrix = np.diag(5.*np.ones(5))
    importance_matrix = np.vstack([importance_matrix, importance_matrix])
    result = dci.completeness(importance_matrix)
    np.testing.assert_allclose(result, 1. - np.log(2)/np.log(10))

  def test_missed_factors(self):
    importance_matrix = np.diag(5.*np.ones(5))
    result = dci.completeness(importance_matrix[:2, :])
    np.testing.assert_allclose(result, 1.0)

  def test_one_code_two_factors(self):
    importance_matrix = np.diag(5.*np.ones(5))
    importance_matrix = np.hstack([importance_matrix, importance_matrix])
    result = dci.completeness(importance_matrix)
    np.testing.assert_allclose(result, 1.)


class DCITest(absltest.TestCase):

  def test_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: np.array(x, dtype=np.float64)
    random_state = np.random.RandomState(0)
    scores = dci.compute_dci(
        ground_truth_data, representation_function, random_state, None, 1000,
        1000)
    self.assertBetween(scores["disentanglement"], 0.9, 1.0)
    self.assertBetween(scores["completeness"], 0.9, 1.0)

  def test_bad_metric(self):

    ground_truth_data = dummy_data.IdentityObservationsData()