Intro to Jess The Java Expert System Shell

Slides:



Advertisements
Similar presentations
The Logic of Intelligence Pei Wang Department of Computer and Information Sciences Temple University.
Advertisements

CS 484 – Artificial Intelligence1 Announcements Choose Research Topic by today Project 1 is due Thursday, October 11 Midterm is Thursday, October 18 Book.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
The CLIPS Programming Tool History of CLIPS –Influenced by OPS5 and ART –Implemented in C for efficiency and portability –Developed by NASA, distributed.
Expert System Shells - Examples
Programming in Visual Basic
1 01/12/2011Knowledge-Based Systems, Paula Matuszek Intro to CLIPS Paula Matuszek CSC 9010, Spring, 2011.
Chapter 7: Introduction to CLIPS
Rule Based Systems Michael J. Watts
Chapter 12: Expert Systems Design Examples
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
1 Chapter 9 Rules and Expert Systems. 2 Chapter 9 Contents (1) l Rules for Knowledge Representation l Rule Based Production Systems l Forward Chaining.
Rules and Expert Systems
© C. Kemke Control 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
EXPERT SYSTEMS Part I.
Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.
Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.
Expert Systems Infsy 540 Dr. Ocker. Expert Systems n computer systems which try to mimic human expertise n produce a decision that does not require judgment.
Artificial Intelligence Lecture No. 15 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 14: Artificial Intelligence Invitation to Computer Science, C++ Version, Third Edition.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Production Systems A production system is –a set of rules (if-then or condition-action statements) –working memory the current state of the problem solving,
An Introduction to Programming and Algorithms. Course Objectives A basic understanding of engineering problem solving process. A basic understanding of.
Chapter 10: Procedural Programming Expert Systems: Principles and Programming, Fourth Edition.
Jess: A Rule-Based Programming Environment Reporter: Yu Lun Kuo Date: April 10, 2006 Expert System.
Java Expert System Shell JESS 報告者 : 江梓安. Why we need an expert systems? Conventional programming languages Conventional programming languages Complex.
Chapter 13 Artificial Intelligence and Expert Systems.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
1 Knowledge Based Systems (CM0377) Lecture 10 (Last modified 19th March 2001)
Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.
Artificial Intelligence Lecture No. 19 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
Artificial Intelligence
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
Artificial Intelligence Knowledge Representation.
The CLIPS Expert System Shell Dr Nicholas Gibbins
Summary for final exam Agent System..
Business Rules Engine in Java Introduction to JBoss Rules by Tom Sausner.
Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
User-Written Functions
Intelligent Systems JESS constructs.
Python: Experiencing IDLE, writing simple programs
PROGRAMMING LANGUAGES
Intro to Jess The Java Expert System Shell
Chapter 9. Rules and Expert Systems
Principles of programming languages 4: Parameter passing, Scope rules
Variables, Expressions, and IO
Architecture Components
Chapter 7: Introduction to CLIPS
Knowledge Representation
Intro to PHP & Variables
PL/SQL Scripting in Oracle:
Computer Programming.
Intro to Expert Systems Paula Matuszek CSC 8750, Fall, 2004
Artificial Intelligence
Chapter 8: Advanced Pattern Matching
Java Programming Loops
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Chapter 11: Classes, Instances, and Message-Handlers
KNOWLEDGE REPRESENTATION
JESS (Java Expert System Shall)
Jess Knowledge, Influence, Behavior
Intro to Jess The Java Expert System Shell
Java Programming Loops
Chapter 9. Rules and Expert Systems
Data Structures & Algorithms
Presentation transcript:

Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions

Agenda What are expert systems? What are rule-based expert systems? Introduction to Jess The Jess Language We’ll just briefly define what expert systems are. Then we’ll introduce rule-based systems. Next, we’ll jump into Jess and talk about how it differs from other programming paradigms. While there, we’ll look at the Jess scripting language and the Jess API To tie it all together, we’ll examine a small expert system to assist with choosing an appropriate design pattern for a given application. Finally, we'll list some references and places where you can get more info.

Expert Systems… Are a branch of artificial intelligence. Simulate human reasoning in some domain. “Reason” by heuristic or approximate methods. Explain and justify solutions in user-friendly terms. A human expert must also explain how he/she arrived at a particular solution.

