人工智能原理人工智能原理 (41).pdf
Artificial IntelligenceRepresentation Using LogicArtificial Intelligence2 7.3.1 Procedural vs.Declarative Approaches 7.3.2 Five Different Logics 7.3.3 Logical Symbols 7.3.4 Propositional Logic vs.First-order Logic 7.3.5 Formation Rules in First Order Logic 7.3.6 Prolog LanguageContentsArtificial Intelligence:Reasoning:Reasoning by Knowledge3 Procedural approaches过程性方法 use procedural languages,such as 采用过程性语言,例如 C/C+/C#/Java,Lisp,Python.Declarative approaches陈述性方法 use declarative languages,such as 采用陈述性语言,例如 Propositional logic,命题逻辑,First-order logic,一阶逻辑,Temporal logic.时序逻辑。Procedural vs.Declarative Approaches 过程性与陈述性方法7.3.Representation Using LogicArtificial Intelligence:Reasoning:Reasoning by Knowledge4Five Different Logics 五种不同的逻辑7.3.Representation Using LogicFormal Language形式语言Ontological Commitment本体论约定Epistemological Commitment认识论约定Propositional logic命题逻辑facts事实true/false/unknown真/假/未知First-order logic一阶逻辑facts,objects,relations事实、对象、关系true/false/unknown真/假/未知Temporal logic时序逻辑facts,objects,relations,times事实、对象、关系、时间true/false/unknown真/假/未知Probability theory概率论Facts事实degree of belief 0,1可信度Fuzzy logic模糊逻辑facts with degree of truth 0,1事实具有真实度known interval value已知区间值Artificial Intelligence:Reasoning:Reasoning by Knowledge5Logical Symbols 逻辑符号7.3.Representation Using LogicCategory 类别Symbol 符号Mean 含义Connectives 连接词not非and与or或implies蕴含当且仅当entailment导出Quantifiers限量词for all所有there exist存在Equality 等量词equal等于Artificial Intelligence:Reasoning:Reasoning by Knowledge6 Propositional logic:命题逻辑:also known as propositional calculus,亦被称为命题演算 use of logical connectives,deal with simple declarative propositions(if they are true or false).使用逻辑连接词,用于处理简单的陈述性命题。First-order logic:一阶逻辑:also known as first-order predicate calculus,亦被称为一阶谓词演算,additionally,use quantifiers,equality,and use predicates(often associated with sets).此外,还使用限量词、等量词、以及谓词(通常与集合相关联)。Propositional Logic vs.First-order Logic 命题逻辑与一阶逻辑7.3.Representation Using LogicArtificial Intelligence:Reasoning:Reasoning by Knowledge7Propositional Logic Syntax with BNF 用BNF表述的命题逻辑语法7.3.Representation Using LogicSentenceAtomicSentence|ComplexSentenceAtomicSentenceTrue|False|P|Q|R|ComplexSentence|Sentence|Sentence Sentence|Sentence Sentence|Sentence Sentence|Sentence SentenceOPERATOR PRECEDENCE:BNF:BackusNaur Form巴科斯-诺尔范式Artificial Intelligence:Reasoning:Reasoning by Knowledge8First-Order Logic Syntax with BNF 用BNF表述的一阶逻辑的语法7.3.Representation Using LogicSentenceAtomicSentence|ComplexSentenceAtomicSentenceComplexSentence|Sentence Sentence|Sentence Sentence|Sentence Sentence|Quantifier Variable,SentenceTermFunction(Term,)|Constant|VariableQuantifier|ConstantA|X1|John|Variablea|x|s|PredicateTrue|False|After|Loves|Raining|FunctionMother|LeftLeg|OPERATOR PRECEDENCE:Artificial Intelligence:Reasoning:Reasoning by Knowledge9 The formation rules define 该形式规则定义 terms,and 项,以及 formulas.公式 The formation rules can be used to write a formal grammar for terms and formulas.该形式规则可以用于书写项和公式的形式文法。Formation rules are generally context-free,i.e.,形式规则通常是上下文无关的,即 each production has a single symbol on the left side.每个产生式左侧有一个单一的符号。Formation Rules in First Order Logic 一阶逻辑的形式规则7.3.Representation Using LogicArtificial Intelligence:Reasoning:Reasoning by Knowledge10 Rule1:Variables 规则1:变量Any variable is a term.任何变量都是一个项。Rule2:Constants 规则2:常数Any constant is also a term.任何常数也都是一个项。Rule3:Functions 规则3:函数Any expression f(t1,.,tn)of n arguments is a term,where each argument tiis a term,and f is a function symbol of valence n.In particular,symbols denoting individual constants are 0-ary function symbols,and are thus terms.任何n个参数的表达式f(t1,.,tn)都是一个项,其中每个参数ti是一个项,并且f是一个价n的函数符号。尤其是,表示个体常量的符号是0元函数符号,因此也是一个项。Formation Rules of First Order Logic:Terms 一阶逻辑的形式规则:项7.3.Representation Using LogicArtificial Intelligence:Reasoning:Reasoning by Knowledge11Formation Rules of First Order Logic:Formulas 一阶逻辑的形式规则:公式7.3.Representation Using Logic Predicate symboles.If P is an n-ary predicate symbol and t1,.tnare terms,then P(t1,.tn)is a formula.谓词符号:若P是一个n元谓词符号并且t1,.tn是项,则 P(t1,.tn)是一个公式。Equality.If the equality symbol is considered part of logic,and t1and t2are terms,then t1=t2is a formula.等量:若等量符号被认为是逻辑的一部分,并且 t1和 t2是项,则 t1=t2 是一个公式。Negation.If is a formula,then is a formula.否定:若是一个公式,则是一个公式。Binary connectives.If and are formulas,then is a formula.Similar rules apply to other binary logical connectives.二元连接:若和是公式,则是一个公式。类似的规则可用于其他二元逻辑连接。Quantifiers.If is a formula and x is a variable,then and are formulas.限量:若是一个公式并且x是一个变量,则和是公式。Artificial Intelligence:Reasoning:Reasoning by Knowledge12 Performance measure:性能指标:+1000:gold,黄金-1000:death 死亡(enters a PIT or a wumpus),-1:per step,每一步-10:using the arrow.用箭 Actuators:执行器:Turn Left,Turn Right,Forward,向左、向右、前进Shoot:to fire an arrow,射击:发射一只箭Grab:to pick up gold,抓住:拾起黄金Climb:to climb out of cave.攀爬:攀越陷阱Example:Wumpus world 魔兽世界7.3.Representation Using Logic12344321 Environment:环境:Agent 智能体,Gold 黄金,Wumpus魔兽,Pit(probability 0.2)陷阱(概率0.2)Percept Stench,Breeze,Glitter,Bump,ScreamBreeze微风,Scream尖叫.Sensors:感受器:Stench臭气,Bump碰撞,Glitter闪光,Artificial Intelligence:Reasoning:Reasoning by Knowledge13Example:Wumpus world 魔兽世界7.3.Representation Using LogicThe first step taken by the agent.(a)Initial situation,after Percept None,None,None,None,None.(b)After one move,with Percept None,Breeze,None,None,None.智能体所采取的第一步。(a)初始状态,在Percept None,None,None,None,None之后。(b)移动一步后,具有Percept None,Breeze,None,None,None。(a)12344321(b)12344321Artificial Intelligence:Reasoning:Reasoning by Knowledge14Example:Wumpus world 魔兽世界7.3.Representation Using Logic(c)12344321(d)12344321Two later stages in the progress of the agent.(c)After third move,with Percept Stench,None,None,None,None.(d)After fifth move,with Percept Stench,Breeze,Glitter,None,None.智能体进展的两个后期阶段。(c)移动第三步后,具有Percept Stench,None,None,None,None。(d)移动第四步后,具有Percept Stench,Breeze,Glitter,None,None。Artificial Intelligence:Reasoning:Reasoning by Knowledge15 Percept sentence 感知语句Using First-Order Logic for Wumpus World 用一阶逻辑描述魔兽世界7.3.Representation Using LogicPercept(Stench,Breeze,Glitter,None,None,5)t,s,g,m,c Percept(s,Breeze,g,m,c,t)Breeze(t)t,s,b,m,c Percept(s,b,Glitter,m,c,t)Glitter(t)Turn(Right),Turn(Left),Forward,Shoot,Grab,Climb.ASKVARS(a,BestAction(a,5)Action sentence 动作语句 Query sentence 查询语句(To determine which is best,确定那个是最好的)Artificial Intelligence:Reasoning:Reasoning by Knowledge16 Prolog language has its roots in first-order logic.Prolog语言起源于一阶逻辑。Prolog is a general purpose logic programming language,has been used for theorem proving,expert systems,natural language processing,and so on.Prolog是一种通用的逻辑编程语言,已经被用于定理证明、专家系统、自然语言处理,等等。Unlike other programming languages,Prolog is declarative:the program logic is expressed in terms of relations,represented as facts and rules.不同于其它编程语言,Prolog是陈述性的:程序逻辑由关系来表达,表示为事实与规则。Prolog LanguageProlog语言7.3.Representation Using Logiclikes(bill,car).animal(X):-cat(X).bird(X):-animal(X),has(X,feather).