Esempio n. 1
0
	def mlnFileToCFactorGraph(self, file, eviFile):
		print "Create CFactorGraph from MLN file"
		mln = MLN(file)
		
		if eviFile == None:
			f = open('temp.db', 'w')
			f.close()
			evidence = evidence2conjunction(mln.combineDB('temp.db', verbose=True))
			remove('temp.db')	
		else:
			evidence = evidence2conjunction(mln.combineDB(eviFile, verbose=True))
						 		              
		return mlnToCFactorGraph(mln);
Esempio n. 2
0
	def mlnFileToFgFile(self, mlnfilename, outfilename, eviFile=None):
		print "Transforming MLN to grounded FG (in libDAI format with ordered variables)..."
		
		mln = MLN(mlnfilename, verbose=False)

		if eviFile == None:
			f = open('temp.db', 'w')
			f.close()
			evidence = evidence2conjunction(mln.combineDB('temp.db', verbose=True))
			remove('temp.db')	
		else:
			evidence = evidence2conjunction(mln.combineDB(eviFile, verbose=True))

		self.mlnToFgFile(mln, outfilename)
		print "...done"
Esempio n. 3
0
 def learn(infile, mode, dbfile, startpt=False, rigidPreds=[]):
     mln = MLN(infile)    
     #db = "tinyk%d%s" %  (k, db)
     mln.combineDB(dbfile)
     for predName in rigidPreds:
         mln.setRigidPredicate(predName)
     mln.learnwts(mode, initialWts=startpt)
     prefix = 'wts'
     if mode == 'PLL':
         tag = "pll"
     else:
         tag = mode.lower()
         if mode == 'LL' and not POSSWORLDS_BLOCKING:
             tag += "-nobl"
         if mode == 'LL_fac':
             prefix = 'fac'
     fname = ("%s.py%s.%s" % (prefix, tag, infile[3:]))
     mln.write(file(fname, "w"))
     print "WROTE %s\n\n" % fname
Esempio n. 4
0
	def mlnFileToFactorGraph(self, file, eviFile, cnf=False):
		print "Create FactorGraph from MLN file"
		mln = MLN(file)
		
		if eviFile == None:
			f = open('temp.db', 'w')
			f.close()
			evidence = evidence2conjunction(mln.combineDB('temp.db', verbose=True))
			remove('temp.db')	
		else:
			evidence = evidence2conjunction(mln.combineDB(eviFile, verbose=True))
		
		fg = self.mlnToFactorGraph(mln,cnf);
		
		# set evidence
		for i, atom in enumerate(mln.gndAtomsByIdx):
			if mln.evidence[atom] == True:
				fg.clamp(i, 1, False);
			elif mln.evidence[atom] == False:
				fg.clamp(i, 0, False);
		
		return fg;
Esempio n. 5
0
     print "              domain: a dictionary mapping domain names to lists of constants, e.g."
     print "                      \"{'dom1':['const1', 'const2'], 'dom2':['const3']}\""
     print "                      To use just the constants declared in the MLN, use \"{}\""
     print "              query, evidence: ground formulas\n" 
     print "           inferGibbs <mln file> <domain> <query> <evidence>\n"
     print "           topWorlds <mln file> <domain>\n"
     print "           test <test name>"
     print "              run the test with the given name (dev only)\n"
     print "  NOTE: This script exposes but a tiny fraction of the functionality of the MLN class!\n"
     sys.exit(0)
 if args[0] == "print":
     mln = MLN(args[1])
     mln.write(sys.stdout)
 elif args[0] == 'printGF':
     mln = MLN(args[1])
     mln.combineDB(args[2])
     mln.printGroundFormulas()
 elif args[0] == 'printGC':
     mln = MLN(args[1])
     mln.combineDB(args[2])
     mln._toCNF()
     mln.printGroundFormulas()
 elif args[0] == 'printGA':
     mln = MLN(args[1])
     mln.combineDB(args[2], groundFormulas=False)
     mln.printGroundAtoms()
 elif args[0] == "inferExact":
     mln = MLN(args[1])
     mln.combine(eval(args[2]))
     mln.inferExact(args[3], args[4])
 elif args[0] == "topWorlds":