CSE 415 -- (c) S. Tanimoto, 2008 Production Systems 1 Production Systems Many AI programs are “data driven.” The program examines the data, and then it.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Boost Spirit V2 A cookbook style guide to parsing and output generation in C++ Joel de Guzman Hartmut Kaiser
CSE (c) S. Tanimoto, 2007 Production Sys. & Pattern Matching 1 CSE 415 Production Systems Many AI programs are “data driven.” The program examines.
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.
Chapter 2 Writing Simple Programs
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.
RESEARCH REPORT PREPARATION AND PRESENTATION. 2 RESEARCH REPORT A research report is: – a written document or oral presentation based on a written document.
Lesson 7: Improving the User Interface
A Plan That Builds an Essay
Making an Outline A Plan That Builds a Strong Report Report
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.
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.
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
JavaScript: The First Parts Part Three Douglas Crockford Yahoo! Inc.
Roman Numeral Multiplication Quiz
Medical Math Health Occupations Education Mrs. Rose.
Reference & Research Writing 103 Uniformed Writing for Trinity Theological Seminary of South Florida T. Carter C.Ed Ph D.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
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
¸üµÖŸÖ ×¿ÖÖÖ ÃÖÓãÖÖ,ÃÖÖ ŸÖÖ¸üÖ ú´ÖÔ¾Ö߸ü ×¾ÖªÖ¯ÖϲÖÖê× ¬Ö­Öß, ´Ö¬µÖ ×¾Ö³Ö֐Ö, ÃÖÖŸÖÖ¸üÖ ¿ÖÖ»ÖêµÖ †³µÖÖÃ֍Îú´ÖÖ­ÖãÃÖÖ¸ ÃÖÓãÖêŸÖᯙ ÃÖê¾ÖúÖÓ­Öß ŸÖµÖÖ¸ü.
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.
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.
Roman Numerals Students will convert Arabic numerals to Roman numerals and vice versa Students will write numbers using the Roman numeral system.
Chapter 2 Writing Simple Programs
Maths in Year 3 at St Anselm’s.
Introduction to Computing Science and Programming I
Revised based on textbook author’s notes.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
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
Parents Guide to Calculation
27 Amendments XV (15) rights not to be denied because of race XVI (16)
Flow diagrams (i) (ii) (iii) x – Example
Introduction to Python
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, 2008 Production Systems 1 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, 2008 Production Systems 2 Production System Architecture

CSE (c) S. Tanimoto, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 9 Joseph Weizenbaum Was born in Berlin in As a professor of AI at the Massachusetts Institute of Technology, he developed an influential program called ELIZA in the 1960s. J. Weizenbaum in 2005 – from Wikipedia It used pattern matching to detect simple rhetorical patterns and gave clever responses with essentially no understanding of the text.

CSE (c) S. Tanimoto, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 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, 2008 Production Systems 14 Implementation Issues in the Shrink (continued) Python hash tables (“dictionaries”) >>> he_she = {'he':'she', 'his':'her', 'him':'her'} >>> sentence = ['Take', 'him', 'away'] >>> new_sentence = sentence[:] >>> new_sentence[1] = he_she[sentence[1]] >>> print new_sentence ['Take', 'her', 'away']

CSE (c) S. Tanimoto, 2008 Production Systems 15 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, 2008 Production Systems 16 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:]))