コード例 #1
0
    def test_select_merge_components_random_raisesError(self):
        ''' Verify that when comp 0 is excluded with K=3
          we cannot provide comp 0 as kA, [error is raised]
          AND
          in free choice, we only choose kA=1, kB=2
    '''
        MT = MergeTracker(3)
        MSelector = MergePairSelector()

        MT.excludeList = set([0])
        MT._synchronize_and_verify()
        for trial in range(10):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       kA=1,
                                                       mergename='random')
            assert kA == 1
            assert kB == 2
        for trial in range(10):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       kA=2,
                                                       mergename='random')
            assert kA == 1
            assert kB == 2
        with self.assertRaises(AssertionError):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       mergename='random',
                                                       kA=0)
コード例 #2
0
  def test_select_merge_components_random_raisesErrorAllButOneExcluded(self):
    ''' Verify that when comps 0,1 are excluded with K=3
          we cannot provide comp 2 as kA, [error is raised]
    '''
    MT = MergeTracker(3)
    MSelector = MergePairSelector()

    MT.excludeList = set([1, 0])
    MT._synchronize_and_verify()
    with self.assertRaises(AssertionError):
      kA, kB = MSelector.select_merge_components(None, None, MT, mergename='random', kA=2)
コード例 #3
0
  def test_select_merge_components_random_raisesError(self):
    ''' Verify that when comp 0 is excluded with K=3
          we cannot provide comp 0 as kA, [error is raised]
          AND
          in free choice, we only choose kA=1, kB=2
    '''
    MT = MergeTracker(3)
    MSelector = MergePairSelector()

    MT.excludeList = set([0])
    MT._synchronize_and_verify()
    for trial in range(10):
      kA, kB = MSelector.select_merge_components(None, None, MT, kA=1, mergename='random')
      assert kA == 1
      assert kB == 2
    for trial in range(10):
      kA, kB = MSelector.select_merge_components(None, None, MT, kA=2, mergename='random')
      assert kA == 1
      assert kB == 2
    with self.assertRaises(AssertionError):
      kA, kB = MSelector.select_merge_components(None, None, MT, mergename='random', kA=0)
コード例 #4
0
    def test_select_merge_components_random_raisesErrorAllButOneExcluded(self):
        ''' Verify that when comps 0,1 are excluded with K=3
          we cannot provide comp 2 as kA, [error is raised]
    '''
        MT = MergeTracker(3)
        MSelector = MergePairSelector()

        MT.excludeList = set([1, 0])
        MT._synchronize_and_verify()
        with self.assertRaises(AssertionError):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       mergename='random',
                                                       kA=2)
コード例 #5
0
 def test_select_merge_components_random(self):
   ''' Verify that under random choices, we select among 3 components
         equally often
   '''
   MT = MergeTracker(3)
   MSelector = MergePairSelector()
   counts = np.zeros(3)
   for trial in range(1000):
     kA, kB = MSelector.select_merge_components(None, None, MT, mergename='random')
     counts[kA] += 1
     counts[kB] += 1
   counts /= np.sum(counts)
   minFrac = 0.25
   maxFrac = 0.4
   # Uniform at random means fraction of choice should be ~1/3 for each
   assert np.all(counts > minFrac)
   assert np.all(counts < maxFrac)
コード例 #6
0
 def test_select_merge_components_random(self):
     ''' Verify that under random choices, we select among 3 components
       equally often
 '''
     MT = MergeTracker(3)
     MSelector = MergePairSelector()
     counts = np.zeros(3)
     for trial in range(1000):
         kA, kB = MSelector.select_merge_components(None,
                                                    None,
                                                    MT,
                                                    mergename='random')
         counts[kA] += 1
         counts[kB] += 1
     counts /= np.sum(counts)
     minFrac = 0.25
     maxFrac = 0.4
     # Uniform at random means fraction of choice should be ~1/3 for each
     assert np.all(counts > minFrac)
     assert np.all(counts < maxFrac)