pyGM: File Input/Output

pyGM/filetypes.py

Read / write methods for graphical model file types (UAI, WCSP, etc.)

readUai / writeUai : read/write UAI competition file format readEvidence10, readEvidence14 : read/write UAI, Ergo evidence formats (14: single evidence) readErgo : read Ergo Bayes Net format readWCSP / writeWCSP : read/write WCSP weighted CSP format

Version 0.0.1 (2015-09-28) (c) 2015 Alexander Ihler under the FreeBSD license; see license.txt for details.

pyGM.filetypes.Limid2MMAP(C, D, U)[source]

Convert LIMID factors into MMAP factors & query variable list

Example:

>>> C,D,U = readLimid(filename)
>>> factors,query = Limid2MMAP(C,D,U) 

See also readLimid().

pyGM.filetypes.LimidCRA2MMAP(C, D, U)[source]

Convert CRA LIMID factors into MMAP factors & query variable list (Not Implemented)

Example:

>>> factors,query = LimidCRA2MMAP(C,D,U) 

See also readLimidCRA().

pyGM.filetypes.readDSL(filename)[source]

Read GeNIe XML DSL format Bayesian network

pyGM.filetypes.readErgo(filename)[source]

Read in a Bayesian network (list of conditional probabilities) specified in ERGO format

Example:

>>> factor_list,names,labels = readErgo( 'path/filename.erg' )

See e.g. http://graphmod.ics.uci.edu/group/Ergo_file_format for details

pyGM.filetypes.readEvidence10(evidence_file)[source]

Read UAI-2010 evidence file

The 2010 specification allowed multiple evidence configurations in the same file:

>>>  evList = readEvidence10('path/file.uai.evid') 

Returns a list of evidence configurations; evList[i] is a dictionary, { Xi : xi , … } indicating that variable Xi = value xi.

pyGM.filetypes.readEvidence14(evidence_file)[source]

Read a UAI-2014 format evidence file

The 2014 specification allowed only one evidence configuration per file:

>>> ev = readEvidence14('path/file.uai.evid') 

Returns an evidence configuration as a dictionary, { Xi : xi , … }, indicating that variable Xi = value xi.

pyGM.filetypes.readFileByTokens(path, specials=[])[source]

Helper function for parsing pyGM file formats

pyGM.filetypes.readFileByTokensNEW(path, specials=[])[source]

Helper function for parsing pyGM file formats

pyGM.filetypes.readLimid(filename)[source]

Read in a LIMID file (Maua format)

Example: get CPTs for chance nodes C, uniform policies D, and utilities U:

>>>  C,D,U = readLimid(filename) 

See e.g. https://github.com/denismaua/kpu-pp TODO: may have an error in variable orderings? Hard to tell from Denis’ page. TODO: seems to expect multiplicative utility functions?

pyGM.filetypes.readLimidCRA(filename)[source]

Read in a LIMID file specified by our format with Charles River.

Example:

>>> fChance,fDecision,fUtil = readLimidCRA( 'path/filename.uai' )
pyGM.filetypes.readOrder(filename)[source]

Read an elimination order from a file

Elimination orders are stored as unknown length vectors, format “[nvar] [v0] [v1] … [vn]”

Note: the same file format may also be useful for MPE configurations, etc.

pyGM.filetypes.readTEST(filename)[source]

Read in a collection (list) of factors specified in UAI (2006-?) format

Example:

>>> factor_list = readUai( 'path/filename.uai' )
pyGM.filetypes.readUai(filename)[source]

Read in a collection (list) of factors specified in UAI (2006-?) format

Example:

>>> factor_list = readUai( 'path/filename.uai' )
pyGM.filetypes.readWCSP(filename)[source]

Read in a weighted CSP (list of neg-log factors) specified in WCSP format

Example:

>>> factor_list,name,upperbound = readWCSP( 'path/filename.wcsp' )

See e.g. http://graphmod.ics.uci.edu/group/WCSP_file_format

pyGM.filetypes.writeOrder(filename, order)[source]

Write an elimination order (or other vector) to a file

pyGM.filetypes.writeUai(filename, factors)[source]

Write a list of factors to <filename> in the UAI competition format

pyGM.filetypes.writeWCSP(filename, factors, upper_bound=None, use_float=False)[source]

Write ‘filename’ in weighted CSP format

(see http://graphmod.ics.uci.edu/group/WCSP_file_format)