实验一: 动物识别专家系统设计
- 格式:pdf
- 大小:261.26 KB
- 文档页数:8
华南农业大学信息学院动物识别专家系统一、实验内容按下列规则,写出一个分类专家系统:(1)有毛的动物是哺乳类;(2)有奶的动物是哺乳类;(3)有羽毛的动物是鸟类;(4)若动物会飞且会生蛋,则它是鸟类;(5)吃肉的哺乳类是肉食动物;(6)犬牙利爪,眼睛向前的是肉食动物;(7)反刍食物的哺乳类是有蹄类;(8)有蹄的哺乳类是有蹄类;(9)黄褐色有暗斑点的肉食类是金钱豹;(10)黄褐色有黑条纹的肉食类是老虎;(11)长腿长脖子有黄褐色暗斑的有蹄类是长颈鹿;(12)有黑白条纹的有蹄类是斑马;(13)不会飞长腿长脖的鸟是鸵鸟;(14)不会飞善游泳黑白色的鸟是企鹅;(15)善飞的鸟是信天翁。
二、实验目的1.加深对产生式表示法的认识;2.熟悉数据库的制作与使用。
3. 专家系统的学习与应用三、实验原理四、设计过程1.环境与配置windows系统,Delphi7.0(可视化程序设计)2结果如下3.主要源代码实现过程//unit2.dfmunit Unit1;interfaceusesWindows, Messages, SysUtils, V ariants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids, DBCtrls, StdCtrls, ExtCtrls,CheckLst;typeTForm1 = class(TForm)DataSource1: TDataSource;Query1: TQuery;DataSource2: TDataSource;Table1: TTable;GroupBox1: TGroupBox;Panel2: TPanel;Panel1: TPanel;Panel3: TPanel;Splitter1: TSplitter;Splitter2: TSplitter;ListBox1: TListBox;ListBox2: TListBox;Button1: TButton;Button3: TButton;Button5: TButton;Label1: TLabel;Label2: TLabel;Button2: TButton;procedure FormCreate(Sender: TObject);procedure Button1Click(Sender: TObject);procedure Button3Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button5Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementationuses Unit2;var sql,strWhere:String;{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);beginsql:='SELECT 结论FROM 推导';with table1 dobeginfirst;while not eof dobeginListBox1.Items.Add(fieldbyname('条件').asString);next;end;end;end;procedure TForm1.Button1Click(Sender: TObject);var i:integer;begini:=0;while i<Listbox1.Items.Count doif ListBox1.Selected[i] thenbeginListBox2.Items.Add(ListBox1.Items[i]);ListBox1.Items.Delete(i);endElsei:=i+1;end;procedure TForm1.Button3Click(Sender: TObject);var i:integer;begini:=0;while i<Listbox2.Items.Count doif ListBox2.Selected[i] thenListBox2.Items.Delete(i)Elsei:=i+1;end;procedure TForm1.Button2Click(Sender: TObject);beginListBox2.Items.Clear;end;procedure TForm1.Button5Click(Sender: TObject);var i,tag:integer;sqlTest,sWtest,sub:String;begini:=0;strWhere:='';while i<Listbox2.Items.Count dobeginif strWhere='' thenbeginsWtest:='WHERE 条件like '+'''%'+ListBox2.Items[i]+'%'' ';sWtest:=sWtest+'and '+'条件not like ''%不'+ListBox2.Items[i]+'%'' ';sqlTest:=sql+sWtest;tag:=0;if Query1.Active then query1.Close;query1.SQL.Clear;query1.SQL.Add(sqlTest);query1.Active:=true;query1.First;while not query1.Eof dobeginif(Pos('类',query1.fieldbyname('结论').asString)<>0)thenbeginif strWhere='' then strWhere:='WHERE 条件like '+'''%'+query1.fieldbyname('结论').asString+'%'' 'elsestrWhere:=strWhere+'or 条件like '+'''%'+query1.fieldbyname('结论').asString+'%'' ';tag:=1;end;query1.Next;end;if tag=0 thenbeginstrWhere:='WHERE 条件like '+'''%'+ListBox2.Items[i]+'%'' ';strWhere:=strWhere+'and '+'条件not like ''%不'+ListBox2.Items[i]+'%'' ';end;endelsebeginsWtest:='WHERE 条件like '+'''%'+ListBox2.Items[i]+'%'' ';sWtest:=sWtest+'and '+'条件not like ''%不'+ListBox2.Items[i]+'%'' ';sqlTest:=sql+sWtest;if Query1.Active then query1.Close;query1.SQL.Clear;query1.SQL.Add(sqlTest);query1.Active:=true;query1.First;tag:=0;while not query1.Eof dobeginif(Pos('类',query1.fieldbyname('结论').asString)<>0)thenbeginsub:=query1.fieldbyname('结论').asString;if(Pos(sub,strWhere)<>0)thenbegintag:=1;break;endelsebeginstrWhere:=strWhere+'and 条件like '+'''%'+query1.fieldbyname('结论').asString+'%'' ';tag:=1;end;end;query1.Next;end;if tag=1 then begin i:=i+1;continue; end;sWtest:=strWhere+'and 条件like '+'''%'+ListBox2.Items[i]+'%'' ';sWtest:=sWtest+'and '+'条件not like ''%不'+ListBox2.Items[i]+'%'' ';sqlTest:=sql+sWtest;if Query1.Active then query1.Close;query1.SQL.Clear;query1.SQL.Add(sqlTest);query1.Active:=true;query1.First;tag:=0;while not query1.Eof dobeginif(Pos('类',query1.fieldbyname('结论').asString)<>0)thenbeginstrWhere:=strWhere+'and 条件like '+'''%'+query1.fieldbyname('结论').asString+'%'' ';tag:=1;end;query1.Next;end;if tag=0 thenbeginstrWhere:=strWhere+'and 条件like '+'''%'+ListBox2.Items[i]+'%'' ';strWhere:=strWhere+'and '+'条件not like ''%不'+ListBox2.Items[i]+'%'' ';end;end;i:=i+1;end;sql:=sql+strWhere;if Query1.Active then query1.Close;query1.SQL.Clear;query1.SQL.Add(sql);query1.Active:=true;if query1.RecordCount=1 thenbeginform2:=Tform2.create(nil);form2.Left:=form1.Left+30;form2.Top:=form1.Top+20;sub:=query1.fieldbyname('结论').asString;tag:=0;if sub='金钱豹' then tag:=1else if sub='老虎' then tag:=2else if sub='长颈鹿' then tag:=3else if sub='斑马' then tag:=4else if sub='鸵鸟' then tag:=5else if sub='企鹅' then tag:=6else if sub='信天翁' then tag:=7;case tag of1:beginform2.Image1.Picture.LoadFromFile('图片/金钱豹.jpg');bel2.Caption:='金钱豹';end;2:beginform2.Image1.Picture.LoadFromFile('图片/老虎.jpg');bel2.Caption:='老虎';end;3:beginform2.Image1.Picture.LoadFromFile('图片/长颈鹿.jpg');bel2.Caption:='长颈鹿';end;4:beginform2.Image1.Picture.LoadFromFile('图片/斑马.jpg');bel2.Caption:='斑马';end;5:beginform2.Image1.Picture.LoadFromFile('图片/鸵鸟.jpg');bel2.Caption:='鸵鸟';end;6:beginform2.Image1.Picture.LoadFromFile('图片/企鹅.jpg');bel2.Caption:='企鹅';end;7:beginform2.Image1.Picture.LoadFromFile('图片/信天翁.jpg');bel2.Caption:='信天翁';end;elsebeginform2.Image1.V isible:=false;form2.DBGrid1.Visible:=true;end;end;form1.Enabled:=false;endelseif query1.RecordCount>1 thenShowMessage('条件不足,请输入充足的条件')elseshowMessage('条件相悖,不存在这样的动物');sql:='SELECT 结论FROM 推导'; ListBox1.Clear;ListBox2.Clear;with table1 dobeginfirst;while not eof dobeginListBox1.Items.Add(fieldbyname('条件').asString);next;end;end;end;end.//unit2.dfmunit Unit2;interfaceusesWindows, Messages, SysUtils, V ariants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Grids, DBGrids, jpeg;typeTForm2 = class(TForm)Label2: TLabel;Image1: TImage;DBGrid1: TDBGrid;procedure FormClose(Sender: TObject; var Action: TCloseAction);private{ Private declarations }public{ Public declarations }end;varForm2: TForm2;implementationuses Unit1;{$R *.dfm}procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);beginform1.Enabled:=true; form2.Release; end;end.五、实验总结通过本次实验对人工智能有了新的高度的认识,尤其是在实现专家系统中,对数据库的操作有了新的认识。
人工智能作业——动物识别系统动物识别专家系统-------胡沧粟—20131313058动物识别系统由多种规则来判别,首先原则是根据是哺乳动物还是鸟类来区别大类。
然后根据在哺乳动物类里建立规则:食肉动物,非食肉,黄褐色,有斑点,长脖子,黑白两色来区分老虎,金钱豹,长颈鹿和斑马。
鸟类里面建议规则:会飞,不会飞,长腿,黑白两色来区分信天翁,企鹅和鸵鸟。
将书本上的规则适当进行了简化,并利用界面的人性化来诱导人们更好的使用软件。
程序由c#语言编写。
本程序系统在考虑到整体结构相同的结构下,将规则进行了优化。
先将哺乳动物与非哺乳动物进行了区分,从而在选取完第一条规则后可以筛选掉很多不用的规则。
在哺乳动物里,规则如下:1.老虎=食肉+黄褐色2.金钱豹=食肉+有斑点3.长颈鹿=非食肉+长脖子4.斑马=非食肉+黑白两色鸟类动物里面,规则如下:1.信天翁=会飞2.企鹅=不会飞+黑白两色3.鸵鸟=不会飞+长腿程序实际操作图:1.程序界面通过选取哺乳动物和鸟类可以筛选掉很多不需要的信息。
2.当按以上的规则描述时可以通过下面的显示栏显示判定的动物。
3.当错误输入或者选取规则过多时则会显示错误提醒。
部分程序代码:using System;using System.Collections.Generic; using ponentModel; using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms; namespace人工智能作业;{public partial class form1 : Form {public form1(){InitializeComponent();panel1.Visible = true;panel2.Visible = false;bel3.Text = str1;radioButton1.Checked = true;}private void button1_Click(object sender, EventArgs e){//bel3.Text = str1;this.button1.Enabled = false;if ((checkBox01.Checked == true) && (checkBox03.Checked == true) && (checkBox02.Checked == false) && (checkBox04.Checked == false) && (checkBox05.Checked == false) && (checkBox06.Checked == false))bel3.Text = str1 + "老虎";if ((checkBox01.Checked == true) && (checkBox02.Checked == true) && (checkBox03.Checked == false) && (checkBox04.Checked == false) && (checkBox05.Checked == false) && (checkBox06.Checked == false)){bel3.Text = str1 + "金钱豹";}if ((checkBox04.Checked == true) && (checkBox05.Checked == true) && (checkBox02.Checked == false) && (checkBox01.Checked == false) && (checkBox03.Checked == false) && (checkBox06.Checked == false)){bel3.Text = str1 + "长颈鹿";if ((checkBox04.Checked == true) && (checkBox06.Checked == true) && (checkBox02.Checked == false) && (checkBox01.Checked == false) && (checkBox05.Checked == false) && (checkBox03.Checked == false))bel3.Text = str1 + "斑马";if ((checkBox07.Checked == true) && (checkBox08.Checked == false) && (checkBox09.Checked == false) && (checkBox10.Checked == false) ){bel3.Text = str1 + "信天翁";}if ((checkBox09.Checked == true) && (checkBox08.Checked == true) && (checkBox07.Checked == false) && (checkBox10.Checked == false)){bel3.Text = str1 + "鸵鸟";}if ((checkBox09.Checked == true) && (checkBox10.Checked == true) && (checkBox08.Checked == false) && (checkBox07.Checked == false)){bel3.Text = str1 + "企鹅";}if ((bel3.Text == str1)){MessageBox.Show("动物类型描述错误,请重新输入!");this.button1.Enabled = true;}}private void radioButton1_CheckedChanged(object sender, EventArgs e){if (radioButton1.Checked == true){panel1.Visible = true;panel2.Visible = false;}}private void radioButton2_CheckedChanged(object sender, EventArgs e){if (radioButton2.Checked == true){panel2.Visible = true;panel1.Visible = false;}private void button2_Click(object sender, EventArgs e) {bel3.Text = str1;this.button1.Enabled = true;checkBox01.Checked = false;checkBox02.Checked = false;checkBox03.Checked = false;checkBox04.Checked = false;checkBox05.Checked = false;checkBox06.Checked = false;checkBox07.Checked = false;checkBox08.Checked = false;checkBox09.Checked = false;checkBox10.Checked = false;}}}。
摘要专家系统是目前人工智能中最活跃,最有成效的一个研究领域,它是一种基于知识的系统,它从人类专家那里获得知识,并用来解决只有专家才能解决的困难问题。
该动物识别专家系统是在VC编程环境下编写的基于Windows操作平台上的图形用户界面程序,依据15条规则,构建知识库,能判别七种动物。
该系统具有较好的扩充性,可移植性、透明性,算法简单高效,使用方便,用户界面友好。
在层次树结构的数据结构基础上,采用正向推理的技术构建推理机,解释机构的实现采用了唱片技术和追踪技术。
构建该动物识别专家系统主要目的是为了提高人工智能的理论水平,更深入地了解专家系统的原理、历史、构成和各组成部件的基本原理,并提高VC的编程能力。
关键字:专家系统,知识库,规则,推理机,解释机AbstractExpert system is one of the most active and effective research realms. It can solve difficult problems, which can only be solved by experts. It is a system based on knowledge and can achieve knowledge from experts.This expert system is the visual interface program, which based on Windows operation system in the situation of Visual C++ programming. It can distinguish seven kinds of animals by constructing knowledge base, which is based on 15 rules. This system is moveable, transparent, and expansible. It can be easily used. Its mathematic is simple and efficient the user interface is friendly. The construction of reasoning machine adopts the positive reasoning technology and the realization of explanation adopts the record and pursuit technologyThis animal distinguish expert system aims to raise the theory standard of artificial intelligence. The writer intended to know about the principle, the history and the composition theory of expert system, and upgrade the programming ability.Key W ords: expert system, repository, rule, reasoning machine, explanative machine目录摘要 (1)Abstract (2)目录 (3)前言 (4)第一章需求分析 (6)1.1 需求状况 (6)1.2专家系统的设计要求 (6)1.3组成部分 (10)1.4推理机 (12)第2章概要设计 (14)2.1总体流程的设计 (14)2.1.1创建知识库 (14)2.1.2 设计推理机的工作流程 (17)2.2用户界面设计 (19)2.2.1 用户界面设计的原则 (19)2.2.2设计的用户界面 (20)第3章详细设计 (22)3.1学习VC有感 (22)3.1.1认识VC (22)3.1.2使用MSDN (23)3.2 详细编码 (24)第4章测试与完善 (37)4.1 测试系统 (37)4.2 完善功能 (38)4.2.1改善explain功能 (38)4.2.2 添加backspace功能........................... 错误!未定义书签。
动物识别专家系统1、专家系统的基本工作原理尽管专家系统有众多类型, 名称各异, 但基本原理框图一致, 如图1 所示。
专家系统的核心是知识库和推理机, 其基本工作过程为: 系统根据知识库中的知识和用户提供的事实进行推理, 不断地由已知前提推出一些初步结论, 并将这些初步结论作为中间结果存放在数据库中, 然后将其作为新的已知事实进行下一步推理, 往复循环, 逐步逼近求解目标。
在这个过程中, 系统可以通过人机接口不断地与用户交流, 向用户提问, 或对用户提出的问题做出解释。
知识库是专家系统的知识存储器, 用来存放求解问题的领域知识。
推理机是专家系统中用来实现推理的程序。
其主要功能是模拟领域专家的思维过程, 控制并执行对问题的求解。
它能根据当前已知的事实, 利用知识库中的知识, 按一定的推理方法和控制策略进行推理, 直到得出相应的结论为止。
它包括推理方法和控制策略两个部分。
大多数专家系统都采用人机对话的交互式解释方法。
知识获取机构主要实现机器学习。
人机接口是领域专家、知识工程师、一般用户间进行交互的界面, 由一组程序及相应的硬件组成, 用于完成输入输出工作。
2、动物识别专家系统在PROLOG 下的实现和使用说明为了更好地阐明专家系统的基本工作原理, 我们用PROLOG语言实现一个简单的动物识别专家系统。
该系统可以识别老虎、金钱豹、斑马、长颈鹿、鸵鸟、企鹅、海燕这7 种动物1、知识库在本系统当中, 知识库中的知识用产生式规则来表示。
本系统能够识别7 种动物, 知识库中共有以下15 条规则。
R1 IF 该动物有毛发THEN 该动物是哺乳动物R2 IF 该动物有奶THEN 该动物是哺乳动物R3 IF 该动物有羽毛THEN 该动物是鸟R4 IF 该动物会飞AND会下蛋THEN 该动物是鸟R5 IF 该动物吃肉THEN 该动物是肉食动物R6 IF 该动物有犬齿AND 有爪AND 眼盯前方THEN 该动物是肉食动物R7 IF 该动物是哺乳动物AND 有蹄THEN 该动物是有蹄类动物R8 IF 该动物是哺乳动物AND 是嚼反刍动物THEN 该动物是有蹄类动物R9 IF 该动物是哺乳动物AND 是肉食动物AND 是黄褐色们AND 身上有暗斑点THEN该动物是金钱豹R10 IF 该动物是哺乳动物AND 是肉食动物AND 是黄褐色AND 身上有黑色条纹THEN 该动物是虎R11 IF 该动物是有蹄类动物AND有长脖子AND 有长腿AND 身上有暗斑点THEN 该动物是长颈鹿R12 IF 该动物是有蹄类动物AND身上有黑色条纹THEN 该动物是斑马R13 IF 该动物是鸟AND 有长脖子AND 有长腿AND 不会飞THEN 该动物是鸵鸟R14 IF 该动物是鸟AND 会游泳AND不会飞AND 有黑白二色THEN 该动物是企鹅R15 IF 该动物是鸟AND 善飞THEN 该动物是海燕在知识库中, 并非简单地给每一种动物一条规则。
动物识别专家系统摘要:专家系统是具有人工智能和推理功能的知识系统。
本系统用15条规则,可识别7种动物,用C编程实现,并对结果进行了分析。
该系统把规则的前提与推理机构结合起来,规则的前提作为推理的情况,规则的结论作为推理过程的状态,推理出最终结果后,就能直接处理,不需要判断。
关键字:专家系统;动物;推理Animal recognition expert systemAbstract: Expert systems are knowledge systems with artificial intelligence and reasoning function. The system uses 15 rules, and can identify seven kinds of animals, using C programming, and the results were analyzed. The system is the premise and reasoning mechanism combining rules, rules for reasoning rule conclusion as the reasoning process , reasoning out the final result , can directly handle, without judge.Key words: Expert systems; Animals; Reasoning1 引言1.1 专家系统简介专家系统是人工智能中最重要的也是最活跃的一个应用领域,它实现了人工智能从理论研究走向实际应用、从一般推理策略探讨转向运用专门知识的重大突破。
专家系统是早期人工智能的一个重要分支,它可以看作是一类具有专门知识和经验的计算机智能程序系统,一般采用人工智能中的知识表示和知识推理技术来模拟通常由领域专家才能解决的复杂问题 [1]。
动物专家系统课程设计一、教学目标本课程旨在让学生了解和掌握动物的基本知识,培养学生对动物的观察、分析和思考能力,提高学生对动物保护的意识。
具体目标如下:1.知识目标:a.掌握动物的分类、特征、习性和生态环境等基本知识;b.了解动物的进化和人类对其影响;c.理解动物在生态系统中的作用。
2.技能目标:a.能运用观察、、实验等方法研究动物;b.学会分析动物行为和生态环境的关系;c.能撰写简单的动物研究报告。
3.情感态度价值观目标:a.培养学生对动物的热爱和保护意识;b.培养学生团结合作、勇于探究的精神;c.培养学生珍惜生命、关注生态环境的观念。
二、教学内容本课程以动物的基本知识为主线,教学大纲如下:1.动物的分类与特征:介绍动物的分类系统,重点讲解脊椎动物和无脊椎动物的特点。
2.动物的生态环境:讲解动物的生活习性、栖息地选择和生态适应。
3.动物的进化:介绍动物的进化历程,重点讲解生物进化的证据和机制。
4.动物的行为:分析动物行为的适应意义和分类,如取食行为、繁殖行为等。
5.人类与动物:探讨人类活动对动物的影响,如栖息地破坏、偷猎等。
6.动物保护:讲解保护动物的重要性,介绍保护措施和我国的相关法律法规。
三、教学方法为激发学生的学习兴趣和主动性,本课程采用多种教学方法:1.讲授法:讲解动物的基本知识和概念,使学生掌握动物的基本特征。
2.讨论法:分组讨论动物行为和生态环境的关系,培养学生的思考和表达能力。
3.案例分析法:分析典型动物案例,使学生了解动物保护的重要性。
4.实验法:学生进行动物观察和实验,提高学生的实践操作能力。
四、教学资源为支持教学内容和教学方法的实施,丰富学生的学习体验,我们将采用以下教学资源:1.教材:《动物生物学》,为学生提供系统、全面的动物知识。
2.参考书:挑选相关领域的经典著作,为学生提供深入的阅读材料。
3.多媒体资料:制作课件、动画等,形象生动地展示动物的特点和生态环境。
4.实验设备:购置必要的实验器材,如显微镜、标本等,为学生提供实践操作的机会。