DOC PREVIEW
USC CSCI 561 - session24-25

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 561, Session 251Introduction to CLIPS• Overview of CLIPS•Facts•Rules• Rule firing• Control techniques•ExampleCS 561, Session 252CLIPS basic elements• Fact-list: global memory of data• Knowledge-base: contain all the rules• Inference engine: controls overall execution using forward chaining• http://www.ghg.net/clips/CLIPS.htmlCS 561, Session 253Inference cycleWorking Memory(Facts)Knowledge-Base(Rules)Pattern MatchingConflict Resolution(select rule)Fire ruleUser’s program1.2.3.assert/retract/modifyfactschangerulesAgendaCS 561, Session 254Antecedent Matching1. matches facts in working memory against antecedents of rules2. each combination of facts that satisfies a rule is called an instantiation 3. each matching rule is added to the agendaCS 561, Session 255Selection of a rule from the AgendaSome selection strategies:• Recency (most recent first)triggered by the most recent facts • Specificity (most specific first)rules prioritized by the number of condition elements •Randomchoose a rule at random from the agendaCS 561, Session 256Execution of the rule• Can modify working memory • add facts • remove facts • alter existing facts • Alter rules • Perform an external task (read sensors, control actuator)CS 561, Session 257Control mechanism• Consider the following rule-base:(1) Car won’t start à check battery(2) Car won’t start à check gas(3) Check battery AND battery bad à replace battery• If the fact “car won’t start” is asserted, then which of the rules (1) and (2) should be placed on the agenda? (1), (2), or both?• We need a mechanism to place instantiations of rules on the agenda.CS 561, Session 258Control mechanisms• Markov algorithms:Approach: Apply rule with highest priority, if not applicable then take the next one etc.Problem: inefficient for systems with many (1000s of) rules.Has to do pattern matching on every rule in each cycle.• Rete algorithm:Fast pattern matching that obtains speed by storing information about all rules in a network. Only looks for changes in patternmatches in every cycle.CS 561, Session 259Install and run• Access to CLIPS:• On aludra: at ~csci561a/clips• In Windows: install http://www.ghgcorp.com/clips/download/executables/pc• Running Clips• On aludra: > clips• In Windows: run clips.exeCS 561, Session 2510Overviewshellagenda focusfactsinstancesglobalsCS 561, Session 2511Getting started• Shell commands: (<command>)•(help)•(reset) à places (initial-fact) on factlist• (run) à runs till completion of program• (run 1) à runs 1 step•(facts) à shows the factlist• (assert (fact)) à puts (fact) on factlist• (retract 0) à removes fact with ID 0 from factlist•(defrule myrule …)à defines a rule named myrule•(clear) à removes all facts from factlistCS 561, Session 2512Facts• (field1 field2 … fieldN) an ordered, flat list• E.g.,(Hans 561a) is not equal to (561a Hans)• (Hans (561a 561b)) is illegal• Common to start with the relation that fact describese.g.,(class Hans 561b)• Keyword nil: used to indicate that a field has no value• deftemplates to have names for each fieldCS 561, Session 2513Field types• Types:•Float: 1.34• Integer: 1, 2, 10, 20• Symbol: alkflksjfd• String: "duck/soup"• external-address:• fact-address:• instance-name: • instance-address:• The type of each field is determined by the type of value stored in the field.•Indeftemplates, you can explicitly declare the type of value that a field can contain.CS 561, Session 2514Deffacts• (deffacts <deffacts name> [<optional comment>]<<facts>> )used to automatically assert a set of facts• (deffacts status “some facts about emergency”(emergency fire)(fire-class A) )• Are asserted after a (reset) commandCS 561, Session 2515Adding and removing facts• (assert <<<fact>>>) used to assert multiple facts• (retract <<<fact-index>>>) removes a number of factse.g., (assert (fact1)(fact2) )(retract 1)• Is assigned a unique fact identifier: (e.g., f-1) starts with ‘f’ and followed by an integer called the fact-index• Fact-index: can be used to refer to that fact (e.g., retract it)• Fact-list: can be viewed in the fact-list window or using the (facts) command.(facts [<start> [<end> [<maximum]]])CS 561, Session 2516Components of a rule• (defrule <rule name> [<optional comment>]<<<patterns>>>=><<<actions>>>)• (defrule fire-emergency “An example rule”(emergency fire)=>(assert (action activate-sprinkler-system)))• Rules can be inserted into the shell or loaded from a file using the (load) commandCS 561, Session 2517The agenda and activation• (run [<limit>])runs a CLIPS program,<limit> is the number of rules to fire• Activating a rule: requires that all its patterns on LHS (Left-Hand-Side) are matched. Asserting an existing fact has no effect. • List of activated rules: can be seen in the agenda window or listed using (agenda)0 fire-emergency f-2saliencerule namematching factsCS 561, Session 2518Rule firing and refraction• (run) will cause the most salient rule on the agenda to fire• What if the run command is issued again?CS 561, Session 2519Rule firing and refraction• (run) will cause the most salient rule on the agenda to fire• What if the run command is issued again?There are no rules on the agenda so nothing will happen.• Refraction: CLIPS rule firing models the refraction effect of a neuron to avoid endless loopsCS 561, Session 2520Commands used with rules• (rules) displays the rules in the knowledge-base• (pprule <rule-name>) displays a rule• (load <file-name>) loads rules described in a file• (save <file-name>) saves the stored rules into a file• Comments: start with the character “;”CS 561, Session 2521Multiple rules• (defrule fire-emergency (emergency fire)=>(assert (action activate-sprinkler-system)))• (defrule flood-emergency (emergency flood)=>(assert (action shut-down-electrical-equipment)))• Asserting (emergency fire) will fire rule 1asserting (emergency flood) will activate rule 2CS 561, Session 2522Rules with multiple patterns• (defrule class-A-fire-emergency (emergency fire)(fire-class A)=>(assert (action activate-sprinkler-system)))• (defrule class-B-fire-emergency (emergency fire)(fire-class B)=>(assert (action activate-carbon-dioxide-extinguisher)))• All patterns must be matched for the rule to fireCS 561, Session 2523Removing rules• (clear) removes


View Full Document

USC CSCI 561 - session24-25

Download session24-25
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view session24-25 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view session24-25 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?