Reference

tddlog.solve(program, *, format='problog', evidence=None, vtree='auto', evidence_probability=False, queries=True, arguments=None)

Read program, text in format, then ground, compile and count it, and return the answers to its queries.

format names what the text is, as the command line tells it by the file’s extension: "problog", the default (an LPAD where it holds :- begin_lpad.), "dice", "circulette" (a .cql netlist), or a network’s: "bif", "hugin" (.net), "xdsl" or "uai". A network’s variables are each queried at every value, and evidence is the text of its evidence file, as the command line’s --evidence reads it: a UAI .evid file for a UAI network, an Ace .inst file for any other.

vtree is the command line’s --vtree: "auto", the default, or one of the layouts it lists. evidence_probability=True also computes P(e), compiling the evidence no query depends on rather than dropping it. queries=False leaves out the program’s queries, as --no-queries does, and needs evidence_probability=True. arguments, a list of strings, are a ProbLog program’s, an LPAD’s or a Dice program’s arguments, the values the command line takes after the program’s file: each the text of a term that takes the places $1, $2, … of the program, as in solve("$1::a. query(a).", arguments=["0.3"]); in a Dice program a place stands for an integer, and its argument is a natural number.

An unknown format or vtree, evidence for a program that is not a network, arguments for a network, an argument that is not a term (for a Dice program, not a natural number) or that no place takes, or options that ask for nothing raise ValueError; a place without an argument raises tddlog.ParseError; a program tddlog cannot answer raises a subclass of tddlog.Error. The interpreter lock is released for the whole run.

class tddlog.Solution

The answers to a program’s queries, and the probability of its evidence where solve was asked for it.

answers

A dict from each query, as ProbLog prints it (\+ before a negative one), to its probability, in the program’s order; None where the evidence is inconsistent.

evidence_probability

P(e), the probability of the evidence: 1.0 with none, 0.0 where it is inconsistent, and 0.0 too where it is under the least float, which log10_evidence_probability still gives. For a UAI network, the partition function given the evidence, as the command line’s Z: line. None unless solve was called with evidence_probability=True.

log10_evidence_probability

The base-10 logarithm of P(e), exact beyond a float’s range: -inf where the evidence is inconsistent. None unless solve was called with evidence_probability=True.

exception tddlog.Error

A program tddlog could not answer: the base of ParseError, GroundingError and CompilationError.

exception tddlog.ParseError

The program is not in the language or the format it is said to be in.

exception tddlog.GroundingError

The program parses but cannot be ground: an unsupported construct or a rule that is not range restricted.

exception tddlog.CompilationError

The ground program could not be compiled and counted under the vtree strategy asked for, or the well-founded model of some world leaves an atom undefined.