def main(): length = 10 concept = Conjunction(length) function = concept.get_ideal_function() distribution = UniformDistribution(concept, length) pac_oracle = PAC_Oracle(concept, distribution) pac_alg = PAC_Algorithm(pac_oracle, length) hypo = pac_alg.learn_ideal_function(0.5, 0.1) print "FUNC IS: " + str(function) print "HYPO IS: " + str(hypo)
class TestPACAlgorithm(unittest.TestCase): def setUp(self): self.oracle = Mock() self.pac_alg = PAC_Algorithm(self.oracle, 4) def test_get_current_hypo(self): with self.assertRaises(ValueError): self.pac_alg.get_current_hypo() def test_eliminate_unfit_from_current_hypo(self): sample = [1, -1, 1, 1] self.pac_alg.eliminate_unfit_from_current_hypo(sample) self.assertEqual([1, -1, 1, 1], self.pac_alg.get_current_hypo()) sample2 = [1, -1, -1, 1] self.pac_alg.eliminate_unfit_from_current_hypo(sample2) self.assertEqual([1, -1, 0, 1], self.pac_alg.get_current_hypo())
def setUp(self): self.oracle = Mock() self.pac_alg = PAC_Algorithm(self.oracle, 4)