def setUp(self):
     dataset_filepath = SurealConfig.test_resource_path(
         'NFLX_dataset_public_raw.py')
     dataset = import_python_file(dataset_filepath)
     dataset_reader = RawDatasetReader(dataset)
     pc_dataset = dataset_reader.to_pc_dataset(pc_type='within_subject')
     self.pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
Beispiel #2
0
class RawDatasetReaderPCTest(unittest.TestCase):
    def setUp(self):
        dataset_filepath = SurealConfig.test_resource_path(
            'NFLX_dataset_public_raw.py')
        dataset = import_python_file(dataset_filepath)
        self.dataset_reader = RawDatasetReader(dataset)

    def test_dataset_to_pc_dataset(self):
        pc_dataset = self.dataset_reader.to_pc_dataset()
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertEqual(np.nanmean(opinion_score_3darray), 0.816039603960396)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_within_subject(self):
        pc_dataset = self.dataset_reader.to_pc_dataset(
            pc_type='within_subject')
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 80106)
        self.assertEqual(np.nanmean(opinion_score_3darray), 0.8050935185278244)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_coin_toss(self):
        pc_dataset = self.dataset_reader.to_pc_dataset(
            tiebreak_method='coin_toss')
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertEqual(np.nanmean(opinion_score_3darray), 1.0)
        self.assertEqual(np.nanmin(opinion_score_3darray), 1.0)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_random(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(randomness_level=0.5)
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        # check: python2 values seem to fluctuate quite a bit
        self.assertAlmostEqual(np.nanmean(opinion_score_3darray),
                               0.85,
                               delta=0.1)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_sampling_rate(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(sampling_rate=0.1)
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 844)
        self.assertAlmostEqual(np.nanmean(opinion_score_3darray),
                               0.85,
                               delta=0.1)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_per_asset_sampling_rates(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(
            per_asset_sampling_rates=np.hstack(
                [np.ones(39), np.ones(40) * 0.1]))
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 4550)
        self.assertAlmostEqual(np.nanmean(opinion_score_3darray),
                               0.85,
                               delta=0.1)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)
Beispiel #3
0
class RawDatasetReaderPCTest(unittest.TestCase):

    def setUp(self):
        dataset_filepath = SurealConfig.test_resource_path('NFLX_dataset_public_raw.py')
        dataset = import_python_file(dataset_filepath)
        self.dataset_reader = RawDatasetReader(dataset)

    def test_dataset_to_pc_dataset(self):
        pc_dataset = self.dataset_reader.to_pc_dataset()
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertEqual(np.nanmean(opinion_score_3darray), 0.816039603960396)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_within_subject(self):
        pc_dataset = self.dataset_reader.to_pc_dataset(pc_type='within_subject')
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 80106)
        self.assertEqual(np.nanmean(opinion_score_3darray), 0.8050935185278244)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_coin_toss(self):
        pc_dataset = self.dataset_reader.to_pc_dataset(tiebreak_method='coin_toss')
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertEqual(np.nanmean(opinion_score_3darray), 1.0)
        self.assertEqual(np.nanmin(opinion_score_3darray), 1.0)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_random(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(cointoss_rate=0.5)
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        # check: python2 values seem to fluctuate quite a bit
        self.assertAlmostEqual(float(np.nanmean(opinion_score_3darray)), 0.8966492602262838, delta=0.01)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_sampling_rate(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(sampling_rate=0.1)
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 844)
        self.assertAlmostEqual(float(np.nanmean(opinion_score_3darray)), 0.8107588856868396, delta=0.0001)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_sampling_rate_greater_than_1(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(sampling_rate=2.1)
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertAlmostEqual(float(np.nanmean(opinion_score_3darray)), 0.816039603960396, delta=0.0001)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_per_asset_sampling_rates(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(per_asset_sampling_rates=np.hstack([np.ones(39), np.ones(40) * 0.1]))
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 4546)
        self.assertAlmostEqual(float(np.nanmean(opinion_score_3darray)), 0.8116303960042811, delta=0.01)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_per_asset_cointoss_rates(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(per_asset_cointoss_rates=np.hstack([np.ones(39), np.ones(40) * 0.1]))
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertAlmostEqual(float(np.nanmean(opinion_score_3darray)), 0.91102022769979, delta=0.01)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_per_asset_noise_levels(self):
        import random
        random.seed(0)
        pc_dataset = self.dataset_reader.to_pc_dataset(per_asset_noise_levels=np.hstack([np.ones(39), np.ones(40) * 0.1]))
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 8242)
        self.assertAlmostEqual(float(np.nanmean(opinion_score_3darray)), 1.0, delta=0.0001)
        self.assertEqual(np.nanmin(opinion_score_3darray), 1.0)
        self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)

    def test_dataset_to_pc_dataset_within_subject_per_asset_mean_scores(self):
        pc_dataset = self.dataset_reader.to_pc_dataset(pc_type='within_subject', per_asset_mean_scores=np.ones(79))
        pc_dataset_reader = PairedCompDatasetReader(pc_dataset)
        opinion_score_3darray = pc_dataset_reader.opinion_score_3darray
        self.assertEqual(np.nansum(opinion_score_3darray), 80106)
        self.assertEqual(np.nanmean(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
        self.assertEqual(np.nanmax(opinion_score_3darray), 0.5)