28
Artificial Intelligence and Lisp Lecture 2 LiU Course TDDC65 Autumn Semester, 2010 http://www.ida.liu.se/ext/TDDC65/

Artificial Intelligence and Lisp Lecture 2 LiU Course TDDC65 Autumn Semester, 2010

  • View
    224

  • Download
    3

Embed Size (px)

Citation preview

Artificial Intelligence and LispLecture 2

LiU Course TDDC65Autumn Semester, 2010

http://www.ida.liu.se/ext/TDDC65/

List Processing - Recursive Functions

(length .s) ==

(if [equal .s <>] 0 (+ 1 (length (t1 .s))))

(replace .a .b .s) ==

(if [equal .s .a] .b

(if [atom .s] s

(cons (replace .a .b (e1 .s))

(replace .a .b (t1 .s)) )))

The Autonomous Intelligent Agent

Much of the software technology for A.I. systems centers around the concept of an autonomous intelligent agent. This is a software platform with good capabilities for the following:

Representing a world model based on 'entities' and their relationships

Representing the components of e.g. the BDI model or the HTN model as data so that they can be modified dynamically

Contain the various algorithms etc that are need for aspects of the behavior

Persist over time, e.g. so that learned behavior can be kept Communicate with other agents Interface to specialized software, e.g. sensors and actuators

Example Hierachical Task Network

Goto Trainstation

Go from Sth Cto Globen

Take train toStockholm

Walkto Busstop

Take bus toLinköping C

Wait for bus toLinköping C

Go to Globen

Preconditions: Bus stop close enough, agent is able to walk, ...

Preconditions: There is such abusline, bus actually arrives...

Formulas and Languages

Language requirements for agent platform software: Support for expressing and using formulas in logic, for

example for preconditions of actions Support for implementing a variety of specialized

languages, for example for representing particular kinds of environment models, or for use in agent-to-agent communication, or for representing scripts for sequences of actions

The language requirement is often met by identifying a common syntactic style that can be used by a set of related languages. The Lisp language is related to the syntactic style of S-expressions.

Implementation of Languages in a Style

Implement a parser that converts expressions in that style to an internal representation as a datastructure

For each of the participating languages, implement an interpreter or a compiler that operates on the datastructure

Advantages: Less implementation work Enables library of programs that operate on internal

representation and that can be used for several languages Greater uniformity of languages makes them easier to learn Facilitates embedding embedding one language in another,

and cross-language invocation

S-expression Style

Examples:

color.red "Yes or no: " 421

(walkto busstop-4) (walk :from home :to busstop-4)

(seq (walkto busstop-4)(takebus Lkp-C))

(set busstop-4 busstop-7 busstop-12)

(+ (timefor (walkto busstop-d)) (timefor (waitfor (some (and bus (going-to Lkp-C)) ))) (timefor (go bus busstop-4 Lkp-C)) )

S-expression Style

1. Nested parenthesized expressions (lists) 2. Convention: operator as first element in list 3. Convention: use of tags e.g. :from, :to 4. Convention, sometimes: variables as ?vbl Can be used for programming language, but also for plain

data, for logic, and for alternative languages S-expression-based programming languages: Lisp,

Scheme

S-expression Style

Can be used for programming language, but also for plain data, for logic, and for alternative languages

S-expression-based programming languages: Lisp, Scheme

Some other S-expression-based languages: KIF, Knowledge Interchange Format FIPA-ACL, Agent Communication Language PDDL, Planning Domain Definition Language

XML Style

Example (from Web Ontology Language, OWL):

<Region rdf:ID="SantaCruzMountainsRegion"> <locatedIn rdf:resource="#CaliforniaRegion" /></Region>

<Winery rdf:ID="SantaCruzMountainVineyard" />

<CabernetSauvignon rdf:ID="SantaCruzMountainVineyardCabernetSauvignon" > <locatedIn rdf:resource="#SantaCruzMountainsRegion"/> <hasMaker rdf:resource="#SantaCruzMountainVineyard" /> </CabernetSauvignon>

XML Style

Originates from SGML which was intended for markup of text, via HTML for markup of web pages

XML wanted to have the same notation for markup of text and for structured data

Use for programs and other formula languages was not considered initially but has been brought up more recently

Strong emphasis on standardization and on use in very large systems

Difficult to read for the human eye

KR Expressions

Similar to S-expressions but easier to read Closer to the notation for logic formulas Contains some higher-level constructs that are found

in some S-expression-based languages, but which are generally useful

Used both in lecture notes/compendiums and in the software system being used (Leonardo)

KR Expressions

Examples of use:

color.red "Answer yes or no: "

{busstop-4 busstop-7 busstop-12}

