# 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.evaluation.metrics import utils
import numpy as np
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for utils.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class UtilsTest(absltest.TestCase):

  def test_histogram_discretizer(self):
    # Input of 2D samples.
    target = np.array([[0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
                       [0.6, .5, .4, .3, .2, .1]])
    result = utils._histogram_discretize(target, num_bins=3)
    shouldbe = np.array([[1, 1, 2, 2, 3, 3], [3, 3, 2, 2, 1, 1]])
    np.testing.assert_array_equal(result, shouldbe)

  def test_discrete_entropy(self):
    target = np.array([[1, 1, 2, 2, 3, 3], [3, 3, 2, 2, 1, 1]])
    result = utils.discrete_entropy(target)
    shouldbe = np.log(3)
    np.testing.assert_allclose(result, [shouldbe, shouldbe])

  def test_discrete_mutual_info(self):
    xs = np.array([[1, 2, 1, 2], [1, 1, 2, 2]])
    ys = np.array([[1, 2, 1, 2], [2, 2, 1, 1]])

# 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/utils_test.py
from absl.testing import absltest
from disentanglement_lib.evaluation.metrics import utils
import numpy as np

# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for utils.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class UtilsTest(absltest.TestCase):

  def test_histogram_discretizer(self):
    # Input of 2D samples.
    target = np.array([[0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
                       [0.6, .5, .4, .3, .2, .1]])
    result = utils._histogram_discretize(target, num_bins=3)
    shouldbe = np.array([[1, 1, 2, 2, 3, 3], [3, 3, 2, 2, 1, 1]])
    np.testing.assert_array_equal(result, shouldbe)

  def test_discrete_entropy(self):
    target = np.array([[1, 1, 2, 2, 3, 3], [3, 3, 2, 2, 1, 1]])
    result = utils.discrete_entropy(target)
    shouldbe = np.log(3)
    np.testing.assert_allclose(result, [shouldbe, shouldbe])

  def test_discrete_mutual_info(self):
    xs = np.array([[1, 2, 1, 2], [1, 1, 2, 2]])
    ys = np.array([[1, 2, 1, 2], [2, 2, 1, 1]])

    result = utils.discrete_mutual_info(xs, ys)