1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 6 – Arithmetic, fail and the cut.
Some Prolog Prolog is a logic programming language
Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
Chapter 11 :: Logic Languages
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Situation Calculus for Action Descriptions We talked about STRIPS representations for actions. Another common representation is called the Situation Calculus.
First Order Logic Resolution
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
1 Knowledge Based Systems (CM0377) Lecture 8 (Last modified 5th March 2001)
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
James Tam Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CPSC 322 Introduction to Artificial Intelligence September 20, 2004.
Proof System HY-566. Proof layer Next layer of SW is logic and proof layers. – allow the user to state any logical principles, – computer can to infer.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Fundamentals of Python: From First Programs Through Data Structures
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Fundamentals of Python: First Programs
Formal Models of Computation Part II The Logic Model
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Chapter 2 - Algorithms and Design
Chapter 10: Procedural Programming Expert Systems: Principles and Programming, Fourth Edition.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
CSC 211 Data Structures Lecture 13
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Halting Problem Introduction to Computing Science and Programming I.
1 Predicate (Relational) Logic 1. Introduction The propositional logic is not powerful enough to express certain types of relationship between propositions.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Pascal Programming Pascal Loops and Debugging. Pascal Programming Pascal Loops In our first brush with the while do loops, simple comparisons were used.
Programming Languages Third Edition Chapter 4 Logic Programming.
Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Testing CSE 160 University of Washington 1. Testing Programming to analyze data is powerful It’s useless (or worse!) if the results are not correct Correctness.
Knowledge Based Information System
Logic: Proof procedures, soundness and correctness CPSC 322 – Logic 2 Textbook §5.2 March 7, 2011.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
For Friday No reading Prolog Handout 2. Homework.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Answer Extraction To use resolution to answer questions, for example a query of the form  X C(X), we must keep track of the substitutions made during.
1 TP #2: How does Prolog answer questions? n Miscellaneous info; n Last TP exercises solved; n How does Prolog answer questions? n Recursive Prolog programs;
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
Logic Programming Lecture 2: Unification and proof search.
Section 16.5, 16.6 plus other references
Introduction To Repetition The for loop
Tests, Backtracking, and Recursion
Probabilistic Horn abduction and Bayesian Networks
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006

2 Content Starting CILOG Syntax Ask and Tell Loading and Listing Knowledge Bases Explanation and Debugging Ask-the-user Built-in predicates Assumables Negation-as-failure Probabilities

3 CILOG CILOG is a purely declarative representation and reasoning system. CILOG runs in SWI Prolog. SWI-Prolog is an open Prolog environment

4 Starting CILOG load the file cilog2.pl into Prolog cilog2.pl for SWI Prolog, version 5.3 or later The basic system prompt is: cilog: Some commands: cilog: help. cilog: quit. cilog: prolog. | ?- start.

5 Syntax Variable Constant david, comp_intell, ciLOG, and a45_23 123, -5, 1.0, … ’X’, ’2b˜2b’, ’../ch2/foo.pl’, ’A Tall Person’ Term a variable, a constant, or of the form f (t 1,..., t n ) Atom p or p(t 1,..., t n )

6 Syntax (cont) Body either an atom, of the form α&β, where α and β are bodies, or of the form ˜α, where α is a body. Clause either an atom or is a rule of the form h<-b where h is an atom (the head of the clause) and b is a body.

7 Ask and Tell cilog: tell clause. cilog: ask query.

8 Ask and Tell (Cont) After given an answer, you can reply with: ok. to indicate that you don’t want any more answers more. to ask for more answers how. to investigate how that answer was produced help. to get a menu of available answers

9 Example 1

10 Example 1 (cont)

11 Loading and Listing Knowledge Bases cilog: load ’filename’. cilog: clear. cilog: clear atom. cilog: listing. cilog: listing atom.

12 Loading and Listing Knowledge Bases (cont) Load a file that uses Prolog syntax cilog: prload ’filename’. This assumes the clauses in the file use the Prolog implication :- and use a comma for conjunction.

13 Loading and Listing Knowledge Bases (cont) check the knowledge base cilog: check. This lists the rules in the knowledge base with atoms in the body which don’t unify with the head of any clause in the knowledge base. This is a simple check that the rule can never be used in a proof. It is more useful in that it can be done before asking any queries, it finds clauses that contain atoms that must immediately fail.