(union {a b}{a c d})

[subset {a b} {c a d b g}]

[knows-what peter (phone-number-of: lars)]

[walk peter :from (home-of peter) :to Lkp-C]

KR Expressions

Constructs:

Entity color.redString "Answer yes or no: "Number 421

Composite entity (phone-number-of: lars)

Set {busstop-4 busstop-7 busstop-12}Sequence <red green blue>Mapping {[: rose red][: waterlily white]}

Form (union {a b}{a c d}) (+ 14 .offset) use of variableRecord [subset {a b} {c a d b g}] [walk peter :from (home-of peter) :to Lkp-C]

KR Expressions, extensions

Constructs:

Entity color.redString "Answer yes or no: "Number 421

Composite entity (phone-number-of: lars)

Set {busstop-4 busstop-7 busstop-12}Sequence <red green blue>Mapping {[: rose red][: waterlily white]}

Form ({a b} union {a c d}) (14 + .offset) use of variableRecord [{a b} subset {c a d b g}] [peter walk :from (home-of peter) :to Lkp-C]

Common Expression Language (CEL)

CEL is one of the languages using KRE style. It can be used in command-line dialog with a system, and in files in a knowledgebase

Each construct in CEL is written using one of the constructs in KRE

Literals (atomic propositions) as records [...] Actions as records [...] Composite propositions (using and, or, etc) as forms (...) Terms, i.e. arguments for actions and atomic propositions,

are written as forms (...) The operator in an action record is called a verb The operator in a literal record is called a predicate

Common Expression Language (CEL)

Literal [subset {b} {a b c}] [-subset {d} {a b c}]

Proposition (or [equal a b][equal a c]) (not [equal a b]) Literals are also propositions

Action [peter walk :from (home-of peter) :to Lkp-C]

Term (home-of peter) (union {a b}{b c}]

Simple Session Example 1

The Autonomous Intelligent Agent

Much of the software technology for A.I. systems centers around the concept of an autonomous intelligent agent. This is a software platform with good capabilities for the following:

Representing a world model based on 'entities' and their relationships

Representing the components of e.g. the BDI model or the HTN model as data so that they can be modified dynamically

Contain the various algorithms etc that are need for aspects of the behavior

Persist over time, e.g. so that learned behavior can be kept Communicate with other agents Interface to specialized software, e.g. sensors and actuators

In this course: Leonardo Platform

AllegroCommonLisp

agent indivmap

individual

Session with the agentleohost

Otherindividual

andagent

Manifestations, etc

The individual has a persistent manifestation as a directory structure with files, and a dynamic manifestation as a run in a computer. These are kept consistent during the run.

The persistent manifestation is expected to be long-lived (months, years) and to accumulate information over time.

One indidivual can contain several agents. An individual (and an agent) can move between hosts. Agents can exchange messages. The indivmap structure

contains location and addressing information. The leohost structure contains information about the

current host, for use by visiting agents/individuals.

Structure of Leonardo system for this course

AllegroCommonLisp

remus

orange

lablib

indivmap

Leonardo Platform and Registrar

AllegroCommonLisp

remus

orange

lablib

indivmap

AllegroCommonLisp

remus

registrar

indivmap

Registration and Lab Routine The first time you use your agent it will prompt you for your

name, student id, some more.

Asap you should register your agent, i.e. give a command where it sends a registration message to the registrar. At this time your computer must be connected to the Internet.

Lab assignments are downloaded from registrar to your Leonardo agent, using a download command.

You do the work for the labs using your agent. The results of your work are put in a particular results file for each of the labs.

To report your work, you issue a command whereby your agent sends the results file to the registrar.

In some of the labs there is a command that you can use for checking your results file before sending it.

We check the results file manually and/or automatically and send back a confirmation message by email.

Structure of Leonardo system after registration

AllegroCommonLisp

remus

orange

lablib

indivmap

yourname

Simple Session Example 2

Leonardo platform in virtual host

AllegroCommonLisp

remus

orange

lablib

indivmap

ubuntu linux

Available Operational Modes Use Leonardo system in virtual host from VMware on your own

computer. Recommended if you have one, you are comfortable with it, and it is sufficiently powerful. Available for Windows and Linux systems (not Mac).

Use Leonardo system on IDA's student computer network. Recommended if you do not have a computer that you wish to use for this purpose.

Use Leonardo system on your own computer without virtual host. Avoids the overhead of the virtual host, but requires you to install Allegro yourself, and minor problems may arise. Available for Windows, Linux and Mac systems.

Note: You will be using an evaluation license for the Lisp system that expires on March 15, 2011.

Technical information will be given in the tutorial session on Thursday (tomorrow).