收藏 分销(赏)

人工智能-实验.doc

上传人:xrp****65 文档编号:7226554 上传时间:2024-12-28 格式:DOC 页数:18 大小:298KB
下载 相关 举报
人工智能-实验.doc_第1页
第1页 / 共18页
人工智能-实验.doc_第2页
第2页 / 共18页
点击查看更多>>
资源描述
华 中 科 技 大 学 《人工智能与模式识别》 实 验 报 告 院 系: 电子与信息工程系 班 级: 电信中英班1101 姓 名: 何宇坤 学 号: U201115729 指导老师: 刘澍 电 话: 13058153519 邮 箱: 826319028@ 日 期: 2015年1月17日 实验一 一、 实验内容 利用一阶谓词逻辑求解猴子摘香蕉问题:房内有一个猴子,一个箱子,天花板上挂了一串香蕉,其位置如图所示,猴子为了拿到香蕉,它必须把箱子搬到香蕉下面,然后再爬到箱子上。请定义必要的谓词,列出问题的初始化状态(即下图所示状态),目标状态(猴子拿到了香蕉,站在箱子上,箱子位于位置b)。(附加:从初始状态到目标状态的谓词演算过程。) 二、 实验平台 VC6.0 三、 实验分析 1. 定义描述环境状态的谓词。 AT(x,w):x在t处,个体域:xϵ{monkey},wϵ{a,b,c,box}; HOLD(x,t):x手中拿着t,个体域:tϵ{box,banana}; EMPTY(x):x手中是空的; ON(t,y):t在y处,个体域:yϵ{b,c,ceiling}; CLEAR(y):y上是空的; BOX(u):u是箱子,个体域:uϵ{box}; BANANA(v):v是香蕉,个体域:vϵ{banana}; 2. 使用谓词、连结词、量词来表示环境状态。 问题的初始状态可表示为: So:AT(monkey,a)˄EMPTY(monkey)˄ON(box,c)˄ON(banana,ceiling)˄CLEAR(b)˄BOX(box)˄ BANANA(banana) 要达到的目标状态为: Sg:AT(monkey,box)˄HOLD(monkey,banana)˄ON(box,b)˄CLEAR(ceiling)˄CLEAR(c)˄ BOX(box)˄BANANA(banana) 3. 从初始状态到目标状态的转化, 猴子需要完成一系列操作, 定义操作类谓词表示其动作。 WALK(m,n):猴子从m走到n处,个体域:m,nϵ{a,b,c}; CARRY(s,r):猴子在r处拿到s,个体域:rϵ{c,ceiling},sϵ{box,banana}; CLIMB(u,b):猴子在b处爬上u; 这3个操作也可分别用条件和动作来表示。条件直接用谓词公式表示,是为完成相应操作所必须具备的条件;当条件中的事实使其均为真时,则可激活操作规则,于是可执行该规则中的动作部分。动作通过前后状态的变化表示,即通过从动作前删除或增加谓词公式来描述动作后的状态。 WALK(m,n):猴子从m走到n处 条件:AT(monkey,m) 动作: CARRY(s,r):猴子在r处拿到s 条件:AT(monkey,r)˄EMPTY(monkey)˄ON(s,r)˄BOX(box)˄BANANA(banana) 动作: CLIMB(u,b):猴子在b处爬上u 条件:AT(monkey,b)˄HOLD(monkey,u)˄CLEAR(b)˄BOX(box)˄BANANA(banana) 动作: 4. 按照行动计划, 一步步进行状态替换, 直至目标状态。 AT(monkey,a)˄EMPTY(monkey)˄ON(box,c)˄ON(banana,ceiling)˄CLEAR(b)˄BOX(box)˄ BANANA(banana) AT(monkey,c)˄EMPTY(monkey)˄ON(box,c)˄ON(banana,ceiling)˄CLEAR(b)˄BOX(box)˄ BANANA(banana) AT(monkey,c)˄HOLD(monkey,box)˄ON(banana,ceiling)˄CLEAR(b)˄CLEAR(c)˄BOX(box)˄ BANANA(banana) AT(monkey,b)˄HOLD(monkey,box)˄ON(banana,ceiling)˄CLEAR(b)˄CLEAR(c)˄BOX(box)˄ BANANA(banana) AT(monkey,box)˄EMPTY(monkey)˄ON(box,b)˄ON(banana,ceiling)˄CLEAR(c)˄BOX(box)˄ BANANA(banana) AT(monkey,box)˄HOLD(monkey,banana)˄ON(box,b)˄CLEAR(ceiling)˄CLEAR(c)˄BOX(box)˄ BANANA(banana)(目标得解) 猴子行动的规则序列是:WALK(a,c)→CARRY(c,box)→WALK(c,b)→CLIMB(box,b)→ CARRY(banana,ceiling) 在上述过程中,我们应该注意,当猴子执行某一个操作之前,需要检查当前状态是否可使所要求的条件得到满足,即证明当前状态是否蕴涵操作所要求的状态的过程。在行动过程中, 检查条件的满足性后才进行变量的代换。代入新条件后的新状态如果是目标状态,则问题解决;否则看是否满足下面的操作,如果不满足或即使满足却又回到了原来的状态,那么代入无效。 四、 源代码 #include <stdio.h> struct State { int monkey; /*-1:Monkey at A;0: Monkey at B;1:Monkey at C;*/ int box; /*-1:box at A;0:box at B;1:box at C;*/ int banana; /*Banana at B,Banana=0*/ int monbox; /*-1: monkey on the box;1: monkey the box;*/ }; struct State States [150]; char* routesave[150]; /*function monkeygoto,it makes the monkey goto the other place*/ void monkeygoto(int b,int i) { int a; a=b; if (a==-1) { routesave[i]="Monkey go to A"; States[i+1]=States[i]; States[i+1].monkey=-1; } else if(a==0) { routesave[i]="Monkey go to B"; States[i+1]=States[i]; States[i+1].monkey=0; } else if(a==1) { routesave[i]="Monkey go to C"; States[i+1]=States[i]; States[i+1].monkey=1; } else { printf("parameter is wrong"); } } /*end function monkeyygoto*/ /*function movebox,the monkey move the box to the other place*/ void movebox(int a,int i) { int B; B=a; if(B==-1) { routesave[i]="monkey move box to A"; States[i+1]=States[i]; States[i+1].monkey=-1; States[i+1].box=-1; } else if(B==0) { routesave[i] = "monkey move box to B"; States[i+1]=States[i]; States[i+1].monkey=0; States[i+1].box=0; } else if(B==1) { routesave[i] = "monkey move box to C"; States[i+1]=States[i]; States[i+1].monkey=1; States[i+1].box=1; } else { printf("parameter is wrong"); } } /*end function movebox*/ /*function climbonto,the monkey climb onto the box*/ void climbonto(int i) { routesave[i]="Monkey climb onto the box"; States[i+1]=States[i]; States[i+1].monbox=1; } /*function climbdown,monkey climb down from the box*/ void climbdown(int i) { routesave[i]="Monkey climb down from the box"; States[i+1]=States[i]; States[i+1].monbox=-1; } /*function reach,if the monkey,box,and banana are at the same place,the monkey reach banana*/ void reach(int i) { routesave[i]="Monkey reach the banana"; } /*output the solution to the problem*/ void showSolution(int i) { int c; printf ("%s \n", "Result to problem:"); for(c=0; c<i+1; c++) { printf ("Step %d : %s \n",c+1,routesave[c]); } printf("\n"); } /*perform next step*/ void nextStep(int i) { int c; int j; if(i>=150) { printf("%s \n", "steplength reached 150,have problem "); return; } for (c=0; c<i; c++) /*if the current state is same to previous,retrospect*/ { if(States[c].monkey==States[i].monkey&&States[c].box==States[i].box&&States[c].banana==States[i].banana&&States[c].monbox==States[i].monbox) { return; } } if(States[i].monbox==1&&States[i].monkey==0&&States[i].banana==0&&States[i].box==0) { showSolution(i); printf("Press any key to continue \n"); getchar();/*to save screen for user,press any key to continue*/ return; } j=i+1; if(States[i].monkey==0) { if(States[i].box==0) { if(States[i].monbox==-1) { climbonto(i); reach(i+1); nextStep(j); /*monkeygoto(-1,i); nextStep(j); monkeygoto(0,i); nextStep(j); movebox(-1,i); nextStep(j); movebox(0,i); nextStep(j);*/ } else { reach(i+1); nextStep(j); /*climbdown(i); nextStep(j);*/ } } else if(States[i].box==1) { /*monkeygoto(-1,i); nextStep(j);*/ monkeygoto(1,i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } else /*box==-1*/ { monkeygoto(-1,i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } } /*end if*/ if(States[i].monkey==-1) { if(States[i].box==-1) { if(States[i].monbox==-1) { movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } else { climbdown(i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } } else if(States[i].box==0) { monkeygoto(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } else { monkeygoto(1,i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } } /*end if*/ if(States[i].monkey==1) { if (States[i].box==1) { if(States[i].monbox==-1) { movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } else { climbdown(i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } } else if(States[i].box==-1) { monkeygoto(-1,i); nextStep(j); movebox(0,i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } else { monkeygoto(0,i); nextStep(j); movebox(0,i); nextStep(j); climbonto(i); reach(i+1); nextStep(j); } } /*end if*/ }/*end nextStep*/ int main() { States[0].monkey=-1; States[0].box=1; States[0].banana=0; States[0].monbox=-1; nextStep(0); } 五、 实验截图 六、 实验感想 主要输算法的中心思想要搞明白,根据设计的流程图转换成程序,加上互联网资源丰富,得以顺利完成 实验二 求解函数逼近问题 一、 实验内容 有21组单输入矢量P和相对应的目标矢量T,试采用Matlab (7.0以上版本)设 计神经网络来实现这对数组的函数关系 P=-1:0.1:1 T=[-0.96 0.577 -0.0729 0.377 0.641 0.66 0.461 0.1336 -0.201 -0.434 -0.5 -0.393 -0.1647 0.0988 0.3072 0.396 0.3449 0.1816 -0.0312 -0.2183 -0.3201] 测试集 P2=-1:0.025:1 二、 实验解 看到期望输出的范围是,所以利用双极性Sigmoid函数作为转移函数。 程序如下: clear; clc; X=-1:0.1:1; D=[-0.9602 -0.5770 -0.0729 0.3771 0.6405 0.6600 0.4609... 0.1336 -0.2013 -0.4344 -0.5000 -0.3930 -0.1647 -.0988... 0.3072 0.3960 0.3449 0.1816 -0.312 -0.2189 -0.3201]; figure; plot(X,D,'*'); %绘制原始数据分布图(附录:1-1) net = newff([-1 1],[5 1],{'tansig','tansig'}); net.trainParam.epochs = 100; %训练的最大次数 net.trainParam.goal = 0.005; %全局最小误差 net = train(net,X,D); O = sim(net,X); figure; plot(X,D,'*',X,O); %绘制训练后得到的结果和误差曲线(附录:1-2、1-3) V = net.iw{1,1}%输入层到中间层权值 theta1 = net.b{1}%中间层各神经元阈值 W = net.lw{2,1}%中间层到输出层权值 theta2 = net.b{2}%输出层各神经元阈值 三、 实验结果 输入层到中间层的权值: 中间层各神经元的阈值: 中间层到输出层的权值: 输出层各神经元的阈值: 图一 原始数据分布图 图二 仿真结果
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服