# 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/factor_vae.py
# def compute_factor_vae(ground_truth_data,
#                        representation_function,
#                        random_state,
#                        artifact_dir=None,
#                        batch_size=gin.REQUIRED,
#                        num_train=gin.REQUIRED,
#                        num_eval=gin.REQUIRED,
#                        num_variance_estimate=gin.REQUIRED):
# def _prune_dims(variances, threshold=0.):
# def _compute_variances(ground_truth_data,
#                        representation_function,
#                        batch_size,
#                        random_state,
#                        eval_batch_size=64):
# def _generate_training_sample(ground_truth_data, representation_function,
#                               batch_size, random_state, global_variances,
#                               active_dims):
# def _generate_training_batch(ground_truth_data, representation_function,
#                              batch_size, num_points, random_state,
#                              global_variances, active_dims):


from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import factor_vae
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 factor_vae.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class FactorVaeTest(absltest.TestCase):

  def test_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: x
    random_state = np.random.RandomState(0)
    scores = factor_vae.compute_factor_vae(
        ground_truth_data, representation_function, random_state, None, 5, 3000,
        2000, 2500)
    self.assertBetween(scores["train_accuracy"], 0.9, 1.0)
    self.assertBetween(scores["eval_accuracy"], 0.9, 1.0)

  def test_bad_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = np.zeros_like
    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/factor_vae.py
# def compute_factor_vae(ground_truth_data,
#                        representation_function,
#                        random_state,
#                        artifact_dir=None,
#                        batch_size=gin.REQUIRED,
#                        num_train=gin.REQUIRED,
#                        num_eval=gin.REQUIRED,
#                        num_variance_estimate=gin.REQUIRED):
# def _prune_dims(variances, threshold=0.):
# def _compute_variances(ground_truth_data,
#                        representation_function,
#                        batch_size,
#                        random_state,
#                        eval_batch_size=64):
# def _generate_training_sample(ground_truth_data, representation_function,
#                               batch_size, random_state, global_variances,
#                               active_dims):
# def _generate_training_batch(ground_truth_data, representation_function,
#                              batch_size, num_points, random_state,
#                              global_variances, active_dims):


# Path: disentanglement_lib/evaluation/metrics/factor_vae_test.py
from absl.testing import absltest
from disentanglement_lib.data.ground_truth import dummy_data
from disentanglement_lib.evaluation.metrics import factor_vae
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 factor_vae.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class FactorVaeTest(absltest.TestCase):

  def test_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = lambda x: x
    random_state = np.random.RandomState(0)
    scores = factor_vae.compute_factor_vae(
        ground_truth_data, representation_function, random_state, None, 5, 3000,
        2000, 2500)
    self.assertBetween(scores["train_accuracy"], 0.9, 1.0)
    self.assertBetween(scores["eval_accuracy"], 0.9, 1.0)

  def test_bad_metric(self):
    ground_truth_data = dummy_data.IdentityObservationsData()
    representation_function = np.zeros_like
    random_state = np.random.RandomState(0)

    scores = factor_vae.compute_factor_vae(