some thoughts to consider 2 aside from what ai is or isn’t, it is possible to build competent...

15
Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability for automated reasoning using that knowledge. An intelligent piece of software is one that surprises its designers occasionally. Once AI techniques have been incorporated into standard software practice, they are no longer considered part of AI. There are several interesting polarities (continua?) present in AI culture. Consider the following: Weak AI ----------------------------------- Strong AI Neat ----------------------------------- Scruffy Symbolic ----------------------------------- Emergent Web Svc ----------------------------------- Sem Web How do you react to: Eliza Ramona Alice

Upload: hollie-glenn

Post on 27-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Some Thoughts to Consider 2

• Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability for automated reasoning using that knowledge.

• An intelligent piece of software is one that surprises its designers occasionally.

• Once AI techniques have been incorporated into standard software practice, they are no longer considered part of AI.

• There are several interesting polarities (continua?) present in AI culture. Consider the following:

Weak AI ----------------------------------- Strong AI

Neat ----------------------------------- Scruffy

Symbolic ----------------------------------- Emergent

Web Svc ----------------------------------- Sem Web

• How do you react to:• Eliza

• Ramona

• Alice

Page 2: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Four Approaches to AI

• Acting Humanly• The Turing Test Approach

• Emulating what humans do

• Thinking Humanly• The Cognitive Modeling Approach

• Cognitive Science

• Thinking Rationally• The “Laws of Thought” Approach

• Represent everything in terms of logic

• Acting Rationally• The Rational Agent Approach

• Agents are designed software and hardware artifacts that ‘do the right thing’

The textbook concentrates on the fourth approach: the general principles of rational agents and the components for constructing them.

Page 3: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Skills Required for an Agent to Pass the Turing Test

• Natural Language Processing

• Knowledge Representation

• Automated Reasoning

• Machine Learning

And for the ‘Total Turing Test’:

• Computer Vision

• Robotics

These areas of endeavor cover most of AI tradition and practice for the past 50 years.

Page 4: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

A Practical Inferencing Excursion

• It is important to start engaging with examples that illustrate AI concepts. This provides context for the textbook learning.

• To this end, consider a simple knowledge system (agent) that recommends how to get to the theater on time.

• Consider several variations on how to represent the knowledge and how to reason to the advice:

• Hardcoded programming language

• Decision tables

• Rule based inferencing

• Backward chaining

• Forward chaining

• Reasoning over semantic network representation

• Logic and resolution theorem proving

Page 5: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Modus Ponens

• If A is known to be true,

• And if a rule states: If A, then B,

• It is valid to conclude that B is true.

• When B is known to be false,

• And if a rule states: If A, then B,

• It is valid to conclude that A is false.

Modus Tollens

Most expert systems use Modus Ponens.

Page 6: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Rules for Getting to the Theater on Time

1. If Distance > 5 miles then Means is drive

2. If Distance > 1 mile and Time < 15 minutes then Means is drive

3. If Distance > 1 mile and Time > 15 minutes then Means is walk

4. If Means is drive and Location is downtown then Action is take a cab

5. If Means is drive and Location is not downtown then Action is drive your car

6. If Means is walk and Weather is bad then Action is take a coat and walk

7. If Means is walk and Weather is good then Action is walk

Page 7: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Getting to the Theater on Time in Code

/** * TheaterDecision - a class to provide decision support * for getting to the theater on time. */public class TheaterDecision {

static int distance; static int time; static String location; static String means; static String weather; static String action;

/** * Four arguments are anticipated: * args[0] distance in miles to theater * args[1] time in minutes before performance * args[2] location of theater (downtown or notdowntown) * args[3] weather conditions (bad or good) */ public static void main (String[] args) { distance = Integer.parseInt(args[0]); time = Integer.parseInt(args[1]); location = args[2]; weather = args[3];

if (distance > 5) means = "drive"; else if (distance > 1) { if (time < 15) means = "drive"; else means = "walk"; } if ("drive".equals(means)) { if ("downtown".equals(location)) action = "Take cab."; else action = "Drive."; } else if ("walk".equals(means)) { if ("bad".equals(weather)) action = "Take coat and walk."; else if ("good".equals(weather)) action = "Walk."; } if (action == null) action = "No decision available."; System.out.println("Decision: " + action); }

} // End of TheaterDecision class

Page 8: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT via Decision Tables

Distance Time Means Location Weather Action

Table to conclude meansgt 5 miles drivegt 1 mile lt 15 drivegt 1 mile gt 15 walk

Table to conclude actiondrive downtown take cabdrive not downtown drive carwalk bad walk with coatwalk good walk

