Пример #1
0
 def test_priorConstraint(self):
     mln = MLN([os.path.join(self.smokingDir, "wts.smoking.mln"), os.path.join(self.smokingDir, "smoking-prior.emln")])
     mln.write(sys.stdout)
     mrf = mln.groundMRF(os.path.join(self.smokingDir, "smoking-test-peopleonly.db"))
     results = map(float, (mrf.inferEnumerationAsk("Smokes")))
     correctResults = [0.5, 0.5]
     self.assertApproxListEqual(results, correctResults, 0.01)
Пример #2
0
 def test_inferExact_inferEnumerationAsk(self):
     mln = MLN(os.path.join(self.smokingDir, "wts.smoking.mln"))
     mln.write(sys.stdout)
     mrf = mln.groundMRF(os.path.join(self.smokingDir, "smoking-test-peopleonly.db"))
     results = map(float, (mrf.inferExact(["Smokes", "Cancer"])))
     results2 = map(float, (mrf.inferEnumerationAsk(["Smokes", "Cancer"])))
     correctResults = [0.3537297423387627, 0.3537297423387627, 0.5902867352545694, 0.5902867352545694]
     self.assertApproxListEqual(results, correctResults)
     self.assertApproxListEqual(results2, correctResults)
Пример #3
0
 def test_priorConstraint(self):
     mln = MLN([
         os.path.join(self.smokingDir, "wts.smoking.mln"),
         os.path.join(self.smokingDir, "smoking-prior.emln")
     ])
     mln.write(sys.stdout)
     mrf = mln.groundMRF(
         os.path.join(self.smokingDir, "smoking-test-peopleonly.db"))
     results = map(float, (mrf.inferEnumerationAsk("Smokes")))
     correctResults = [0.5, 0.5]
     self.assertApproxListEqual(results, correctResults, 0.01)
Пример #4
0
 def test_groundAMLN(self):
     mln = MLN(os.path.join(self.studentDir, "student_course2.a.mln"))
     mrf = mln.groundMRF(self.studentDB)
     weights = map(lambda p: float(p[0]), mrf.getGroundFormulas())
     correctWeights = [
         1.5604290525533999, 3.6511741317144004, -0.7968133588156,
         7.0145072690164003, 0.151252120947, -1.6360797755282002,
         -1.5131502151878, -8.4313192249819995, -0.38454063647300002,
         -1.16283955905, 1.3519705598595, -2.8760315103522003
     ]
     self.assertApproxListEqual(weights, correctWeights)
Пример #5
0
 def test_groundWithVars(self):
     mln = MLN(
         os.path.join(self.studentDir, "student_course2_simLearned.mln"))
     mrf = mln.groundMRF(self.studentDB)
     weights = map(lambda p: float(p[0]), mrf.getGroundFormulas())
     correctWeights = [
         -0.40546510810816444, -1.0986122886681098, -0.22314355131420957,
         -1.6094379124341012, -7.3508372506616082, -0.0006422607799453446,
         -1.0986122886681098, -0.40546510810816427, -6.1468644463356723,
         -0.0021424753776469402, 27.350837250661606, 27.350837250661606
     ]
     self.assertApproxListEqual(weights, correctWeights)
Пример #6
0
 def test_inferExact_inferEnumerationAsk(self):
     mln = MLN(os.path.join(self.smokingDir, "wts.smoking.mln"))
     mln.write(sys.stdout)
     mrf = mln.groundMRF(
         os.path.join(self.smokingDir, "smoking-test-peopleonly.db"))
     results = map(float, (mrf.inferExact(["Smokes", "Cancer"])))
     results2 = map(float, (mrf.inferEnumerationAsk(["Smokes", "Cancer"])))
     correctResults = [
         0.3537297423387627, 0.3537297423387627, 0.5902867352545694,
         0.5902867352545694
     ]
     self.assertApproxListEqual(results, correctResults)
     self.assertApproxListEqual(results2, correctResults)
Пример #7
0
 def test_groundWithVars(self):
     mln = MLN(os.path.join(self.studentDir, "student_course2_simLearned.mln"))
     mrf = mln.groundMRF(self.studentDB)
     weights = map(lambda p: float(p[0]), mrf.getGroundFormulas())
     correctWeights = [-0.40546510810816444, -1.0986122886681098, -0.22314355131420957, -1.6094379124341012, -7.3508372506616082, -0.0006422607799453446, -1.0986122886681098, -0.40546510810816427, -6.1468644463356723, -0.0021424753776469402, 27.350837250661606, 27.350837250661606]
     self.assertApproxListEqual(weights, correctWeights)
Пример #8
0
 def test_groundAMLN(self):
     mln = MLN(os.path.join(self.studentDir, "student_course2.a.mln"))
     mrf = mln.groundMRF(self.studentDB)
     weights = map(lambda p: float(p[0]), mrf.getGroundFormulas())
     correctWeights = [1.5604290525533999, 3.6511741317144004, -0.7968133588156, 7.0145072690164003, 0.151252120947, -1.6360797755282002, -1.5131502151878, -8.4313192249819995, -0.38454063647300002, -1.16283955905, 1.3519705598595, -2.8760315103522003]
     self.assertApproxListEqual(weights, correctWeights)
Пример #9
0
 def test_softEvidenceMCSATPC(self):
     mln = MLN(os.path.join(self.posteriorCDir, "simple.mln"))
     mrf = mln.groundMRF(os.path.join(self.posteriorCDir, "test.db"))
     results = map(float, (mrf.inferMCSAT("attr")))
     correctResults = [0.6666666666666666, 0.10]
     self.assertApproxListEqual(results, correctResults, 0.04)
Пример #10
0
 def getSimpleLearningModel(self):
     return MLN(os.path.join(self.simpleLearnDir, "simple.mln"))
Пример #11
0
 def getSmokersModel(self):
     return MLN(os.path.join(self.smokingDir, "smoking.mln"))
Пример #12
0
 def test_softEvidenceMCSATPC(self):
     mln = MLN(os.path.join(self.posteriorCDir, "simple.mln"))
     mrf = mln.groundMRF(os.path.join(self.posteriorCDir, "test.db"))
     results = map(float, (mrf.inferMCSAT("attr")))
     correctResults = [0.6666666666666666, 0.10]
     self.assertApproxListEqual(results, correctResults, 0.04)