Types Of Expert Systems Neural Networks Blackboard Systems Belief (Bayesian) Networks Case-Based Reasoning Rule-Based Systems Neural Nets are the quintessential expert system of science fiction fame – Hal 9000 for example. Non-structured data redundantly linked via multiple paths and massively parallel processed by multiple CPUs. The Blackboard metaphor is an interesting approach that models a collection of domain experts all trying to solve a complex problem. Each expert module tries to solve parts of the problem specific to its domain. Belief (Bayesian) Networks were originally researched as an approach to modeling natural language. Use a probabilistic approach to finding solutions. Case-Based Reasoning uses pattern-matching mimicking the way humans recall previously previous problem solutions. Derived solutions are based on similarity to an existing solution that best fits the problem parameters. Successful solutions are integrated into the case-base. Example would be chess masters who recall patterns of previous games and stratagems rather than calculate from first principles. Rule-Based Systems are the oldest and most researched form of expert system architecture. They simulate the reasoning that human experts use to arrive at conclusions by using first principles or “rules of thumb” called heuristics.

Rule-Based Expert Systems Originated from AI research in the 70s and 80s. Problem data stored as facts. “Reason” using IF…THEN…ELSE rules. Can “reason” deductively (forward-chaining) or inductively (backward-chaining). The DENDRAL Project (1965-83) One of the earliest expert systems. DENDRAL began as an effort to explore the mechanization of scientific reasoning and the formalization of scientific knowledge by working within a specific domain of science, organic chemistry. Think of a fact as a “truth McNugget”. :-D

Inference Process Rules and facts compared using pattern matcher. Matched rules activated into a conflict set. Conflict set resolved into agenda (process called conflict resolution). Rule engine fires on agenda. Engine cycles until all rules are satisfied. The interesting thing is that rules can add, delete, or alter facts in the working memory. They can also call other code (Jess functions or Java methods) The rule engine fires only once on any given set of facts in working memory.

The Java Expert System Shell Developed at Sandia National Laboratories in late 1990s. Created by Dr. Ernest J. Friedman-Hill. Inspired by the AI production rule language CLIPS. Fully developed Java API for creating rule-based expert systems. Jess came along when Java was very young! According to Dr. Friedman-Hill, Jess was nearly implemented in a hacked kind of C! CLIPS was developed by the Johnson Space Center at NASA in the early 80s. BTW - There is also an Object-Oriented version of CLIPS called COOL (CLIPS Object Oriented Language)

Rule-Based Expert System Architecture Rule Base (knowledge base) Working Memory (fact base) Inference Engine (rule engine) This is the typical architecture common to rule-based systems.

Rule-Based Expert System Architecture

Inference (Rule) Engines Pattern Matcher – decides what rules to fire and when. Agenda – schedules the order in which activated rules will fire. Execution Engine – responsible for firing rules and executing other code. This mechanism underscores a key difference between procedural programming and declarative programming.

Inference Process Match the facts against the rules. Choose which rules to fire. Execute the actions associated with the rules. We’ll have more to say when we get to the section on creating rules on exactly how Jess matches facts to rules.

Procedural Programming Traditional programming (BASIC, C, FORTRAN, Pascal, etc.). Largely based on functions. Programmer controls logic. Sequential and deterministic. Object-oriented programming is procedural within object methods. Ohhh! Ordinarily, I practice cliché-free presenting, but here I’ll break my own rule and say that we are are entering a “paradigm shift” zone – that is to say that programming in rules is not that same as programming in other procedural or object-oriented languages.

Declarative Programming New programming paradigm - rules. Programmer does not really control code logic. Rule engine finds most efficient “path” of code execution. Replaces hard to maintain nested IF…THEN…ELSE coding. New in the sense that it may be new to you… the paradigm actually goes back to the 1940s.

Your very first Jess program! Obligatory Tradition Your very first Jess program! (printout t “Hello PJUG-ers!” crlf) The “t” is a parameter that directs to standard output. Q. What do you notice?? Any LISP folks here? :-D A. The whole statement is a list!

Lists in Jess Here are some valid lists in Jess: (a b c) ; list of tokens (1 2 3) ; list of integers (+ 2 3) ; an expression (“Hello world!”) ; a string (foo ?x ?y) ; a function call Again the head of a list has a special connotation – Jess looks to see if it’s a function.

Jess Variables Named containers that hold a single value. Untyped. Begin with a ? mark. Can change types during lifetime. Assigned using bind function. OK… I am referring to Jess “script” variables, obviously not anything inside Java code that uses the Jess API. This is not uncommon in scripting languages in view of the simplified syntax and coding it affords. For example, JavaScript variables are untyped as well.

Jess Variables and Lists Everything is a list in Jess! EXAMPLE: Adding two numbers (bind ?x 2) ; assign x = 2 (bind ?y 3) ; assign y = 3 (bind ?result (+ ?x ?y)) ; find sum Like LISP, Jess expressions are evaluated from the inside out, passing their resulting values to the next level of nesting.

Control Flow Common Jess-specific foreach if/then/else while apply build eval progn Apply – calls a function on a given set of arguments. Build – parses and executes a function from a string. Eval - parses and executes a function from a string. Progn – like an in-line function call…like an anonymous method in LISP.

