# 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/sap_score.py
# def compute_sap(ground_truth_data,
#                 representation_function,
#                 random_state,
#                 artifact_dir=None,
#                 num_train=gin.REQUIRED,
#                 num_test=gin.REQUIRED,
#                 batch_size=16,
#                 continuous_factors=gin.REQUIRED):
# def _compute_sap(mus, ys, mus_test, ys_test, continuous_factors):
# def compute_sap_on_fixed_data(observations, labels, representation_function,
#                               train_percentage=gin.REQUIRED,
#                               continuous_factors=gin.REQUIRED,
#                               batch_size=100):
# def compute_score_matrix(mus, ys, mus_test, ys_test, continuous_factors):
# def compute_avg_diff_top_two(matrix):


from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import sap_score
import numpy as np
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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 sap_score.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class SapScoreTest(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 = sap_score.compute_sap(
        ground_truth_data, representation_function, random_state, None, 3000,
        3000, continuous_factors=True)
    self.assertBetween(scores["SAP_score"], 0.9, 1.0)

  def test_bad_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: np.zeros_like(x, dtype=np.float64)
    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/sap_score.py
# def compute_sap(ground_truth_data,
#                 representation_function,
#                 random_state,
#                 artifact_dir=None,
#                 num_train=gin.REQUIRED,
#                 num_test=gin.REQUIRED,
#                 batch_size=16,
#                 continuous_factors=gin.REQUIRED):
# def _compute_sap(mus, ys, mus_test, ys_test, continuous_factors):
# def compute_sap_on_fixed_data(observations, labels, representation_function,
#                               train_percentage=gin.REQUIRED,
#                               continuous_factors=gin.REQUIRED,
#                               batch_size=100):
# def compute_score_matrix(mus, ys, mus_test, ys_test, continuous_factors):
# def compute_avg_diff_top_two(matrix):


# Path: disentanglement_lib/evaluation/metrics/sap_score_test.py
from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import sap_score
import numpy as np

#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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 sap_score.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class SapScoreTest(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 = sap_score.compute_sap(
        ground_truth_data, representation_function, random_state, None, 3000,
        3000, continuous_factors=True)
    self.assertBetween(scores["SAP_score"], 0.9, 1.0)

  def test_bad_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: np.zeros_like(x, dtype=np.float64)
    random_state = np.random.RandomState(0)

    scores = sap_score.compute_sap(