CSE 415 -- (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 1 CSE 415 Production Systems Many AI programs are “data driven.” The program examines.

Slides:



Advertisements
Similar presentations
Neofunctionalism Ernst Haas. Assumptions (i) Regional basis (ii) Central institutions crucial (iii) Advanced industrial societies (iv) International/domestic.
Advertisements

Hamlet /Media Outline. I. Thesis Statement: (Director)s To be or not to be and (director)s Alas poor Yorick best exemplify William Shakespeares original.
Reagan/Clinton Compare/Contrast Essay. I. Reagan and Clinton both argue... but... A.Reagan argues B.Clinton argues.
Boost Spirit V2 A cookbook style guide to parsing and output generation in C++ Joel de Guzman Hartmut Kaiser
CSE 341, S. Tanimoto Pattern Matching - 1 Pattern Matching in Lisp Lists can be used to represent sentences, relations, tree structures, etc. (this list.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
1 Series RLC Resonant Circuit V s = 10 Vrms, R = 10 , L = 100 mH, C = 10  F VsVs R L C I + V R - + V L - +VC-+VC-   (varied) Assignment #1: Part.
Lecture 7 C Pointers Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Minimal Neural Networks Support vector machines and Bayesian learning for neural networks Peter Andras
PrasadAbstraction1 VEDIC MATHEMATICS : Abstraction T. K. Prasad
Mathematics Shape and Space: Polygon Angles Science and Mathematics Education Research Group Supported by UBC Teaching and Learning Enhancement Fund
Roman Numerals. Roman Numerals - Past and Present  Romans used them for trading and commerce.  When Romans learned to write they needed a way to write.
man/html/RomanMatch.htmlhttp://fi.edu/time/keepers/Silver man/html/RomanMatch.html Please open above link and play a.
Roman Numerals. The Numbers I-1 II-2 III-3 IV-4 V-5 VI-6 VII-7 VIII-8 IX-9 X-10 C-100 D-500 M-1000.
Computer Science 101 Introduction to Programming.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
A Plan That Builds an Essay
Making an Outline A Plan That Builds a Strong Report Report
G © Math As A Second Language All Rights Reserved Roman Numerals next and The Super Bowl.
General Programming Introduction to Computing Science and Programming I.
Computer Science 101 Introduction to Programming.
Roman Numerals Learning objective: To learn how to count using Roman numerals.
CSE (c) S. Tanimoto, 2008 Production Systems 1 Production Systems Many AI programs are “data driven.” The program examines the data, and then it.
Computer Science 101 Introduction to Programming.
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
DATA REPRESENTATION, DATA STRUCTURES AND DATA MANIPULATION TOPIC 4 CONTENT: 4.1. Number systems 4.2. Floating point binary 4.3. Normalization of floating.
Python Jim Eng Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages.
JavaScript: The First Parts Part Three Douglas Crockford Yahoo! Inc.
Roman Numeral Multiplication Quiz
Medical Math Health Occupations Education Mrs. Rose.
Presentation on Number System
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
What is History? Presentation #3 Mr. Bridgeo. How do we measure or retrace the evolution of societies? The unit of time that historians use to measure.
Getting Started: Research Paper
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
¸üµÖŸÖ ×¿ÖÖÖ ÃÖÓãÖÖ,ÃÖÖ ŸÖÖ¸üÖ ú´ÖÔ¾Ö߸ü ×¾ÖªÖ¯ÖϲÖÖê× ¬Ö­Öß, ´Ö¬µÖ ×¾Ö³Ö֐Ö, ÃÖÖŸÖÖ¸üÖ ¿ÖÖ»ÖêµÖ †³µÖÖÃ֍Îú´ÖÖ­ÖãÃÖÖ¸ ÃÖÓãÖêŸÖᯙ ÃÖê¾ÖúÖÓ­Öß ŸÖµÖÖ¸ü.
I’M MR. KRIEGER WELCOME!!!!. WHAT DO I TEACH? Math I/E Writing History.
The Household God (Lar Familiaris) recites the prologue. I.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Roman Numerals. A Brief History of Roman Numerals Roman numerals originated in ancient Rome. This ancient counting system is believed to have started.
Flexible and fast convergent learning agent Miguel A. Soto Santibanez Michael M. Marefat Department of Electrical and Computer Engineering University of.
CSE S. Tanimoto Pattern Matching 1 Pattern Matching Many Lisp programs are “data driven”. The program exams the data and then decides how to process.
Introduction to Computing Science and Programming I
CSC1018F: Regular Expressions
Introduction to Python
Containers and Lists CIS 40 – Introduction to Programming in Python
CSE (c) S. Tanimoto, 2002 AI Techniques
Printing Lines of Asterisks
Variables, Expressions, and IO
Natural Language Understanding
27 Amendments XV (15) rights not to be denied because of race XVI (16)
Flow diagrams (i) (ii) (iii) x – Example
LATIN NUMBERS.
Roman Numerals Adding value to letters I, V, X, L, C, D, M 11/30/2018.
Roman Numerals.
Write these notes in your spirals!
CSE (c) S. Tanimoto, 2004 AI Techniques
Advanced Python Concepts: Exceptions
Roman Numerals.
Roman Numerals.
Roman Numerals.
Advanced Python Concepts: Exceptions
Roman numerals -Rules for writing.
Data Structures in Lisp
Data Structures in Lisp
Roman Numerals.
Roman Numerals.
To be able to explore Roman Numerals up to 100
Presentation transcript:

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 1 CSE 415 Production Systems Many AI programs are “data driven.” The program examines the data, and then it decides how to process it. Rule-based programming: the program consists of a collection of rules and a means for applying them.

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 2 Production System Architecture

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 3 Production System Form A rule of the form G if [condition] then [action] is sometimes called a production rule. Python’s if statement can be used to implement rule testing and application. If input=='Why?': return explain()

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 4 Example: Conversion to Roman Numerals 0 = 1 = I 2 = II 3 = III 4 = IV 5 = V 6 = VI 7 = VII 8 = VIII 9 = IX 10 = X 11 = XI 12 = XII 13 = XIII 14 = XIV 15 = XV 16 = XVI 17 = XVII 18 = XVIII 19 = XIX 20 = XX 30 = XXX 40 = XL 50 = L 60 = LX 70 = LXX 80 = LXXX 90 = XC 100 = C 500 = D 1000 = M

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 5 Example Production System If x is null, then prompt the user and read x. If x is not null and is bigger than 39, then print ``too big'' and make x null. If x is not null and is between 10 and 39, then print ``X'' and reduce x by 10. If x is not null and is equal to 9, then print ``IX'' and reduce x to 0. If x is not null and is between 5 and 8, then print ``V'' and reduce x by 5. If x is not null and is equal to 4, then print ``IV'' and reduce x to 0. If x is not null and is between 1 and 3, then print ``I'' and reduce x by 1. If x is not null and is equal to 0, then print an end-of-line and make x null.

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 6 Ordered vs Unordered Production Systems We’ve just seen an “unordered” production system. Permuting the rules does not change the behavior of an unordered system. Easy to add new rules, remove rules Condition testing typically is redundant In an ordered system, the rule order is important and errors might occur if the rules are permuted. Harder to add and remove rules without breaking the system Condition testing is less redundant

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 7 Python Implementation of an Ordered Production Systems # Roman2.py def Roman2(): """Roman numeral conversion with ordered Production System""" x = ''; ans = '' while True: if x=='': x = input('Enter number: ') elif x > 39: print 'too big'; x = '' elif x > 9: ans += 'X'; x -= 10 elif x == 9: ans += 'IX'; x = 0 elif x > 4: ans += 'V'; x -= 5 elif x == 4: ans += 'IV'; x = 0 elif x > 0: ans += 'I'; x -= 1 elif x == 0: print ans; x = ''; ans = '' else: print 'bad number'; break

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 8 Discrimination Nets In order to speed up condition testing, Structure the search for a matching condition as a tree search rather than a linear search.

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 9 Application to Dialog-Style Interaction The ELIZA program was written by Joseph Weizenbaum at the Massachusetts Institute of Technology’s Artificial Intelligence Lab in the late 1960s. It was written in Lisp, and demonstrated how, through clever pattern matching and phrase transformation, an illusion of an intelligent agent could be created.

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 10 The Shrink The Shrink is a small program modeled after Weizenbaum’s ELIZA program to demonstrate production-system programming. This version of the Shrink is written in Python, and works by converting the user’s raw string inputs into lists of words. It then looks for particular words in these word lists.

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 11 Application to Dialog-Style Interaction User: “I am full of anticipation.” Shrink: “Please tell me why you are full of anticipation.” The Shrink’s production rule, in Python: if wordlist[0:2] == ['i','am']: print "Please tell me why you are " +\ stringify(mapped_wordlist[2:]) + '.' return

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 12 Implementation Issues in the Shrink Input of raw strings and conversion to word lists. the_input = raw_input('TYPE HERE:>> ') if match('bye',the_input): print 'Goodbye!' return wordlist = split(' ',remove_punctuation(the_input))

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 13 Implementation Issues in the Shrink (continued) Use of regular expressions. from re import * # regular expression module. punctuation_pattern = compile(r"\,|\.|\?|\!|\;|\:") def remove_punctuation(text): 'Returns a string without any punctuation.' return sub(punctuation_pattern,'', text)

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 14 Implementation Issues in the Shrink (continued) Pronoun and verb case transformation. CASE_MAP = {'i':'you', 'I':'you', 'me':'you','you':'me', 'my':'your', 'your':'my', 'yours':'mine', 'mine':'yours', 'am':'are'} def you_me(w): 'Changes a word from 1st to 2nd person or vice-versa.' try: result = CASE_MAP[w] except KeyError: result = w return result def you_me_map(wordlist): 'Applies YOU-ME to a whole sentence or phrase.' return map(you_me, wordlist)

CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 15 Implementation Issues in the Shrink (continued) Output formatting (with functional programming) def stringify(list): '''Create a string from the list, but with spaces between words.''' if len(list) == 0: return "" if len(list) == 1: return list[0] # If more than 1 element, # put spaces between adjacent pairs: return list[0] + reduce(lambda y,z: y+z, map(lambda x: ' ' + x, list[1:]))