Composite table with 'don't care' conditionsgt 1 mile lt 15 drive downtown take cabgt 1 mile lt 15 drive not downtown drive cargt 1 mile gt 15 walk bad walk with coatgt 1 mile gt 15 walk good walkgt 5 miles drive downtown take cabgt 5 miles drive not downtown drive car

Table of all possibilitiesgt 1 mile lt 15 drive downtown bad take cabgt 1 mile lt 15 drive downtown good take cabgt 1 mile lt 15 drive not downtown bad drive cargt 1 mile lt 15 drive not downtown good drive cargt 1 mile gt 15 walk downtown bad walk with coatgt 1 mile gt 15 walk downtown good walkgt 1 mile gt 15 walk not downtown bad walk with coatgt 1 mile gt 15 walk not downtown good walkgt 5 miles lt 15 drive downtown bad take cabgt 5 miles lt 15 drive downtown good take cabgt 5 miles lt 15 drive not downtown bad drive cargt 5 miles lt 15 drive not downtown good drive cargt 5 miles gt 15 drive downtown bad take cabgt 5 miles gt 15 drive downtown good take cabgt 5 miles gt 15 drive not downtown bad drive cargt 5 miles gt 15 drive not downtown good drive car

Page 9: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT Using a Semantic Network

import java.util.Vector;import org.narl.*;

/** * TheaterDecision2 - a class to provide decision support * for getting to the theater on time. */public class TheaterDecision2 {

static NodeTag[] paramNames = {NodeTag.intern("distance"), NodeTag.intern("time"), NodeTag.intern("location"), NodeTag.intern("weather")};

/** * Four arguments are anticipated: * args[0] distance in miles to theater * args[1] time in minutes before performance * args[2] location of theater (downtown or notdowntown) * args[3] weather conditions (bad or good) */ public static void main (String[] args) throws Exception { if (!Narl.isPresent()) Narl.newEnv(); Narl.nread("TheaterOnTime.narl");

Vector predList = new Vector(); Vector pred;

for (int i = 0; i < paramNames.length; i++) { if (i < 2) pred = NarlC.makeVector3(paramNames[i], NarlC.VALUE, new Integer(args[i])); else pred = NarlC.makeVector3(paramNames[i], NarlC.VALUE, args[i]); predList.addElement(pred); }

NodeTag[] contexts = Node.ngetIntersectNode(predList); if (contexts == null) System.out.println("No decision."); else for (int j = 0; j < contexts.length; j++) System.out.println("Action: " + Node.ngetName(contexts[j])); }

} // End of TheaterDecision2 class

Page 10: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT Rules in Nodes

;=========================================================

; Model to handle rules for Getting to the Theater on Time

;---------------------------------------------------------

; Rules in English:

; 1. If Distance > 5 miles

; then Means is drive

; 2. If Distance > 1 mile and Time < 15 minutes

; then Means is drive

; 3. If Distance > 1 mile and Time > 15 minutes

; then Means is walk

; 4. If Means is drive and Location is downtown

; then Action is take a cab

; 5. If Means is drive and Location is not downtown

; then Action is drive your car

; 6. If Means is walk and Weather is bad

; then Action is take a coat and walk

; 7. If Means is walk and Weather is good

; then Action is walk

;============================================

(rule-model-root

(a-kind-of (value model-root))

)

;--------------------------------------------

(rule-node

(a-kind-of (value rule-model-root))

)

(theater-rule

(instance-of (value rule-node))

(goal (value action))

(multivalued (value action))

(parameter (distance 3)

(time 20)

(location "downtown")

(weather "good"))

)

Page 11: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT Rules in Nodes (cont.)

(rule_1

(instance-of (value theater-rule))

(rule (value

{if {distance > 5}

{then {set {theater-rule parameter means} "drive"}}}))

)

(rule_2

(instance-of (value theater-rule))

(rule (value

{if {distance > 1} {time < 15}

{then {set {theater-rule parameter means} "drive"}}}))

)

(rule_3

(instance-of (value theater-rule))

(rule (value

{if {distance > 1} {time > 15}

{then {set {theater-rule parameter means} "walk"}}}))

)

(rule_4

(instance-of (value theater-rule))

(rule (value

{if {means = "drive"} {location = "downtown"}

{then {set {theater-rule parameter action} "Take a cab"}}}))

)

(rule_5

(instance-of (value theater-rule))

(rule (value

{if {means = "drive"} {location != "downtown"}

{then {set {theater-rule parameter action} "Drive car"}}}))

)

(rule_6

(instance-of (value theater-rule))

(rule (value

{if {means = "walk"} {weather = "bad"}

{then {set {theater-rule parameter action} "Walk with coat"}}}))

)

