Techniqueadvanced
Knowledge compilation
Also called offline compilation of knowledge bases.
Translates a knowledge base once, offline, into a target language in which the queries asked online, such as entailment or model counting, take polynomial time in the size of the result.
Knowledge compilation splits reasoning into two phases. Offline, a knowledge base, typically a propositional formula in CNF, is translated once into a target language in which the questions of interest are easy. Online, each question is answered from the compiled form in time polynomial in its size. The offline phase may be expensive, since it often solves an NP-hard problem, but its cost is shared by all the questions that follow. This page is the general method and how to apply it; the knowledge compilation map page compares the target languages, and the d-DNNF and SDD pages describe two of them in detail.
In plain words
Some questions about a set of rules are hard every time you ask them, for example "is this fact a consequence of the rules?" If the rules stay the same and you ask many such questions, you can do the hard work once. Rewrite the rules in a special form, chosen so that each question becomes a quick walk over the rewritten form. The rewriting can be slow and the result can be large, but you do it only once, before the questions arrive. The right form depends on which questions you will ask and how the rules will change. Some forms make counting easy, some make combining two rule sets easy, and no form makes everything easy without becoming very large for some rules.
When it applies
- The knowledge base changes rarely, and many queries are asked against it. Examples are a product configurator with fixed constraints, a diagnosis model of a fixed device, or a probabilistic model that answers many queries under different evidence.
- The queries are hard on the original form: SAT, clause entailment, model counting, or equivalence.
- There is a target language that supports the needed queries in polynomial time, and the knowledge base has a compiled form of manageable size in that language. The second condition depends on the structure of the input and cannot be guaranteed in general: unless NP is contained in P/poly, no target language with polynomial clause entailment has polynomial-size compiled forms for all CNFs (results of Selman and Kautz and of Cadoli and Donini, as stated by Darwiche and Marquis 2002). By the Karp-Lipton theorem, that inclusion would collapse the polynomial hierarchy.
- Online answers must be fast and predictable, for example in an interactive tool or an embedded device, where the cost of a SAT call per query is not acceptable.
The template
COMPILE-THEN-QUERY(Σ, Q) ▷ Σ is the knowledge base, Q the stream of queries- 1
L ← ⟨target language⟩ that supports in polynomial time the queries and transformations that Q needs - 2
C ← ⟨compiler⟩(Σ, L) ▷ offline, once; C is equivalent to Σ - 3
for each query q in Q do - 4
if q changes the knowledge base then C ← ⟨transformation⟩(C, q) - 5
else answer q by ⟨polynomial query⟩(C, q)
The holes are:
- target language (L1). Choose it from the tables of the map: the queries (consistency, validity, clause entailment, model counting, equivalence, and others) and the transformations (conditioning, conjunction, disjunction, negation, forgetting) that the application needs. Among the languages that support them, prefer the most succinct, since it has the smallest compiled forms.
- compiler (L2). Top-down compilers run an exhaustive search and record its trace; exhaustive DPLL with component splitting and caching gives a decision-DNNF (Huang and Darwiche 2007). Bottom-up compilers build the form of each clause and combine them with a conjunction operation, as with the apply of OBDDs and SDDs.
- transformation (L4). Conditioning on evidence is polynomial in all the usual languages; conjunction of two compiled forms is polynomial for OBDDs with a fixed order but not for d-DNNF unless P = NP. A d-DNNF can be conjoined with one clause in polynomial time, as the disjunction over of conditioned on these literals, which is deterministic, decomposable and of size ; but the size can grow by such a factor with each added clause.
- polynomial query (L5). One or more passes over the compiled form, such as the bottom-up count of a smooth d-DNNF.
Why it pays. Let compilation take time , a query on the compiled form take time , and the same query on take time . Answering queries costs with compilation and without, so compilation pays off once . For hard queries is exponential in the worst case and is linear in , so the break-even point is small when is.
Why correctness is easy to state. A compiler must return a form that is equivalent to , or for counting, has the same models over the same variables. Every query then has the same answer on as on . A compiler that drops this requirement and returns a weaker or stronger theory gives approximate answers, as in the Horn approximations below.
Classic examples
- CNF to d-DNNF for counting and probabilities. A CNF, or the encoding of a Bayesian network as a CNF with weights, is compiled by exhaustive search into a d-DNNF. Then model counting, weighted counting under any evidence and clause entailment are each one linear pass. The compiler bears the #P-hard part once.
- Circuits to OBDDs for verification. A combinational circuit, or the transition relation of a system, is compiled into an OBDD for a fixed variable order. Equivalence of two circuits is then a comparison of two roots, and symbolic model checking applies conjunction and existential quantification to OBDDs again and again. Here the transformations matter as much as the queries.
- Prime implicates for entailment. The set of prime implicates of a CNF supports clause entailment by a subset test: a clause is entailed if and only if it contains some prime implicate. The dual form uses prime implicants. Both can be exponentially larger than the input, and conjoining a set of prime implicates with a new clause is not polynomial (Darwiche and Marquis 2002, Table 7).
- Incremental compilation with SDDs. When the knowledge base grows by conjunction with new constraints, a sentential decision diagram for a vtree chosen from the structure of the problem keeps the canonical form and an apply operation, and for some functions it is exponentially smaller than every OBDD, as the SDD page explains.
Variations
- Approximate compilation. Selman and Kautz (1996) compute a Horn theory that entails and a Horn theory that entails, and entailment from a Horn theory takes linear time. If then , and if then ; only the queries between the two need the full theory.
- Compilation that uses structure. Darwiche (2001) compiles a CNF of treewidth into a DNNF of size linear in the number of variables and exponential only in . SDDs have a similar bound for their vtrees. These bounds explain why compilation works for many structured inputs despite the general lower bound.
- Compiling to a query, not a language. When only one kind of query will be asked, for example a fixed set of variables to count over, the compiler can drop the parts of the knowledge base that the query cannot see, such as by forgetting the other variables first in a language that supports forgetting.
- Choosing the language by the map. The map gives, for each language, its polynomial queries and transformations and its place in the succinctness order, and so turns the choice in L1 into a lookup.
Pitfalls
- Size blowup. The compiled form can be exponential in the input, and for some inputs every equivalent form in a given language is. Measure the size on real inputs before you commit to compilation; the time and size of a compiler are measurements on benchmarks, not guarantees.
- The wrong transformations. d-DNNF supports conditioning but not conjunction of two compiled forms in polynomial time unless P = NP. An application that adds clauses after compilation must recompile or pick a language with polynomial conjunction, such as OBDD with a fixed order.
- Variable order and vtree. The size of an OBDD or SDD depends strongly on the variable order or the vtree, from linear to exponential for the same function. A poor choice can make compilation fail on inputs that a good choice handles easily.
- Counting over the wrong variables. A compiled form that does not mention a variable of the original problem still counts it as free; the model count must be taken over all the variables of the input, which may need smoothing.
- Unsound shortcuts. A compiler that is not exactly equivalent to , for example one that drops clauses it considers redundant without proof, gives wrong answers to every later query.
Exercises
- Show that the CNF has prime implicants, so its smallest DNF has terms, while it has an OBDD with inner nodes for the order .
- Show that a language that supports consistency and conditioning in polynomial time also supports clause entailment in polynomial time.
- A SAT call on a knowledge base takes 2 seconds, compilation takes 600 seconds, and a query on the compiled form takes 1 millisecond. After how many queries does compilation pay off?
- Give a CNF with variables whose d-DNNF from the compiler of the d-DNNF page has size linear in , but which is not a Horn formula and has no Horn equivalent.
References
- Adnan Darwiche and Pierre Marquis, A knowledge compilation map, Journal of Artificial Intelligence Research 17, 2002, Table 5 on page 239 (queries) and Table 7 on page 242 (transformations); the cited result of Selman and Kautz and of Cadoli and Donini that no compilation of polynomial size gives polynomial clause entailment unless NP is in P/poly (general locator)
- Adnan Darwiche, Decomposable negation normal form, Journal of the ACM 48(4), 2001, pages 608 to 647 (a compiler from CNF to DNNF and the bound for CNFs of bounded treewidth)
- Jinbo Huang and Adnan Darwiche, The language of search, Journal of Artificial Intelligence Research 29, 2007, pages 191 to 219 (the traces of exhaustive search as compiled forms, from OBDD and FBDD to decision-DNNF)
- Bart Selman and Henry Kautz, Knowledge compilation and theory approximation, Journal of the ACM 43(2), 1996, Horn upper and lower bounds of a clausal theory as an approximate compilation (general locator)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag 4H7SHT Edit this page History Report an error Markdown