# 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/strong_downstream_task.py
# def compute_strong_downstream_task(ground_truth_data,
#                                    representation_function,
#                                    random_state,
#                                    artifact_dir=None,
#                                    num_train=gin.REQUIRED,
#                                    num_test=gin.REQUIRED,
#                                    n_experiment=gin.REQUIRED):
# def _compute_loss(x_train, y_train, x_test, y_test, predictor_fn):
# def _compute_loss_intervene(factors_train, factors_test, predictor_fn,
#                             ground_truth_data, representation_function,
#                             random_state, n_experiment=10):
# def intervene(y_train, y_test, target_y, num_factors, ground_truth_data):
# 
# Path: disentanglement_lib/evaluation/metrics/utils.py
# def generate_batch_factor_code(ground_truth_data, representation_function,
#                                num_points, random_state, batch_size):
# def split_train_test(observations, train_percentage):
# def obtain_representation(observations, representation_function, batch_size):
# def discrete_mutual_info(mus, ys):
# def discrete_entropy(ys):
# def make_discretizer(target, num_bins=gin.REQUIRED,
#                      discretizer_fn=gin.REQUIRED):
# def _histogram_discretize(target, num_bins=gin.REQUIRED):
# def normalize_data(data, mean=None, stddev=None):
# def make_predictor_fn(predictor_fn=gin.REQUIRED):
# def logistic_regression_cv():
# def gradient_boosting_classifier():


from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import strong_downstream_task
from disentanglement_lib.evaluation.metrics import utils
import numpy as np
import gin.tf
    ground_truth_data = dummy_data.DummyData()

    random_state = np.random.RandomState(0)

    ys_train = ground_truth_data.sample_factors(1000, random_state)
    ys_test = ground_truth_data.sample_factors(1000, random_state)
    num_factors = ys_train.shape[1]
    for i in range(num_factors):
      (y_train_int, y_test_int, interv_factor,
       factor_interv_train) = strong_downstream_task.intervene(
           ys_train.copy(), ys_test.copy(), i, num_factors, ground_truth_data)
      assert interv_factor != i, "Wrong factor interevened on."
      assert (y_train_int[:, interv_factor] == factor_interv_train
             ).all(), "Training set not intervened on."
      assert (y_test_int[:, interv_factor] != factor_interv_train
             ).all(), "Training set not intervened on."

  def test_task(self):
    gin.bind_parameter("predictor.predictor_fn",
                       utils.gradient_boosting_classifier)
    gin.bind_parameter("strong_downstream_task.num_train",
                       [1000])
    gin.bind_parameter("strong_downstream_task.num_test",
                       1000)
    gin.bind_parameter("strong_downstream_task.n_experiment",
                       2)
    ground_truth_data = dummy_data.DummyData()
    def representation_function(x):
      return np.array(x, dtype=np.float64)[:, :, 0, 0]
    random_state = np.random.RandomState(0)

# 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/strong_downstream_task.py
# def compute_strong_downstream_task(ground_truth_data,
#                                    representation_function,
#                                    random_state,
#                                    artifact_dir=None,
#                                    num_train=gin.REQUIRED,
#                                    num_test=gin.REQUIRED,
#                                    n_experiment=gin.REQUIRED):
# def _compute_loss(x_train, y_train, x_test, y_test, predictor_fn):
# def _compute_loss_intervene(factors_train, factors_test, predictor_fn,
#                             ground_truth_data, representation_function,
#                             random_state, n_experiment=10):
# def intervene(y_train, y_test, target_y, num_factors, ground_truth_data):
# 
# Path: disentanglement_lib/evaluation/metrics/utils.py
# def generate_batch_factor_code(ground_truth_data, representation_function,
#                                num_points, random_state, batch_size):
# def split_train_test(observations, train_percentage):
# def obtain_representation(observations, representation_function, batch_size):
# def discrete_mutual_info(mus, ys):
# def discrete_entropy(ys):
# def make_discretizer(target, num_bins=gin.REQUIRED,
#                      discretizer_fn=gin.REQUIRED):
# def _histogram_discretize(target, num_bins=gin.REQUIRED):
# def normalize_data(data, mean=None, stddev=None):
# def make_predictor_fn(predictor_fn=gin.REQUIRED):
# def logistic_regression_cv():
# def gradient_boosting_classifier():


# Path: disentanglement_lib/evaluation/metrics/strong_downstream_task_test.py
from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import strong_downstream_task
from disentanglement_lib.evaluation.metrics import utils
import numpy as np
import gin.tf

    ground_truth_data = dummy_data.DummyData()

    random_state = np.random.RandomState(0)

    ys_train = ground_truth_data.sample_factors(1000, random_state)
    ys_test = ground_truth_data.sample_factors(1000, random_state)
    num_factors = ys_train.shape[1]
    for i in range(num_factors):
      (y_train_int, y_test_int, interv_factor,
       factor_interv_train) = strong_downstream_task.intervene(
           ys_train.copy(), ys_test.copy(), i, num_factors, ground_truth_data)
      assert interv_factor != i, "Wrong factor interevened on."
      assert (y_train_int[:, interv_factor] == factor_interv_train
             ).all(), "Training set not intervened on."
      assert (y_test_int[:, interv_factor] != factor_interv_train
             ).all(), "Training set not intervened on."

  def test_task(self):
    gin.bind_parameter("predictor.predictor_fn",
                       utils.gradient_boosting_classifier)
    gin.bind_parameter("strong_downstream_task.num_train",
                       [1000])
    gin.bind_parameter("strong_downstream_task.num_test",
                       1000)
    gin.bind_parameter("strong_downstream_task.n_experiment",
                       2)
    ground_truth_data = dummy_data.DummyData()
    def representation_function(x):
      return np.array(x, dtype=np.float64)[:, :, 0, 0]
    random_state = np.random.RandomState(0)

    scores = strong_downstream_task.compute_strong_downstream_task(