Jess Functions Even functions are lists. (deffunction get-input() “Get user input from console.” (bind ?s (read)) (return ?s)) Q. So how would you write a call to calculate the area of sphere 2 meters in radius? Pass a list to the Jess interpreter containing the function name at the head of the list and then the expected parameters. So given a function like (deffunction area-sphere (?radius) “Calculate the area of a sphere” (bind ?area (* (* (pi) 2) (* ?radius ?radius))) (return ?area)) We could ask Jess to print out: (printout t "The surface area of a radius = 2 meter sphere is " + (area-sphere 1) + " m^2")

Jess Function Example (deffunction area-sphere (?radius) “Calculate the area of a sphere” (bind ?area (* (* (pi) 2)(* ?radius ?radius))) (return ?area))

Jess Function Example How do we use this in Jess? (printout t "The surface area of a radius = 2 meter sphere is " + (area-sphere 2) + " m^2")

Working With Facts Facts have a head and one or more slots. Slots hold data (can be typed). Multislots can hold lists. You can modify slot values at runtime. Facts are constructed from templates. 1. We’ll take a look at some facts in the next slides. 2. You can explicitly specify the type of data in a slot when you define the fact in a template. 3. The multislot can appear anywhere in the list of slots in a fact. 4. Facts are like physical objects in the system. Rules are like actions to be performed.

Jess Fact Types Ordered – head only. Ordered – single slot. Unordered – multiple slot, like a database record. Shadow – slots correspond to properties of a JavaBean. I promise not to make some lame “just the facts” joke. :-D That’s a subreference to the old show Dragnet for you younger programmers.

Deftemplate Used to define the structure of a fact. (deftemplate pattern “A design pattern.” (slot name) (slot type (default “creation”)) (slot intent) (slot solution)) Facts can be asserted with slots in any order. Omitted slots use default values. Unspecified default values are null.

Asserting Facts Facts store the initial conditions. ;; Asserting a new “pattern” fact. (printout t “Enter pattern name:” crlf) (bind ?x getInput) (assert pattern (name ?x)) Recall the getInput function that we wrote a few slides back… that read a line of input from the console. The Jess command Assert adds a fact to working memory.

All Kinds of Facts ;; An ordered fact with no slots – a placeholder that indicates state. (assert(answer-is-valid)) ;; A ordered fact of one slot (assert(weightfactor 0.75)) The ordered fact with no slots is like a “truth-McNugget”, a “trigger” that sets off other rules by indicating a change in state of the problem space. This is the most common usage of ordered facts. The ordered fact with a single value is like problem parameter that other rules can use later… imagine a predicate constraint that says: (defrule check-valid-weight ?wf <- (weightfactor ?f) (answer ?x&: (<= 0.5 (* ?f ?x))) => (assert ((answeris-valid)) As long as there is no conflict with any fact template, you can assert facts without the assert function. Consider: Q. How would you use the (answer-is-valid) fact? A. You would write a rule that looks for the presence of a (answer-is-valid) fact in working memory, then takes some action if it finds one.

Jess Rules… … are the knowledge-base of the system. … fire only once on a given set of facts. … use pattern constraints to match facts. … are much faster than IF-THEN statements. Rules really are the repository of the knowledge elicited from the human expert emulated by the expert system. Think about the second item here…what does that imply? Faster in the sense that the Rete algorithm optimizes the order in which the rules are fired.

Rule Syntax Rules have a “left-hand” side (LHS) and a “right-hand” side (RHS). The LHS contains facts fitting certain patterns. The RHS contains function calls.

Simple Rule Example Checking working memory state. ;; A not very useful error handler (defrule report-error (error-is-present) => (printout t “There is an error” crlf)) Q. Ok… now what does this mean? If I told you that the symbol “=>” is read as “THEN”, can you discern the meaning of the rule? A. The rule looks in working memory for the presence of a fact of type (error-is-present) [BTW – what kind of fact is this?] (ordered with no slots) THEN if that fact is in working memory, Jess prints a statement to the console stating that fact.

A More Complex Rule Using pattern bindings in rules. ;; A more useful error handler (defrule report-err ?err <- (is-error (msg ?msg)) => (printout t "Error was: " ?msg crlf) (retract ?err)) This illustrates some interesting Jess abilities… Q. Can you guess at what the code above the => does? A. It looks for a fact of type is-error with any msg slot. The cool thing is that the variable ?msg is now available on the RHS of the rule! A reference to the matched fact object is stored in ?err. The RHS can use that “pointer” to modify, retract, or duplicate that fact.

More Pattern and Control Tools matching control and structure Literal / variable constraints Logical conditional tests Predicate functions Salience Modules Defquery Backward-chaining

Q & A Thanks for your attention, and I hope that you try Jess!