版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
昆明理工大学人工智能第二次实验报告昆明理工大学信息工程与自动化学院学生实验报告2013—2014学年第1学期)课程名称:人工智能开课实验室:信自楼4452013年12月20日年级、专业、计科113学号201110405314姓名周国映成绩班教A.了解□B.基本了师该同学是否了解实验原理:解□C.不了解□评语该同学的实验能力:A.强□B.中等□C.差□该同学的实验是否达到要求:A.达到□B.基本达到□C.未达到□实验报告是否规范:A.规范□B.基本规范□C.不规范□实验过程是否详细记录:A.详细□B.一般□C.没有□教师签名:年月日实验项目名称天气决策树指导教师刘英莉一、上机目的及内容上机内容用确定性推理算法求解教材65-66页介绍的八数码难题。-2-上机目的1)复习程序设计和数据结构课程的相关知识,实现课程间的平滑过渡;2)掌握并实现在小规模状态空间中进行图搜索的方法;3)理解并掌握图搜索的技术要点。二、实验原理及基本技术路线图(方框原理图或程序流程图)1)设计并实现程序,求解出正确的解答路径;2)对所设计的算法采用大O符号进行时间复杂性和空间复杂性分析;3)对一般图搜索的技术要点和技术难点进行评述性分析。三、所用仪器、材料(设备名称、型号、规格等或使用软件)1台PC及VISUALC++6.0 软件四、实验方法、步骤(或:程序代码或操作过程)建立工程后建立 5个sourceFiles文件分别为-3-AttributeValue.cpp#include"AttributeValue.h"#include"base.h"AttributeValue::AttributeValue(std::stringconst&instring)m_value(instring){}boolAttributeValue::GetType(){if(m_value=="P"){returntrue;}elseif(m_value=="N"){returnfalse;}else{-4-throwDataErrException();}}basefun.cpp#include<math.h>floatlog2(floatx){return1.0/log10(2)*log10(x);}floatcalEntropy(floatprob){floatsum=0;if(prob==0||prob==1){return0;}sum-=prob*log2(prob);sum-=(1-prob)*log2(1-prob);returnsum;-5-}DataPoint.cpp#include<iostream>#include"DataPoint.h"DataPoint::DataPoint(std::vector<AttributeValue>const&attributes,booltype)m_type(type){for(inti=0;i<attributes.size();++i){m_attributes.push_back(attributes[i]);}}voidDataPoint::display(){for(inti=0;i<m_attributes.size();++i){std::cout<<"\t"<<m_attributes[i].getValue();-6-}if(true==m_type){std::cout<<"\tP";}else{std::cout<<"\tN";}std::cout<<std::endl;}DataSet.cppmain.cpp#include<fstream>#include<iostream>#include<list>#include<sstream>#include<string>#include<vector>-7-#include"AttributeValue.h"#include"DataPoint.h"#include"DataSet.h"DataPointprocessLine(std::stringconst&sLine){std::istringstreamisLine(sLine,std::istringstream::in);std::vector<AttributeValue>attributes;TODO:needtohandlebeginningandendingemptyspaces.while(isLine.good()){std::stringrawfield;isLine>>rawfield;attributes.push_back(AttributeValue(rawfield));}-8-AttributeValuev=attributes.back();attributes.pop_back();booltype=v.GetType();returnDataPoint(attributes,type);}voidmain(){std::ifstreamifs("in.txt",std::ifstream::in);DataSetinitDataset;while(ifs.good()){TODO:needtohandleemptylines.std::stringsLine;std::getline(ifs,sLine);initDataset.addDataPoint(processLine(sLine));}std::list<DataSet>processQ;std::vector<DataSet>finishedDataSet;-9-processQ.push_back(initDataset);while(processQ.size()>0){std::vector<DataSet>splittedDataSets;DataSetdataset=processQ.front();dataset.splitDataSet(splittedDataSets);processQ.pop_front();for(inti=0;i<splittedDataSets.size();++i){floatprob=splittedDataSets[i].getPositiveProb();if(prob==0.0||prob==1.0){finishedDataSet.push_back(splittedDataSets[i]);}else{-10-processQ.push_back(splittedDataSets[i]);}}}std::cout<<"Thedicisiontreeis:"<<std::endl;for(inti=0;i<finishedDataSet.size();++i){finishedDataSet[i].display();}}建立4个HeaderFiles文件1.AttributeValue.h#ifndefATTRIBUTE_VALUE_H_#defineATTRIBUTE_VALUE_H_#include<string>classAttributeValue{public:AttributeValue(std::stringconst&instring);-11-boolGetType();std::stringconst&getValue()const{returnm_value;}private:std::stringm_value;};structAttributeValueCmp{booloperator()(AttributeValueconst&lhs,AttributeValueconst&rhs)const{returnlhs.getValue()<rhs.getValue();}};#endif2.base.hclassDataErrException:publicstd::exception{-12-};floatcalEntropy(floatprob);3.DatePoint.h#ifndefDATA_POINT_H_#defineDATA_POINT_H_#include<vector>#include"AttributeValue.h"classDataPoint{public:DataPoint(std::vector<AttributeValue>const&attributes,booltype);boolisPositive(){returnm_type;}intgetNAttributes(){-13-returnm_attributes.size();}AttributeValueconst&getAttribute(intindex){returnm_attributes[index];}voiddisplay();private:std::vector<AttributeValue>m_attributes;boolm_type;};#endifDateSet.h#include<map>#include<utility>#include"DataPoint.h"classSplitAttributeValue{-14-public:SplitAttributeValue(AttributeValuev,intid): m_v(v)m_attributeIndex(id){}intgetAttributeIndex(){returnm_attributeIndex;}voiddisplay();private:intm_attributeIndex;AttributeValuem_v;};classDataSet{public:voidaddDataPoint(DataPointconst&datapoint);floatgetPositiveProb();-15-voidsplitDataSet(std::vector<DataSet>&splittedSets);voiddisplay();private:std::vector<SplitAttributeValue>m_splitAttributes;std::vector<DataPoint>m_data;};五、实验过程原始记录
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 初中化学课堂互动教学策略与化学实验操作技能培养研究教学研究课题报告
- 2026年云南珠光实业集团有限公司备考题库(含答案详解)
- 乐山职业技术学院2025年下半年公开考核招聘工作人员备考题库含答案详解
- 2026年澄江市教育体育系统公开招聘毕业生备考题库及一套完整答案详解
- 朝阳市第二医院2025年放射影像技师招聘备考题库及一套参考答案详解
- 2026年北京航空航天大学可靠性与系统工程学院聘用编科研助理F岗招聘备考题库及答案详解一套
- 南京古生物所非在编项目聘用人员(劳务派遣)招聘备考题库(2025年第18期)参考答案详解
- 初中历史教学中如何引导学生进行史料分析的探究教学研究课题报告
- 2026年中化地质矿山总局湖南地质勘查院校园招聘6人备考题库参考答案详解
- 2025年区块链跨境电商供应链金融市场分析报告
- 消防系统瘫痪应急处置方案
- 病理生理学复习重点缩印
- 《大数的认识》复习教学设计
- GB/T 3513-2018硫化橡胶与单根钢丝粘合力的测定抽出法
- GB/T 11417.5-2012眼科光学接触镜第5部分:光学性能试验方法
- 《寝室夜话》(4人)年会晚会搞笑小品剧本台词
- 统编教材部编人教版小学语文习作单元教材解读培训课件:统编小语四-六年级习作梳理解读及教学建议
- 开放大学土木工程力学(本)模拟题(1-3)答案
- 医疗机构远程医疗服务实施管理办法
- 【教学课件】谋求互利共赢-精品课件
- 情感性精神障碍护理课件
评论
0/150
提交评论