(rule_7

(instance-of (value theater-rule))

(rule (value

{if {means = "walk"} {weather = "good"}

{then {set {theater-rule parameter action} "Walk"}}}))

)

Page 12: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT Code to Utilize Rule Engine

import java.util.Enumeration;import com.mckesson.narl.*;

/** * TheaterDecision3 - a class to provide decision support * for getting to the theater on time using rules compatible * with NarlRuleMgr. */public class TheaterDecision3 {

static NodeTag RULEROOT = NodeTag.intern("rule-node"); static NodeTag TSTATE = NodeTag.intern("theater-rule"); static NodeTag PARAM = NodeTag.intern("parameter"); static NodeTag ACTION = NodeTag.intern("action");

/** * Four arguments are anticipated: * args[0] distance in miles to theater * args[1] time in minutes before performance * args[2] location of theater (downtown or notdowntown) * args[3] weather conditions (bad or good) */ public static void main (String[] args) throws Exception { if (!Narl.isPresent()) Narl.newEnv(); Narl.nread("TheaterRules.narl");

if (args.length > 0) { Node.nrplAll(TSTATE, PARAM, NodeTag.intern("distance"), new Integer(args[0])); Node.nrplAll(TSTATE, PARAM, NodeTag.intern("time"), new Integer(args[1])); Node.nrplAll(TSTATE, PARAM, NodeTag.intern("location"), args[2]); Node.nrplAll(TSTATE, PARAM, NodeTag.intern("weather"), args[3]); }

NarlRuleMgr rm = new NarlRuleMgr(); NarlQueue2 actions = new NarlQueue2();

while (true) { System.out.println(Narl.ngetNode(TSTATE).toStringPp()); boolean moreToDo = false; Enumeration rules = Node.ngetAllInstances(RULEROOT);

while (rules != null && rules.hasMoreElements()) { NodeTag rule = (NodeTag) rules.nextElement(); rm.doRules(rule);

Enumeration acts = Node.ngetSomeIEnum(RULEROOT, PARAM, ACTION, NarlC.kindInvArcs);

while (acts != null && acts.hasMoreElements()) { String act = (String) acts.nextElement(); if (!actions.contains(act)) { actions.addRearMaybe(act); moreToDo = true; } } } if (!moreToDo) break; } System.out.println(actions); }

} // End of TheaterDecision3 class

Page 13: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

Resolution Theorem Proving

• A way to discover whether a new fact is valid, given a set of logical statements.

• Based on the fact that the following two statements are logically equivalent:

• If A, Then B.

• Not (A) or B.

• One can show this by a truth table:

A B Not (A) If A then B Not (A) or B

T T F T T

T F F F F

F T T T T

F F T T T

Page 14: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT By Logical Inference (Resolution)

• Given:• If distance > 5 miles, Then means = drive.

• If means = drive, Then action = take a cab.

• Fact: distance > 5 miles.

• Step 1: Rewrite the IF-THEN statements as OR statements:• Not (distance > 5 miles) or means = drive.

• Not (means = drive) or action = take a cab.

• Distance > 5 miles

• Step 2: Assert the negation of the thesis in question and add it to the list:• Not (action = take a cab).

• Step 3: Resolve pairs of facts with the following rule:Not (X) or Y

Not (Y) or Z

Not (X) or Z

• Using the example, inference 1:

Not (distance > 5) or means = drive

Not (means = drive) or action = take a cab

Not (distance > 5) or action = take a cab

• Inference 2:

Not (distance > 5) or action = take a cab

Distance > 5

Action = take a cab

• Inference 3:

action = take a cab

Not (action = take a cab)

Contradiction!

• Step 4: Accept that the thesis is true if a contradiction is encountered. This means that we should believe that ‘action = take a cab’ is correct.

Page 15: Some Thoughts to Consider 2 Aside from what AI is or isn’t, it is possible to build competent software by accurate knowledge representation and the capability

GTTTOT in First Order Logic (Prolog)

case(8, 8, downtown, good).

distance(D) :- case(D, _, _, _).

time(T) :- case(_, T, _, _).

location(L) :- case(_, _, L, _).

weather(W) :- case(_, _, _, W).

means(X) :- distance(D), D > 5, X = drive.

means(X) :- distance(D), D > 1, time(T), T < 15, X = drive.

means(X) :- distance(D), D > 1, time(T), T > 15, X = walk.

action(X) :- means(drive), location(downtown), X = takecab.

action(X) :- means(drive), not location(downtown), X = drivecar.

action(X) :- means(walk), weather(good), X = walk.

action(X) :- means(walk), weather(bad), X = walkwithcoat.