# 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

  def test_diagonal(self):
    importance_matrix = np.diag(5.*np.ones(5))
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, 1.0)

  def test_diagonal_empty_codes(self):
    importance_matrix = np.array([[1., 0.,], [0., 1.], [0., 0.]])
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, 1.0)

  def test_zero(self):
    importance_matrix = np.zeros(shape=[10, 10], dtype=np.float64)
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, .0)

  def test_redundant_codes(self):
    importance_matrix = np.diag(5.*np.ones(5))
    importance_matrix = np.vstack([importance_matrix, importance_matrix])
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, 1.)

  def test_missed_factors(self):
    importance_matrix = np.diag(5.*np.ones(5))
    result = dci.disentanglement(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])

# 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


  def test_diagonal(self):
    importance_matrix = np.diag(5.*np.ones(5))
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, 1.0)

  def test_diagonal_empty_codes(self):
    importance_matrix = np.array([[1., 0.,], [0., 1.], [0., 0.]])
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, 1.0)

  def test_zero(self):
    importance_matrix = np.zeros(shape=[10, 10], dtype=np.float64)
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, .0)

  def test_redundant_codes(self):
    importance_matrix = np.diag(5.*np.ones(5))
    importance_matrix = np.vstack([importance_matrix, importance_matrix])
    result = dci.disentanglement(importance_matrix)
    np.testing.assert_allclose(result, 1.)

  def test_missed_factors(self):
    importance_matrix = np.diag(5.*np.ones(5))
    result = dci.disentanglement(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.disentanglement(importance_matrix)