1、昆明理工大学人工智能第二次实验报告理工大学信息工程与自动化学院学生实验报告( 2013 2014 学年 第 1 学期 )课程名称:人工智能 开课实验室:信自楼445 2013 年12月 20日年级、专业、班计科113学号4周国映成绩教师评语该同学是否了解实验原理: A.了解 B.基本了解 C.不了解该同学的实验能力: A.强 B.中等 C.差 该同学的实验是否达到要求: A.达到 B.基本达到 C.未达到实验报告是否规: A.规 B.基本规 C.不规实验过程是否详细记录: A.详细 B.一般 C.没有 教师签名: 年 月 日实验项目名称天气决策树指导教师 英莉一、上机目的及容1.上机容用确定性
2、推理算法求解教材65-66页介绍的八数码难题。2.上机目的(1)复习程序设计和数据结构课程的相关知识,实现课程间的平滑过渡;(2)掌握并实现在小规模状态空间中进行图搜索的方法;(3)理解并掌握图搜索的技术要点。二、实验原理及基本技术路线图(方框原理图或程序流程图)(1)设计并实现程序,求解出正确的解答路径;(2)对所设计的算法采用大O符号进行时间复杂性和空间复杂性分析;(3)对一般图搜索的技术要点和技术难点进行评述性分析。三、所用仪器、材料(设备名称、型号、规格等或使用软件)1台PC及VISUAL C+6.0软件四、实验方法、步骤(或:程序代码或操作过程) 建立工程后建立5个source Fi
3、les文件分别为1.AttributeValue.cpp#include AttributeValue.h#include base.hAttributeValue:AttributeValue(std:string const& instring): m_value(instring)bool AttributeValue:GetType() if (m_value = P) return true; else if (m_value = N) return false; else throw DataErrException(); 2.basefun.cpp#include float l
4、og2 (float x) return 1.0 / log10(2) * log10(x);float calEntropy(float prob) float sum=0; if (prob = 0 | prob = 1) return 0; sum -= prob * log2(prob); sum -= (1 - prob) * log2 ( 1 - prob ); return sum;3.DataPoint.cpp#include #include DataPoint.hDataPoint:DataPoint(std:vector const& attributes, bool t
5、ype): m_type(type) for (int i=0; iattributes.size(); +i) m_attributes.push_back( attributesi ); void DataPoint:display() for (int i=0; im_attributes.size(); +i) std:cout t m_attributesi.getValue(); if (true = m_type) std:cout tP; else std:cout tN; std:cout std:endl;4.DataSet.cpp5.main.cpp#include #i
6、nclude #include #include #include #include #include AttributeValue.h#include DataPoint.h#include DataSet.hDataPoint processLine(std:string const& sLine) std:istringstream isLine(sLine, std:istringstream:in); std:vector attributes; / TODO: need to handle beginning and ending empty spaces. while( isLi
7、ne.good() ) std:string rawfield; isLine rawfield; attributes.push_back( AttributeValue( rawfield ) ); AttributeValue v = attributes.back(); attributes.pop_back(); bool type = v.GetType(); return DataPoint(attributes, type); void main() std:ifstream ifs(in.txt, std:ifstream:in); DataSet initDataset;
8、while( ifs.good() ) / TODO: need to handle empty lines. std:string sLine; std:getline(ifs, sLine); initDataset.addDataPoint( processLine(sLine) ); std:list processQ; std:vector finishedDataSet; processQ.push_back(initDataset); while ( processQ.size() 0 ) std:vector splittedDataSets; DataSet dataset
9、= processQ.front(); dataset.splitDataSet(splittedDataSets); processQ.pop_front(); for (int i=0; isplittedDataSets.size(); +i) float prob = splittedDataSetsi.getPositiveProb(); if (prob = 0.0 | prob = 1.0) finishedDataSet.push_back(splittedDataSetsi); else processQ.push_back(splittedDataSetsi); std:c
10、out The dicision tree is: std:endl; for (int i = 0; i finishedDataSet.size(); +i) finishedDataSeti.display(); 建立4个Header Files文件1.AttributeValue.h#ifndef ATTRIBUTE_VALUE_H_#define ATTRIBUTE_VALUE_H_#include class AttributeValuepublic: AttributeValue(std:string const& instring); bool GetType(); std:s
11、tring const& getValue() const return m_value; private: std:string m_value;struct AttributeValueCmp bool operator() (AttributeValue const& lhs, AttributeValue const& rhs) const return lhs.getValue() rhs.getValue(); ;#endif2.base.hclass DataErrException : public std:exception;float calEntropy(float pr
12、ob);3.DatePoint.h#ifndef DATA_POINT_H_#define DATA_POINT_H_#include #include AttributeValue.hclass DataPointpublic: DataPoint(std:vector const& attributes, bool type); bool isPositive() return m_type; int getNAttributes() return m_attributes.size(); AttributeValue const& getAttribute(int index) retu
13、rn m_attributesindex; void display();private: std:vector m_attributes; bool m_type;#endif4.DateSet.h#include #include #include DataPoint.hclass SplitAttributeValuepublic: SplitAttributeValue(AttributeValue v, int id) : m_v(v) , m_attributeIndex(id) int getAttributeIndex() return m_attributeIndex; vo
14、id display();private: int m_attributeIndex; AttributeValue m_v;class DataSetpublic: void addDataPoint(DataPoint const& datapoint); float getPositiveProb(); void splitDataSet(std:vector& splittedSets); void display();private: std:vector m_splitAttributes; std:vector m_data;五、实验过程原始记录( 测试数据、图表、计算等)实验运行截图六、实验结果、分析和结论(误差分析与数据处理、成果总结等。其中,绘制曲线图时必须用计算纸或程序运行结果、改进、收获) 这次事件让我的编程能力有了很大的提高,查阅资料等能力也有很大的提升。让我对人工智能技术有了进一步的认识。在解决问题和算法设计上的能力也极提高。这次作业我收集相关材料阅读并消化, 在实际应用中,我发现人工智能是一门很有意思的学科,对本门课程产生了兴趣。在以后的学习中,我会认真学好这门课程。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1