1 / 61

Intro to Jess The Java Expert System Shell

Intro to Jess The Java Expert System Shell. By Jason Morris Morris Technical Solutions. Quotable Quotes. Each problem that I solved became a rule which served afterwards to solve other problems. - Rene Descartes. Quotable Quotes .

olympia
Download Presentation

Intro to Jess The Java Expert System Shell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Quotable Quotes Each problem that I solved became a rule which served afterwards to solve other problems.- Rene Descartes

  3. Quotable Quotes As a rule we disbelieve all the facts and theories for which we have no use. - William James

  4. Quotable Quotes Hell, there are no rules here -- we're trying to accomplish something. - Thomas A. Edison

  5. Quotable Quotes Get your facts first, and then you can distort them as much as you please. - Mark Twain

  6. Quotable Quotes If the facts don't fit the theory, change the facts.- Albert Einstein

  7. Quotable Quotes There are two rules for success: 1) Never tell everything you know. - Roger H. Lincoln

  8. Quotable Quotes Facts do not cease to exist just because they are ignored. - Aldous Huxley

  9. Agenda • What are expert systems? • What are rule-based expert systems? • Introduction to Jess • The Jess Language 5 minute break

  10. Agenda • Scripting & The Jess API • Demo 1 : Design Pattern Expert • Demo 2 : Catalog Servlet • References and Further Study • Q & A

  11. 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.

  12. Types Of Expert Systems • Neural Networks • Blackboard Systems • Belief (Bayesian) Networks • Case-Based Reasoning • Rule-Based Systems

  13. 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).

  14. When to Use Rule-Based Systems • Problem Domain = narrow, well-understood domain theory • Knowledge Representation = facts and rules • Output = recommendation • Explanation = rule firing trace • Learning Ability = generally no (but…)

  15. 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.

  16. 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.

  17. Rule-Based Expert System Architecture • Rule Base (knowledge base) • Working Memory (fact base) • Inference Engine (rule engine)

  18. 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.

  19. Inference Process • Match the facts against the rules. • Choose which rules to fire. • Execute the actions associated with the rules.

  20. How Does Jess Work? • Jess matches facts in the fact base to rules in the rule base. • The rules contain function calls that manipulate the fact base and/or other Java code. • Jess uses the Rete (ree-tee) algorithm to match patterns. • Rete network = an interconnected collection of nodes = working memory.

  21. Jess Architecture Diagram WORKING MEMORY INFERENCE ENGINE EXECUTION ENGINE PATTERN MATCHER RULE BASE AGENDA

  22. 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.

  23. 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.

  24. What? I…I can’t control my code?? Well…yes and no…but don’t worry, Calvin! Wait a minute!

  25. Thought Experiment… • Imagine writing a procedural/OOP algorithm to solve a jigsaw puzzle. • 500+ pieces, different shapes and colors. • Polymorphism runs amok! Yet we manage to solve the puzzle…

  26. Intuition and Rules • Dump the puzzle pieces on a card table in no particular order. • Your brain instinctively begins to apply rules to solve the puzzle! • What might this look like in code?

  27. Intuitive Inferencing (corner_found (piece_is_corner) => (assert corner-found) (save_piece)) Your brain “knows” what to do with a corner piece … (edge_found (piece_is_edge) => (assert edge-found) (save_piece)) … and an edge piece.

  28. What’s Going On… • Your brain recalls rules or heuristics to solve the problem. • Your brain pattern-matches, prioritizes, and applies rules according to the facts in memory. • A particular solution algorithm emerges as rules “fire” on facts.

  29. The Jess Language • Architecturally inspired by CLIPS • LISP-like syntax. • Basic data structure is the list. • Can be used to script Java API. • Can be used to access JavaBeans. • Easy to learn and use.

  30. Obligatory Tradition (printout t “Hello PJUG-ers!” crlf) Your very first Jess program!

  31. 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 Here are some valid lists in Jess:

  32. Jess Variables • Named containers that hold a single value. • Untyped. Begin with a ? mark. • Can change types during lifetime. • Assigned using bind function.

  33. 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

  34. foreach if/then/else while apply build eval progn Control Flow Common Jess-specific

  35. Jess Functions Even functions are lists. (deffunction get-input() “Get user input from console.” (bind ?s (read)) (return ?s))

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

  37. 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")

  38. 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.

  39. Jess Fact Types • Ordered – head only. • Ordered – single slot. • Unordered – multiple slot, like a database record. • Shadow – slots correspond to properties of a JavaBean.

  40. Deftemplate Used to define the structure of a fact. • (deftemplate • pattern “A design pattern.” • (slot name) • (slot type (default “creation”)) • (slot intent) • (slot solution))

  41. Asserting Facts ;; Asserting a new “pattern” fact. (printout t “Enter pattern name:” crlf) (bind ?x getInput) (assert pattern (name ?x)) Facts store the initial conditions.

  42. 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))

  43. Shadow Facts • defclass – creates a deftemplate from a bean. • definstance – adds bean to working memory. Shadow facts are unordered facts whose slots correspond to the properties of a JavaBean.

  44. 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.

  45. 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.

  46. 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))

  47. 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))

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

  49. Break Time! Let’s take a quick 5 minute pause…

  50. Scripting Java from Jess • You can interactively access all Java APIs from Jess. • This makes exploring Java somewhat easier and immediate. • No code, compile, debug cycle.

More Related