昆明理工大学人工智能第二次_第1页
昆明理工大学人工智能第二次_第2页
昆明理工大学人工智能第二次_第3页
昆明理工大学人工智能第二次_第4页
昆明理工大学人工智能第二次_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

昆明理工大学人工智能第二次实验报告昆明理工大学信息工程与自动化学院学生实验报告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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论