14 Explanation and Debugging The main power of CILOG is in the explanation and debugging facilities. These fall into three classes: determining how an answer was proved determining why a potential answer wasn’t produced determining why the search is in a particular state

15 How? Questions When you ask how atom h was proved, it produces the instance of the rule in the knowledge base with h as the head that succeeded: h <- 1: a 1 2: a 2 … k: a k which indicates that the rule h <- a 1 & a 2 &...& a k was used to prove h.

16 How? Questions (cont) You can then give one of: how i. (1 ≤ i ≤ k) This means that you want to see how a i was proved. up. to go back to see the rule with h in the body. If h is the initial query it goes back to the answer interaction. retry. to ask for a different proof tree. ok. to exit the how traversal and go back to the answer prompt. help. for a list of the available commands.

17 Example 2

18 Example 2 (cont)

19 Whynot? Questions You can ask a query to determine why some query failed using: cilog: whynot query.

20 Whynot? Questions (cont) If the query is an atom, you can examine each rule whose head unifies with the query. For each such rule, the system asks whether you want to trace this rule. You can reply with: yes. to determine why this rule failed. You should give this answer when this rule should have succeeded for this query. no. to ask for another rule. You give this answer if this rule should have failed for this query. up. to return to a previous choice point (the rule in which the atom appears, or else the top-level if the atom was the initial query). ok. to return to the top-level. help. to get a menu of available answers.

21 Whynot? Questions (cont) To determine why a rule failed, we determine why the body failed. The body is atomic: we use the whynot mechanism to determine why the rule failed. The body of the rule is a conjunction, α &β, there are four cases: α fails, in which case we should use recursively use the whynot mechanism to determine why it failed. an instance of α succeeds, but should not have succeeded. In this case we can use the how mechanism to debug this proof. This case arises because β may have rightfully failed on the instance of α that succeeded. an instance of α succeeds, but this instance should have lead to failure of the conjunction. In this case we should look for another proof for α. an instance of α succeeds that should lead to the success of the conjunction, in which case we need to determine why β failed on this instance.

22 Whynot? Questions (cont) Thus, when there is a conjunctive body, we first try to prove the leftmost conjunct. If it fails, we use the whynot mechanism to determine why it failed. If it succeeds, the user is asked Should this answer lead to a successful proof? The user can reply: yes. this instance should have made the body succeed. Thus you need to debug the rest of the conjunction. no. this instance should lead to a failure of the body. Thus you need to try another proof for this atom. debug. this instance is false, debug it. This enters the how interaction. ok. to return to the top-level. help. to get a menu of available answers.

23 Example 3 Suppose we had the knowledge base from Example 1. Suppose that, the user knew that Joe had a child called Jane, and wanted to know why the system didn’t think that Randy was Jane’s grandfather.

24

25 Depth Bound The depth bound is set using the command: cilog: bound n. n is a bound on the depth of any proof tree.

26 Depth Bound (cont) When no more answers can be found and the search was cut off due to hitting the depth-bound, the user is informed of this, as is given the option of one of: i. where i is an integer bigger than the current depth-bound. This lets the user explore larger search trees. Repeatedly increasing the depth-bound lets the user simulate an iterative deepening search. where. to let the user explore the place where the depth-bound was reached. ok. to go back to the answer prompt. help. for a list of the available commands.

27 Depth Bound (cont) When the user given the where command, the proof is retried, and it halts at a point where the depth-bound was reached, and shows the user the current subgoal, g. The user can give one of the following commands: fail. to fail g, and explore other places where the depth-bound was reached. succeed. to say that g should succeed. proceed. to fail g and not explore any more subgoals where the depth-bound was reached. why. to let the user explore why g was called. ok. to go back to the answer prompt. help. for a list of the available commands.

28 Why? Questions Ask: why an atom was being asked h <- 1: a 1 2: a 2 … ** j: a j … k: a k

29 Why? Questions (cont) When this is presented you can ask one of: how i. where i is an integer 1 i < j. This means that you want to see how a i was proved. This enters the how dialog. how j. This means that you want to see how CILOG is trying to prove a j (the atom you have previously asked why about). This returns to the rule with a j in the body. why. to see the rule with h in the body. prompt. to return to the CILOG prompt. help. for a list of the available commands.

