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
 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)
Beispiel #3
0
 def from_dataset_file(cls,
                       dataset_filepath,
                       content_ids=None,
                       asset_ids=None):
     dataset = cls._import_dataset_and_filter(dataset_filepath, content_ids,
                                              asset_ids)
     dataset_reader = PairedCompDatasetReader(dataset)
     return cls(dataset_reader)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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.assertEqual(np.nanmean(opinion_score_3darray), 0.8045757864632984)
     self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
     self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)
Beispiel #8
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)
     self.assertEqual(np.nanmean(opinion_score_3darray), 0.8973326075122482)
     self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
     self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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.assertEqual(np.nanmean(opinion_score_3darray), 0.8098967604129583)
     self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
     self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)
Beispiel #14
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.1)
     self.assertEqual(np.nanmin(opinion_score_3darray), 0.5)
     self.assertEqual(np.nanmax(opinion_score_3darray), 1.0)
Beispiel #15
0
def visualize_pc_dataset(dataset_filepath):

    dataset = import_python_file(dataset_filepath)
    dataset_reader = PairedCompDatasetReader(dataset)
    tensor_pvs_pvs_subject = dataset_reader.opinion_score_3darray

    plt.figure()
    # plot the rate of winning x, 0 <= x <= 1.0, of one PVS compared against another PVS
    mtx_pvs_pvs = np.nansum(tensor_pvs_pvs_subject, axis=2) \
                  / (np.nansum(tensor_pvs_pvs_subject, axis=2) +
                     np.nansum(tensor_pvs_pvs_subject, axis=2).transpose())
    plt.imshow(mtx_pvs_pvs, interpolation='nearest')
    plt.title(r'Paired Comparison Winning Rate')
    plt.ylabel(r"PVS ($j$)")
    plt.xlabel(r"PVS ($j'$) [Compared Against]")
    plt.set_cmap('jet')
    plt.colorbar()
    plt.tight_layout()
 def setUp(self):
     pc_dataset = import_python_file(
         SurealConfig.test_resource_path('lukas_pc_dataset.py'))
     self.pc_dataset_reader = PairedCompDatasetReader(pc_dataset)