Ejemplo n.º 1
0
    def __init__(self,
                 campaign_id=None,
                 originpath=None,
                 localpath=None,
                 outputpath='.',
                 logfile=None):
        '''
        Constructor
        '''
        MultiArmedBandit.__init__(self)
        #         self.campaign_id = campaign_id
        self.seedfile_output_base_dir = outputpath

        self.originpath = originpath
        self.localpath = localpath
        # TODO: merge self.outputpath with self.seedfile_output_base_dir
        self.outputpath = outputpath

        self.origindir = None
        self.localdir = None
        self.outputdir = None

        if logfile:
            hdlr = logging.FileHandler(logfile)
            logger.addHandler(hdlr)

        logger.debug('SeedfileSet output_dir: %s',
                     self.seedfile_output_base_dir)
Ejemplo n.º 2
0
class Test(unittest.TestCase):

    def setUp(self):
        self.mab = BayesianMultiArmedBandit()
        self.arms = 'abcdefghijklmnopqrstuvwxyz'
        for arm in self.arms:
            self.mab.add(arm, arm)

    def tearDown(self):
        pass

    def test_next(self):
        i = 1
        n = 1000
        limit = n * len(self.arms)
        from collections import defaultdict
        seen = defaultdict(int)
        for arm in self.mab:
            if i > limit:
                break
            seen[arm] += 1
            i += 1

        for arm in self.arms:
            # ensure we saw each arm about n times
            share = seen[arm] / float(n)
            self.assertLessEqual(0.9, share)
            self.assertGreaterEqual(1.1, share)

    def test_iter(self):
        self.assertIs(self.mab, self.mab.__iter__())

    def test_score(self):
        for key in 'abcdefghijklmnopqrstuvwxy':
            arm = self.mab.arms[key]
            self.assertEqual(0.5, arm.probability)
            arm.update(successes=0, trials=198)
            self.assertEqual(0.005, arm.probability)
        # we haven't touched z yet, so it should be fairly
        # high probability
        zarm = self.mab.arms['z']
        self.assertEqual(0.5, zarm.probability)
        scaled = self.mab._scaled_scores
        self.assertEqual(0.8, scaled['z'])
        for key in 'abcdefghijklmnopqrstuvwxy':
            arm = self.mab.arms[key]
            self.assertEqual(0.005, arm.probability)
            self.assertEqual(0.008, scaled[key])
        # go ahead and pull z
        zarm.update(successes=0, trials=198)
        scaled = self.mab._scaled_scores
        for key in self.arms:
            # now they should all be equal again
            arm = self.mab.arms[key]
            self.assertEqual(0.005, arm.probability)
            self.assertAlmostEqual(1.0 / len(self.arms), scaled[key], 6)
    def __init__(self, low, high):
        MultiArmedBandit.__init__(self)

        self.min = low
        self.max = high
        # the lowest range must have at least abs_min as its max
        # so that we don't wind up fuzzing a range of 0.000000:0.000000
        self.abs_min = 0.000001
        if self.max < self.min:
            raise RangeFinderError('max cannot be less than min')

        self._set_ranges()
Ejemplo n.º 4
0
    def __init__(self, low, high):
        MultiArmedBandit.__init__(self)

        self.min = low
        self.max = high
        # the lowest range must have at least abs_min as its max
        # so that we don't wind up fuzzing a range of 0.000000:0.000000
        self.abs_min = 0.000001
        if self.max < self.min:
            raise RangeFinderError('max cannot be less than min')

        self._set_ranges()
    def __init__(self, campaign_id=None, originpath=None, localpath=None,
                 outputpath='.', logfile=None):
        '''
        Constructor
        '''
        MultiArmedBandit.__init__(self)
#         self.campaign_id = campaign_id
        self.seedfile_output_base_dir = outputpath

        self.originpath = originpath
        self.localpath = localpath
        # TODO: merge self.outputpath with self.seedfile_output_base_dir
        self.outputpath = outputpath

        self.origindir = None
        self.localdir = None
        self.outputdir = None

        if logfile:
            hdlr = logging.FileHandler(logfile)
            logger.addHandler(hdlr)

        logger.debug(
            'SeedfileSet output_dir: %s', self.seedfile_output_base_dir)
    def next_item(self):
        '''
        Returns a seedfile object selected per the scorable_set object.
        Verifies that the seedfile exists, and removes any nonexistent
        seedfiles from the set
        '''
        if not len(self.things):
            raise SeedfileSetError

        while len(self.things):
            logger.debug('Thing count: %d', len(self.things))
            # continue until we find one that exists, or else the set is empty
            sf = MultiArmedBandit.next(self)
            if sf.exists():
                # it's still there, proceed
                return sf
            else:
                # it doesn't exist, remove it from the set
                logger.warning(
                    'Seedfile no longer exists, removing from set: %s', sf.path)
                self.del_item(sf.md5)
Ejemplo n.º 7
0
    def next_item(self):
        '''
        Returns a seedfile object selected per the scorable_set object.
        Verifies that the seedfile exists, and removes any nonexistent
        seedfiles from the set
        '''
        if not len(self.things):
            raise SeedfileSetError

        while len(self.things):
            logger.debug('Thing count: %d', len(self.things))
            # continue until we find one that exists, or else the set is empty
            sf = MultiArmedBandit.next(self)
            if sf.exists():
                # it's still there, proceed
                return sf
            else:
                # it doesn't exist, remove it from the set
                logger.warning(
                    'Seedfile no longer exists, removing from set: %s',
                    sf.path)
                self.del_item(sf.md5)
Ejemplo n.º 8
0
 def setUp(self):
     self.mab = BayesianMultiArmedBandit()
     self.arms = 'abcdefghijklmnopqrstuvwxyz'
     for arm in self.arms:
         self.mab.add(arm, arm)