30 Why? Questions (cont) You can’t ask how i for i > j as there is no proof tree for the atoms a j+1... a k ; CILOG does not guarantee that the rule given will have the atoms in the body in the same order as in the knowledge base; CILOG is free to change the order of atoms in a body as long as this doesn’t introduce an error.

31 Example 4 It shows a trace of a looping program that reaches the depth bound. We first increase the depth-bound, and then explore where the depth-bound was reached.

32 Example 4 (cont)

33

34

35 Ask-the-user To to make an atom askable, you can issue the command: cilog:askable atom. Is g true? The user can reply with one of: yes. no. unknown. if g is unknown. In this case any applicable clauses for g can be used. fail. to fail the subgoal (but not record an answer). This is only used to test you axiomatization. why. prompt. to return to the cilog prompt. help. Example:…

36 Built-in predicates X < Y X > Y X =< Y X >= Y X =\= Y V is E number(N)

37 Example 5 The following shows a simple use of is and >. It shows how we can use variables in the expressions, as long as they are bound before (to the left) they are used.

38 Assumables To to make an atom assumable, you can issue the command: cilog: assumable atom. The interaction between assumables and negation as failure is unsatisfactory, in that ˜g succeeds if there is provably no explanation of g.

39 Example 6

40 Assumables (cont) To create a set of nogoods to ensure that all explanations are consistent, you can issue the command: cilog: create_nogoods. To list all of the nogoods, you can issue the command: cilog: nogoods.

41 Negation-as-failure Negation as finite failure is implemented. Use ˜G to mean the negation of expression G. G must be ground (i.e., contain no variables) when ˜G is called; this may be fixed in future implementations. The interaction of negation as failure and the depth-bound is handled correctly. There is a problem with negation and why questions; sometimes the rule written out omits some negation symbols. This only occurs when non-atomic formulae are negated. The interaction of negation as failure with assumables isn’t satisfactory. It is recommended that you don’t use both assumables and negation as failure. Negation as failure does work with probabilities.

42 Probabilities CILOG contains support for first-order probabilistic reasoning. You can have probabilities associated with atoms that have no associated rules defining them. There atoms are grouped into disjoint sets that correspond to random variables. You can define these probabilistic assumptions using either: cilog: prob atom :probability.

43 Probabilities (cont) The alternative syntax is to write: cilog: prob a 1 : p 1, a 2 : p 2, …, a k : p k. Where the p i are non-negative numbers that sum to 1 and the a i are atoms that share the same variables. In this case every ground instantiation of the a i s forms a random variable: the a i s are mutually exclusive and covering.

44 Probabilities (cont) We also allow statements where the probability is free, for example in: cilog: prob heads_happens(E,P):P.

45 Probabilities (cont) Two main interfaces to the probabilistic reasoning: cilog: observe body. cilog: predict query.

46 Probabilities (cont) Given any prediction or observations you can inspect the explanations of the query. An explanation corresponds to a proof of the query based on a set of the probabilistic atoms. For each of these explanations you can examine the proof tree, and ask how that explanation was computed. This can either be done after a proof, or as a stand- alone command: cilog: explanations.

47 Probabilities (cont) You can also ask for the worlds in which the query and all of the previous explanations are true. This gives a set of descriptions of possible worlds where the possible worlds are described in terms of the probabilistic atoms that are true in them, and the descriptions are mutually exclusive. This can be used form computing the probability of the query (by summing over all of the worlds where it is true). The worlds are computed from the explanations by making sure that they are mutually exclusive. This can either be done after a prediction or observation or by issuing the command: cilog: worlds.

48 Probabilities (cont) cilog: unobserve. cilog: unobserve all. cilog: probs.

49 Probabilities (cont) Note that probabilities integrates cleanly with negation as failure and naively with the depth-bounded search. (It fails if the probability cannot be computed due to the depth-bound. A more sophisticated version may give bounds on the probability.) Probabilistic hypotheses and non-probabilistic hypotheses (using assumable) are not integrated and should not be used together.

50 Example 7 A belief network with Boolean variable A as a parent of variable B can be represented as:

51 Example 7 (cont)