ID3 Algorithm - Reference Manual

61
Reference Manual Generated by Doxygen 1.6.3 Fri Dec 16 16:50:04 2011

description

One of the biggest dilemmas faced by decision-making systems is to determine an efficient means to produce classifiers from data base regarding the processing time and the form of simple symbolic representation understandable that facilitates the analysis of the problem in question. In this brief report we will discuss a very popular tool in knowledge discovery in databases process and thus aid in making decisions: the Decision Trees.

Transcript of ID3 Algorithm - Reference Manual

Page 1: ID3 Algorithm - Reference Manual

Reference Manual

Generated by Doxygen 1.6.3

Fri Dec 16 16:50:04 2011

Page 2: ID3 Algorithm - Reference Manual
Page 3: ID3 Algorithm - Reference Manual

Contents

1 Namespace Index 1

1.1 Namespace List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 Class Index 3

2.1 Class List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 File Index 5

3.1 File List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 Namespace Documentation 7

4.1 LibraryUtils Namespace Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4.1.1 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4.1.1.1 DoubleToStr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4.1.1.2 IntToStr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.1.3 IsNumeric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.1.4 SignalNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.1.5 StrIndexOf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.1.6 StrStartsWith . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.1.7 StrToFloat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1.1.8 StrToInt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1.1.9 TrimString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5 Class Documentation 11

5.1 LibraryUtils::ConversionError Class Reference . . . . . . . . . . . . . . . . . . . . . . . 11

5.1.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5.1.2 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5.1.2.1 what . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5.2 ID3 Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5.2.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.2.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 13

Page 4: ID3 Algorithm - Reference Manual

ii CONTENTS

5.2.2.1 ID3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.2.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.2.3.1 alreadyUsedToDecompose . . . . . . . . . . . . . . . . . . . . . . . . 13

5.2.3.2 calculateEntropy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.2.3.3 createDecisionTree . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.2.3.4 decomposeNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5.2.3.5 getAllValues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

5.2.3.6 getSubset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5.2.3.7 getSymbolValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.2.3.8 printDomains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.2.3.9 printMyLabels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.2.3.10 printTree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

5.2.3.11 readData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5.3 LibraryTime Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 22

5.3.2.1 LibraryTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.2.2 ∼LibraryTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.3.1 Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.3.2 Get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.3.3.3 Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.3.3.4 Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.4 StringTokenizer Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

5.4.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

5.4.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 24

5.4.2.1 StringTokenizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

5.4.2.2 ∼StringTokenizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.4.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.4.3.1 countTokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.4.3.2 filterNextToken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.4.3.3 hasMoreTokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.4.3.4 nextFloatToken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.4.3.5 nextIntToken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.4.3.6 nextToken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

5.4.3.7 nextToken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 5: ID3 Algorithm - Reference Manual

CONTENTS iii

5.4.3.8 remainingString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6 File Documentation 29

6.1 LibraryTime.cxx File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

6.2 LibraryTime.cxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

6.3 LibraryTime.h File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.4 LibraryTime.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.5 LibraryUtils.h File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6.6 LibraryUtils.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

6.7 MyID3Algorithm.cpp File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6.7.1 Typedef Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.7.1.1 IntegerList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.7.1.2 StringList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.7.1.3 StringTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.7.2 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.7.2.1 main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.7.2.2 VectorIndexOf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.8 MyID3Algorithm.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

6.9 StringTokenizer.cpp File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

6.10 StringTokenizer.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

6.11 StringTokenizer.h File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

6.12 StringTokenizer.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 6: ID3 Algorithm - Reference Manual
Page 7: ID3 Algorithm - Reference Manual

Chapter 1

Namespace Index

1.1 Namespace List

Here is a list of all namespaces with brief descriptions:

LibraryUtils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Page 8: ID3 Algorithm - Reference Manual

2 Namespace Index

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 9: ID3 Algorithm - Reference Manual

Chapter 2

Class Index

2.1 Class List

Here are the classes, structs, unions and interfaces with brief descriptions:

LibraryUtils::ConversionError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11ID3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12LibraryTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22StringTokenizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Page 10: ID3 Algorithm - Reference Manual

4 Class Index

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 11: ID3 Algorithm - Reference Manual

Chapter 3

File Index

3.1 File List

Here is a list of all files with brief descriptions:

LibraryTime.cxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29LibraryTime.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31LibraryUtils.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33MyID3Algorithm.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37StringTokenizer.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48StringTokenizer.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

Page 12: ID3 Algorithm - Reference Manual

6 File Index

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 13: ID3 Algorithm - Reference Manual

Chapter 4

Namespace Documentation

4.1 LibraryUtils Namespace Reference

Classes

• class ConversionError

Functions

• template<typename T >

std::string DoubleToStr (T const &myvalue, unsigned int precision)

• bool IsNumeric (const std::string &str)

• long double StrToFloat (const std::string &str)

• string IntToStr (int numero)

• long int StrToInt (const std::string &str)

• string TrimString (const std::string str)

• int SignalNumber (long double value)

• int StrIndexOf (const std::string &str, const std::string &piece)

• bool StrStartsWith (const std::string &str, const std::string &piece)

4.1.1 Function Documentation

4.1.1.1 template<typename T > std::string LibraryUtils::DoubleToStr (T const & myvalue,unsigned int precision) [inline]

Definition at line 56 of file LibraryUtils.h.

00057 {00058 std::ostringstream oss;00059 oss << std::setprecision(precision) << myvalue;00060 return oss.str();00061 }

Page 14: ID3 Algorithm - Reference Manual

8 Namespace Documentation

4.1.1.2 string LibraryUtils::IntToStr (int numero)

Definition at line 101 of file LibraryUtils.h.

00102 {00103 std::ostringstream osbuffer;00104 osbuffer << numero;00105 return osbuffer.str();00106 }

4.1.1.3 bool LibraryUtils::IsNumeric (const std::string & str)

Definition at line 65 of file LibraryUtils.h.

00066 {00067 //Declaração das variáveis de conversão00068 std::istringstream iss(str);00069 long double d;0007000071 //Movendo o conteudo da string para a variavel do tipo double00072 iss >> d;0007300074 //Fazendo verificações de conversão00075 if ( !(iss && (iss >> std::ws).eof())) return false;0007600077 //Caso haja falha na conversão uma exceção é lançada caso não o valor é retorna

do00078 return true;00079 }

4.1.1.4 int LibraryUtils::SignalNumber (long double value)

Definition at line 136 of file LibraryUtils.h.

00137 {00138 return (value >= 0)?(1):(-1);00139 }

4.1.1.5 int LibraryUtils::StrIndexOf (const std::string & str, const std::string & piece)

Retorna posição de uma substring dentro de outra.

Definition at line 144 of file LibraryUtils.h.

00145 {00146 std::string::size_type loc = str.find(piece, 0);00147 return (loc != std::string::npos)?(loc):(-1);00148 }

4.1.1.6 bool LibraryUtils::StrStartsWith (const std::string & str, const std::string & piece)

Verifica se uma cadeia de caracteres começa por uma determinada subcadeia.

Definition at line 154 of file LibraryUtils.h.

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 15: ID3 Algorithm - Reference Manual

4.1 LibraryUtils Namespace Reference 9

00155 {00156 return str.find(piece) == 0;00157 }

Here is the caller graph for this function:

LibraryUtils::StrStartsWith ID3::readData main

4.1.1.7 long double LibraryUtils::StrToFloat (const std::string & str)

Definition at line 83 of file LibraryUtils.h.

00084 {00085 //Declaração das variáveis de conversão00086 std::istringstream iss(str);00087 double d;0008800089 //Movendo o conteudo da string para a variavel do tipo double00090 iss >> d;0009100092 //Fazendo verificações de conversão00093 if ( !(iss && (iss >> std::ws).eof())) throw ConversionError();0009400095 //Caso haja falha na conversão uma exceção é lançada caso não o valor é retorna

do00096 return d;00097 }

4.1.1.8 long int LibraryUtils::StrToInt (const std::string & str)

Definition at line 110 of file LibraryUtils.h.

00111 {00112 //Declaração das variaveis de conversão00113 std::istringstream iss(str);00114 int i;0011500116 //Movendo o conteudo do stringstream para a variavel00117 iss >> i;0011800119 //Fazendo verificações de conversão00120 if ( !(iss && (iss >> std::ws).eof())) throw ConversionError();0012100122 //Caso haja falha na conversão uma exceção é lançada caso não o valor é retorna

do00123 return i;00124 }

4.1.1.9 string LibraryUtils::TrimString (const std::string str)

Definition at line 128 of file LibraryUtils.h.

00129 {00130 string result = str;

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 16: ID3 Algorithm - Reference Manual

10 Namespace Documentation

00131 std::remove(result.begin(),result.end(),’ ’);00132 return result;00133 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 17: ID3 Algorithm - Reference Manual

Chapter 5

Class Documentation

5.1 LibraryUtils::ConversionError Class Reference

#include <LibraryUtils.h>

Public Member Functions

• const char ∗ what ()

5.1.1 Detailed Description

Definition at line 37 of file LibraryUtils.h.

5.1.2 Member Function Documentation

5.1.2.1 const char∗ LibraryUtils::ConversionError::what () [inline]

Definition at line 40 of file LibraryUtils.h.

00040 { return "Erro de conversão !"; };

The documentation for this class was generated from the following file:

• LibraryUtils.h

Page 18: ID3 Algorithm - Reference Manual

12 Class Documentation

5.2 ID3 Class Reference

Collaboration diagram for ID3:

ID3

- number_of_attributes- attribute_names- domains- root

+ ID3()+ getSymbolValue()+ getAllValues()+ getSubset()+ calculateEntropy()+ alreadyUsedToDecompose()+ decomposeNode()+ readData()+ printTree()+ createDecisionTree()+ printMyLabels()+ printDomains()

ID3::TreeNode

+ entropy+ data+ decompositionAttribute+ decompositionValue+ children+ parent

+ TreeNode()

root

parent

Classes

• class DataPoint• class TreeNode

Public Member Functions

• ID3 ()• int getSymbolValue (int attribute, std::string symbol)• IntegerList getAllValues (std::vector< DataPoint > data, int attribute)• std::vector< DataPoint > getSubset (std::vector< DataPoint > data, int attribute, int value)• double calculateEntropy (const std::vector< DataPoint > &data)

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 19: ID3 Algorithm - Reference Manual

5.2 ID3 Class Reference 13

• bool alreadyUsedToDecompose (TreeNode ∗node, int attribute)• void decomposeNode (TreeNode ∗node)• bool readData (std::string filename)• void printTree (TreeNode ∗node, std::string tab)• void createDecisionTree ()• void printMyLabels ()• void printDomains ()

5.2.1 Detailed Description

Uma implementação simples do algoritmo ID3 para criação de árvores de decisão

Version

Dec. 01 2011

Author

Michel Alves dos Santos

Definition at line 56 of file MyID3Algorithm.cpp.

5.2.2 Constructor & Destructor Documentation

5.2.2.1 ID3::ID3 () [inline]

Definition at line 152 of file MyID3Algorithm.cpp.

00153 {00154 root = new TreeNode();00155 };

5.2.3 Member Function Documentation

5.2.3.1 bool ID3::alreadyUsedToDecompose (TreeNode ∗ node, int attribute) [inline]

Esta função verifica se o atributo especificado é usado para decompor o conjunto de dados em qualquer umdos pais do nó existente na árvore de decomposição. Verifica recursivamente o nó especificado, bem comotodos os pais.

= null

Definition at line 251 of file MyID3Algorithm.cpp.

00252 {00253 if (node->children.size() != 0 )00254 {00255 if (node->decompositionAttribute == attribute ) return true;00256 }0025700258 if (node->parent == NULL) return false;00259 return alreadyUsedToDecompose(node->parent, attribute);00260 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 20: ID3 Algorithm - Reference Manual

14 Class Documentation

Here is the caller graph for this function:

ID3::alreadyUsedToDecompose ID3::decomposeNode ID3::createDecisionTree main

5.2.3.2 double ID3::calculateEntropy (const std::vector< DataPoint > & data) [inline]

Calcula a entropia do conjunto de dados.

Definition at line 220 of file MyID3Algorithm.cpp.

00221 {00222 int numdata = data.size();00223 if (numdata == 0) return 0;0022400225 int attribute = number_of_attributes - 1;00226 int numvalues = domains[attribute].size();0022700228 double sum = 0;0022900230 for (int i = 0; i < numvalues; i++)00231 {00232 int count = 0;00233 for (int j = 0; j < numdata; j++)00234 {00235 DataPoint point = data.at(j);00236 if (point.attributes[attribute] == i) count++;00237 }0023800239 double probability = 1.0*count/numdata;00240 if (count > 0) sum += -probability*log2(probability);00241 }0024200243 return sum;00244 };

Here is the caller graph for this function:

ID3::calculateEntropy ID3::decomposeNode ID3::createDecisionTree main

5.2.3.3 void ID3::createDecisionTree () [inline]

Essa função cria a árvore de decisão e a imprime na forma de regras no console.

Definition at line 446 of file MyID3Algorithm.cpp.

00447 {00448 decomposeNode(root);00449 printTree(root, "");00450 };

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 21: ID3 Algorithm - Reference Manual

5.2 ID3 Class Reference 15

Here is the call graph for this function:

ID3::createDecisionTree

ID3::decomposeNode

ID3::printTree

ID3::alreadyUsedToDecompose

ID3::calculateEntropy

ID3::getSubset

ID3::getAllValues VectorIndexOf

Here is the caller graph for this function:

ID3::createDecisionTree main

5.2.3.4 void ID3::decomposeNode (TreeNode ∗ node) [inline]

Esta função decompõe o nó especificado de acordo com o algoritmo ID3.

Nos dois seguintes laços, o melhor atributo é localizado.

Definition at line 265 of file MyID3Algorithm.cpp.

00266 {00267 double bestEntropy = 0;00268 bool selected = false;00269 int selectedAttribute = 0;0027000271 int numdata = node->data.size();00272 int numinputattributes = number_of_attributes - 1;0027300274 node->entropy = calculateEntropy(node->data);00275 if (node->entropy == 0) return;0027600280 for (int i = 0; i < numinputattributes; i++)00281 {00282 int numvalues = domains[i].size();00283 if ( alreadyUsedToDecompose(node, i) ) continue;0028400285 // Use a variável seguinte para armazenar a entropia para o nó de teste cri

ado com o atributo i00286 double averageentropy = 0;00287 for (int j = 0; j < numvalues; j++)00288 {00289 std::vector<DataPoint> subset = getSubset(node->data, i, j);00290 if (subset.size() == 0) continue;00291 double subentropy = calculateEntropy(subset);00292 averageentropy += subentropy * subset.size();00293 }0029400295 averageentropy = (double)averageentropy/numdata;00296 if (selected == false)00297 {00298 selected = true;00299 bestEntropy = averageentropy;00300 selectedAttribute = i;00301 }00302 else00303 {

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 22: ID3 Algorithm - Reference Manual

16 Class Documentation

00304 if (averageentropy < bestEntropy)00305 {00306 selected = true;00307 bestEntropy = averageentropy;00308 selectedAttribute = i;00309 }00310 }0031100312 }0031300314 if (selected == false) return;0031500316 // Agora divide o conjunto de dados usando o atributo selecionado00317 int numvalues = domains[selectedAttribute].size();00318 node->decompositionAttribute = selectedAttribute;0031900320 for (int j = 0; j < numvalues; j++)00321 {00322 node->children.push_back( new TreeNode() );00323 node->children[j]->parent = node;00324 node->children[j]->data = getSubset(node->data, selectedAttribute, j);00325 node->children[j]->decompositionValue = j;00326 }0032700328 // Recursivamente divide nós filhos00329 for (int j = 0; j < numvalues; j++)00330 {00331 decomposeNode(node->children[j]);00332 }00333 };

Here is the call graph for this function:

ID3::decomposeNode

ID3::alreadyUsedToDecompose

ID3::calculateEntropy

ID3::getSubset

Here is the caller graph for this function:

ID3::decomposeNode ID3::createDecisionTree main

5.2.3.5 IntegerList ID3::getAllValues (std::vector< DataPoint > data, int attribute) [inline]

Retorna todos os valores do atributo especificado no conjunto de dados.

Definition at line 175 of file MyID3Algorithm.cpp.

00176 {00177 StringList values;00178 int num = data.size();0017900180 for (int i = 0; i < num; i++)00181 {00182 DataPoint point = data.at(i);00183 std::string symbol = domains[attribute].at( point.attributes[attribute] );

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 23: ID3 Algorithm - Reference Manual

5.2 ID3 Class Reference 17

00184 int index = VectorIndexOf(values, symbol);00185 if (index < 0) { values.push_back(symbol); }00186 }0018700188 int array[ values.size() ];0018900190 for (unsigned int i = 0; i < values.size(); i++)00191 {00192 std::string symbol = values.at(i);00193 array[i] = VectorIndexOf(domains[attribute], symbol);00194 }0019500196 IntegerList l;00197 for (unsigned int i = 0; i < values.size(); i++) l.push_back( array[i] );00198 return l;00199 }

Here is the call graph for this function:

ID3::getAllValues VectorIndexOf

Here is the caller graph for this function:

ID3::getAllValues ID3::printTree ID3::createDecisionTree main

5.2.3.6 std::vector<DataPoint> ID3::getSubset (std::vector< DataPoint > data, int attribute, intvalue) [inline]

Retorna um subconjunto de dados, no qual o valor do atributo de todos os pontos de dados é o valorespecificado

Definition at line 204 of file MyID3Algorithm.cpp.

00205 {00206 std::vector<DataPoint> subset; //= new Vector();00207 int num = data.size();0020800209 for (int i = 0; i < num; i++)00210 {00211 DataPoint point = data.at(i);00212 if (point.attributes[attribute] == value) subset.push_back(point);00213 }00214 return subset;00215 };

Here is the caller graph for this function:

ID3::getSubset ID3::decomposeNode ID3::createDecisionTree main

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 24: ID3 Algorithm - Reference Manual

18 Class Documentation

5.2.3.7 int ID3::getSymbolValue (int attribute, std::string symbol) [inline]

Esta função retorna um inteiro correspondente ao valor simbólico do atributo. Se o símbolo não existe nodomínio, o símbolo é adicionado ao domínio do atributo.

Definition at line 161 of file MyID3Algorithm.cpp.

00162 {00163 int index = VectorIndexOf(domains.at(attribute), symbol);00164 if (index < 0)00165 {00166 domains[attribute].push_back(symbol);00167 return domains[attribute].size() - 1;00168 }00169 return index;00170 };

Here is the call graph for this function:

ID3::getSymbolValue VectorIndexOf

Here is the caller graph for this function:

ID3::getSymbolValue ID3::readData main

5.2.3.8 void ID3::printDomains () [inline]

Imprime o conjunto de testes utilizado.

Definition at line 467 of file MyID3Algorithm.cpp.

00468 {00469 for(unsigned int i = 0; i < domains.size(); i++)00470 {00471 std::cerr << "[" << attribute_names.at(i) << "]\t";00472 for(unsigned int j = 0; j < domains[i].size(); j++){ std::cerr << "[" << (d

omains[i]).at(j) << "]\t"; }00473 std::cerr << std::endl;00474 }00475 };

Here is the caller graph for this function:

ID3::printDomains main

5.2.3.9 void ID3::printMyLabels () [inline]

Imprime o nome dos rótulos ou nome dos atributos.

Definition at line 455 of file MyID3Algorithm.cpp.

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 25: ID3 Algorithm - Reference Manual

5.2 ID3 Class Reference 19

00456 {00457 for(unsigned int i = 0; i < attribute_names.size(); i++)00458 {00459 std::cerr << "[" << attribute_names.at(i) << "]\t";00460 }00461 std::cerr << std::endl;00462 };

5.2.3.10 void ID3::printTree (TreeNode ∗ node, std::string tab) [inline]

Esta função imprime a árvore de decisão na forma de regras.

Definition at line 408 of file MyID3Algorithm.cpp.

00409 {00410 int outputattr = number_of_attributes - 1;0041100412 if (node->children.size() == 0)00413 {00414 IntegerList values = getAllValues(node->data, outputattr);0041500416 if (values.size() == 1)00417 {00418 std::cerr << tab + " " + attribute_names[outputattr] + " = \"" + domains[

outputattr].at(values[0]) + "\";" << std::endl;00419 return;00420 }0042100422 std::cerr << tab + "\t" + attribute_names[outputattr] + " = {" << std::endl

;00423 for (unsigned int i = 0; i < values.size(); i++)00424 {00425 std::cerr << "\"" + domains[outputattr].at(values[i]) + "\" " << std::end

l;00426 if ( i != values.size() - 1 ) std::cerr << " , ";00427 }0042800429 std::cerr << " };" << std::endl;00430 return;00431 }0043200433 unsigned int numvalues = node->children.size();00434 for (unsigned int i = 0; i < numvalues; i++)00435 {00436 std::cerr << tab + "if( " + attribute_names[node->decompositionAttribute] +

" == \"" + domains[node->decompositionAttribute].at(i) + "\")" + "{" << std::endl;

00437 printTree(node->children[i], tab + " ");00438 if (i != numvalues - 1) std::cerr << tab + "} " + "else ";00439 else std::cerr << tab + "}" << std::endl;00440 }00441 };

Here is the call graph for this function:

ID3::printTree ID3::getAllValues VectorIndexOf

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 26: ID3 Algorithm - Reference Manual

20 Class Documentation

Here is the caller graph for this function:

ID3::printTree ID3::createDecisionTree main

5.2.3.11 bool ID3::readData (std::string filename) [inline]

Função para ler a base de dados.

Definition at line 338 of file MyID3Algorithm.cpp.

00339 {00340 /*Objetos para manipulação do arquivo*/00341 std::fstream myfile(filename.c_str());00342 std::string myline;0034300344 /*Verifica se o arquivo pôde ser aberto*/00345 if (!myfile.is_open())00346 {00347 std::cerr << "Unable to open data file: " + filename + "\n" << std::endl;00348 return EXIT_FAILURE;00349 }0035000351 /*Executa a primeira leitura - leitura do cabeçalho da base de testes*/00352 getline(myfile, myline);0035300354 /*Extração das strings de cabeçalho*/00355 StringTokenizer mytokenizer = StringTokenizer(myline, "\t");00356 number_of_attributes = mytokenizer.countTokens();0035700358 if (number_of_attributes <= 1)00359 {00360 std::cerr << "Read line: " + myline << std::endl;00361 std::cerr << "Could not obtain the names of attributes in the line" << std:

:endl;00362 std::cerr << "Expecting at least one input attribute and one output attribu

te" << std::endl;00363 return EXIT_FAILURE;00364 }0036500366 /*Alocando espaço para as listas de valores dos atributos e extraindo rótulos

de cada atributo*/00367 for (int i = 0; i < number_of_attributes; i++)00368 {00369 domains.push_back( StringList() );00370 attribute_names.push_back( mytokenizer.nextToken() );00371 }0037200373 /*Executa leitura das demais linhas da base de dados*/00374 while (!myfile.eof())00375 {00376 /*Extração da linha e atribuição a variável temporária*/00377 getline(myfile, myline);0037800379 /*Caso não encontre nenhum dado então não deve ser feita a quebra da cadeia

*/00380 bool can_tokenize = !(LibraryUtils::StrStartsWith(myline, "//") || (myline

== ""));0038100382 /*Tokenizando a string*/00383 if (can_tokenize)00384 {00385 /*Estabelecendo o token e o número de substrings*/

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 27: ID3 Algorithm - Reference Manual

5.2 ID3 Class Reference 21

00386 mytokenizer = StringTokenizer(myline, "\t");0038700388 /*Criação dos datapoints e nós*/00389 DataPoint point = DataPoint(number_of_attributes);00390 for(int i = 0; i < number_of_attributes; i++)00391 {00392 point.attributes[i] = getSymbolValue(i, mytokenizer.nextToken() );00393 }00394 root->data.push_back(point);00395 }00396 }0039700398 /*Fechando o arquivo*/00399 myfile.close();0040000401 /*Retorno da função*/00402 return true;00403 };

Here is the call graph for this function:

ID3::readData

StringTokenizer::countTokens

ID3::getSymbolValue

StringTokenizer::nextToken

LibraryUtils::StrStartsWith

VectorIndexOf

Here is the caller graph for this function:

ID3::readData main

The documentation for this class was generated from the following file:

• MyID3Algorithm.cpp

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 28: ID3 Algorithm - Reference Manual

22 Class Documentation

5.3 LibraryTime Class Reference

#include <LibraryTime.h>

Public Member Functions

• LibraryTime ()• void Start (void)• void Stop (void)• double Get (void)• void Delay (const int miliseconds)• virtual ∼LibraryTime ()

5.3.1 Detailed Description

Classe que executa verificação de tempo decorrido para realização de determinadas tarefas. Usada parafazer análise de complexidade computacional em relação a quanto tempo um determinado trecho de códigoconsome para ser realizado. O retorno é dado em milisegundos com base no clock da máquina.

Definition at line 19 of file LibraryTime.h.

5.3.2 Constructor & Destructor Documentation

5.3.2.1 LibraryTime::LibraryTime () [inline]

Método construtor da classe.

Definition at line 35 of file LibraryTime.h.

00035 {};

5.3.2.2 virtual LibraryTime::∼LibraryTime () [inline, virtual]

Método destrutor da classe responsável por desalocar quaisquer recursos previamente alocados retornandoos mesmos ao sistema.

Definition at line 66 of file LibraryTime.h.

00066 {};

5.3.3 Member Function Documentation

5.3.3.1 void LibraryTime::Delay (const int miliseconds) [inline]

Método que imprime uma pausa em milisegundos na execução do fluxo do programa a partir do ponto ondeela foi chamada.

Definition at line 59 of file LibraryTime.h.

00060 { clock_t exit_time = clock() + miliseconds; while(clock() <= exit_time); }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 29: ID3 Algorithm - Reference Manual

5.3 LibraryTime Class Reference 23

5.3.3.2 double LibraryTime::Get (void) [inline]

Método responsável por retornar o intervalo em milisegundos decorrido entre as chamadas dos métodoStart() e Stop()

Definition at line 53 of file LibraryTime.h.

00053 { return (double( stop - start )/CLOCKS_PER_SEC); }

Here is the caller graph for this function:

LibraryTime::Get main

5.3.3.3 void LibraryTime::Start (void) [inline]

Método responsável por capturar o tempo ou intervalo inicial de execução de alguma operação.

Definition at line 41 of file LibraryTime.h.

00041 { start = clock(); }

Here is the caller graph for this function:

LibraryTime::Start main

5.3.3.4 void LibraryTime::Stop (void) [inline]

Método responsável por capturar o tempo ou intervalo de interrupção de execução de alguma operação.

Definition at line 47 of file LibraryTime.h.

00047 { stop = clock(); }

Here is the caller graph for this function:

LibraryTime::Stop main

The documentation for this class was generated from the following file:

• LibraryTime.h

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 30: ID3 Algorithm - Reference Manual

24 Class Documentation

5.4 StringTokenizer Class Reference

#include <StringTokenizer.h>

Public Member Functions

• StringTokenizer (const std::string &_str, const std::string &_delim)• ∼StringTokenizer ()• int countTokens ()• bool hasMoreTokens ()• std::string nextToken ()• int nextIntToken ()• double nextFloatToken ()• std::string nextToken (const std::string &delim)• std::string remainingString ()• std::string filterNextToken (const std::string &filterStr)

5.4.1 Detailed Description

Definition at line 18 of file StringTokenizer.h.

5.4.2 Constructor & Destructor Documentation

5.4.2.1 StringTokenizer::StringTokenizer (const std::string & _str, const std::string & _delim)

Definition at line 9 of file StringTokenizer.cpp.

00010 {00011 if ((_str.length() == 0) || (_delim.length() == 0)) return;0001200013 token_str = _str;00014 delim = _delim;0001500016 /*00017 Remove sequential delimiter00018 */00019 unsigned int curr_pos = 0;0002000021 while(true)00022 {00023 if ((curr_pos = token_str.find(delim,curr_pos)) != std::string::npos)00024 {00025 curr_pos += delim.length();0002600027 while(token_str.find(delim,curr_pos) == curr_pos)00028 {00029 token_str.erase(curr_pos,delim.length());00030 }00031 }00032 else00033 break;00034 }0003500036 /*00037 Trim leading delimiter00038 */

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 31: ID3 Algorithm - Reference Manual

5.4 StringTokenizer Class Reference 25

00039 if (token_str.find(delim,0) == 0)00040 {00041 token_str.erase(0,delim.length());00042 }0004300044 /*00045 Trim ending delimiter00046 */00047 curr_pos = 0;00048 if ((curr_pos = token_str.rfind(delim)) != std::string::npos)00049 {00050 if (curr_pos != (token_str.length() - delim.length())) return;00051 token_str.erase(token_str.length() - delim.length(),delim.length());00052 }00053 }

5.4.2.2 StringTokenizer::∼StringTokenizer () [inline]

Definition at line 22 of file StringTokenizer.h.

00022 {};

5.4.3 Member Function Documentation

5.4.3.1 int StringTokenizer::countTokens ()

Definition at line 55 of file StringTokenizer.cpp.

00056 {00057 unsigned int prev_pos = 0;00058 int num_tokens = 0;0005900060 if (token_str.length() > 0)00061 {00062 num_tokens = 0;0006300064 unsigned int curr_pos = 0;00065 while(true)00066 {00067 if ((curr_pos = token_str.find(delim,curr_pos)) != std::string::npos)00068 {00069 num_tokens++;00070 prev_pos = curr_pos;00071 curr_pos += delim.length();00072 }00073 else00074 break;00075 }00076 return ++num_tokens;00077 }00078 else00079 {00080 return 0;00081 }00082 }

Here is the caller graph for this function:

StringTokenizer::countTokens ID3::readData main

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 32: ID3 Algorithm - Reference Manual

26 Class Documentation

5.4.3.2 std::string StringTokenizer::filterNextToken (const std::string & filterStr)

Definition at line 147 of file StringTokenizer.cpp.

00148 {00149 std::string tmp_str = nextToken();00150 unsigned int currentPos = 0;0015100152 while((currentPos = tmp_str.find(filterStr,currentPos)) != std::string::npos)00153 {00154 tmp_str.erase(currentPos,filterStr.length());00155 }0015600157 return tmp_str;00158 }

Here is the call graph for this function:

StringTokenizer::filterNextToken StringTokenizer::nextToken

5.4.3.3 bool StringTokenizer::hasMoreTokens ()

Definition at line 84 of file StringTokenizer.cpp.

00085 {00086 return (token_str.length() > 0);00087 }

5.4.3.4 double StringTokenizer::nextFloatToken ()

Definition at line 115 of file StringTokenizer.cpp.

00116 {00117 return atof(nextToken().c_str());00118 }

Here is the call graph for this function:

StringTokenizer::nextFloatToken StringTokenizer::nextToken

5.4.3.5 int StringTokenizer::nextIntToken ()

Definition at line 110 of file StringTokenizer.cpp.

00111 {00112 return atoi(nextToken().c_str());00113 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 33: ID3 Algorithm - Reference Manual

5.4 StringTokenizer Class Reference 27

Here is the call graph for this function:

StringTokenizer::nextIntToken StringTokenizer::nextToken

5.4.3.6 std::string StringTokenizer::nextToken (const std::string & delim)

Definition at line 120 of file StringTokenizer.cpp.

00121 {00122 if (token_str.length() == 0)00123 return "";0012400125 std::string tmp_str = "";00126 unsigned int pos = token_str.find(delimiter,0);0012700128 if (pos != std::string::npos)00129 {00130 tmp_str = token_str.substr(0,pos);00131 token_str = token_str.substr(pos + delimiter.length(),token_str.length() -

pos);00132 }00133 else00134 {00135 tmp_str = token_str.substr(0,token_str.length());00136 token_str = "";00137 }0013800139 return tmp_str;00140 }

5.4.3.7 std::string StringTokenizer::nextToken ()

Definition at line 89 of file StringTokenizer.cpp.

00090 {00091 if (token_str.length() == 0)00092 return "";0009300094 std::string tmp_str = "";00095 unsigned int pos = token_str.find(delim,0);0009600097 if (pos != std::string::npos)00098 {00099 tmp_str = token_str.substr(0,pos);00100 token_str = token_str.substr(pos+delim.length(),token_str.length()-pos);00101 }00102 else00103 {00104 tmp_str = token_str.substr(0,token_str.length());00105 token_str = "";00106 }00107 return tmp_str;00108 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 34: ID3 Algorithm - Reference Manual

28 Class Documentation

Here is the caller graph for this function:

StringTokenizer::nextToken

StringTokenizer::filterNextToken

StringTokenizer::nextFloatToken

StringTokenizer::nextIntToken

ID3::readData main

5.4.3.8 std::string StringTokenizer::remainingString ()

Definition at line 142 of file StringTokenizer.cpp.

00143 {00144 return token_str;00145 }

The documentation for this class was generated from the following files:

• StringTokenizer.h• StringTokenizer.cpp

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 35: ID3 Algorithm - Reference Manual

Chapter 6

File Documentation

6.1 LibraryTime.cxx File Reference

#include "LibraryTime.h"

#include <ctime>

Include dependency graph for LibraryTime.cxx:

LibraryTime.cxx

ctime

This graph shows which files directly or indirectly include this file:

LibraryTime.cxx

Page 36: ID3 Algorithm - Reference Manual

30 File Documentation

6.2 LibraryTime.cxx

00001 /*00002 * TimeInterval.cpp00003 *00004 * Created on: 26/10/200900005 * Author: Michel Alves dos Santos00006 */0000700008 #include "LibraryTime.h"0000900010

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 37: ID3 Algorithm - Reference Manual

6.3 LibraryTime.h File Reference 31

6.3 LibraryTime.h File Reference

#include <ctime>

Include dependency graph for LibraryTime.h:

LibraryTime.h

ctime

This graph shows which files directly or indirectly include this file:

LibraryTime.h

MyID3Algorithm.cpp

Classes

• class LibraryTime

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 38: ID3 Algorithm - Reference Manual

32 File Documentation

6.4 LibraryTime.h

00001 /*00002 * TimeInterval.h00003 *00004 * Created on: 26/10/200900005 * Author: Michel Alves dos Santos00006 */0000700008 #ifndef LIBRARYTIME_H_00009 #define LIBRARYTIME_H_0001000011 #include <ctime>0001200019 class LibraryTime00020 {00024 clock_t start;0002500029 clock_t stop;0003000031 public:00035 LibraryTime() {};0003600041 void Start(void) { start = clock(); }0004200047 void Stop(void) { stop = clock(); }0004800053 double Get(void) { return (double( stop - start )/CLOCKS_PER_SEC); }0005400059 void Delay(const int miliseconds)00060 { clock_t exit_time = clock() + miliseconds; while(clock() <= exit_time); }0006100066 virtual ~LibraryTime() {};00067 };0006800069 #endif /* LIBRARYTIME_H_ */

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 39: ID3 Algorithm - Reference Manual

6.5 LibraryUtils.h File Reference 33

6.5 LibraryUtils.h File Reference

#include <cstdio>

#include <vector>

#include <iomanip>

#include <sstream>

#include <cstdlib>

#include <iostream>

#include <exception>

#include <algorithm>

Include dependency graph for LibraryUtils.h:

LibraryUtils.h

cstdio vector iomanip sstream cstdlib iostream exception algorithm

Classes

• class LibraryUtils::ConversionError

Namespaces

• namespace LibraryUtils

Functions

• template<typename T >

std::string LibraryUtils::DoubleToStr (T const &myvalue, unsigned int precision)• bool LibraryUtils::IsNumeric (const std::string &str)• long double LibraryUtils::StrToFloat (const std::string &str)• string LibraryUtils::IntToStr (int numero)• long int LibraryUtils::StrToInt (const std::string &str)• string LibraryUtils::TrimString (const std::string str)• int LibraryUtils::SignalNumber (long double value)• int LibraryUtils::StrIndexOf (const std::string &str, const std::string &piece)• bool LibraryUtils::StrStartsWith (const std::string &str, const std::string &piece)

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 40: ID3 Algorithm - Reference Manual

34 File Documentation

6.6 LibraryUtils.h

00001 /*00002 * LibraryUtils.h00003 *00004 * Created on: 05/01/200900005 * Author: Michel Alves dos Santos00006 */0000700008 #ifndef LIBRARYUTILS_H_00009 #define LIBRARYUTILS_H_0001000011 //Area de definicao de cabecalhos utilizados.00012 #include <cstdio>00013 #include <vector>00014 #include <iomanip>00015 #include <sstream>00016 #include <cstdlib>00017 #include <iostream>00018 #include <exception>00019 #include <algorithm>00020 using namespace std;0002100022 //Definicao de constantes e macros utilizadas00023 //const int MAX_LENGTH_CHAR_ARRAY = 255;0002400025 //Definicao de tipos usados no projeto00026 //typedef enum{False, True} Boolean;00027 //typedef float real;00028 //typedef char MyCharArrayString[MAX_LENGTH_CHAR_ARRAY];0002900030 //-------------------------------------------------------------//00031 //Implementacao dos prototipos das funcoes //00032 //-------------------------------------------------------------//00033 namespace LibraryUtils00034 {0003500036 //Classe que trata erros relativos a conversão de tipo00037 class ConversionError : public exception00038 {00039 public :00040 const char* what() { return "Erro de conversão !"; };00041 };0004200043 //Funcao para conversao de numeros reais [ponto flutuante] para string.00044 //@numero : Número que deve ser convertido00045 //@digitos : Quantidade de dígitos que deve ser convertida.00046 //string FloatToStr(double numero, int digitos)00047 //{00048 // MyCharArrayString str;00049 // gcvt(numero, (digitos > MAX_LENGTH_CHAR_ARRAY)?(MAX_LENGTH_CHAR_ARRAY):(digit

os) , str);00050 // return string(str);00051 //}0005200053 //Função pra conversão de números reais de precisão dupla para string00054 //@myvalue : Número que deve ser convertido00055 //@precision : Quantidade de dígitos que devem ser utilizados00056 template <typename T> std::string DoubleToStr(T const& myvalue, unsigned int prec

ision)00057 {00058 std::ostringstream oss;00059 oss << std::setprecision(precision) << myvalue;00060 return oss.str();00061 }0006200063 //Função que verifica se determinado valor realmente é numérico

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 41: ID3 Algorithm - Reference Manual

6.6 LibraryUtils.h 35

00064 //@str : String que deve ser verificada00065 bool IsNumeric(const std::string& str)00066 {00067 //Declaração das variáveis de conversão00068 std::istringstream iss(str);00069 long double d;0007000071 //Movendo o conteudo da string para a variavel do tipo double00072 iss >> d;0007300074 //Fazendo verificações de conversão00075 if ( !(iss && (iss >> std::ws).eof())) return false;0007600077 //Caso haja falha na conversão uma exceção é lançada caso não o valor é retorna

do00078 return true;00079 }0008000081 //Funcao para conversão de strings em numeros de ponto flutuante00082 //@str : String que deve ser convertida00083 long double StrToFloat(const std::string& str)00084 {00085 //Declaração das variáveis de conversão00086 std::istringstream iss(str);00087 double d;0008800089 //Movendo o conteudo da string para a variavel do tipo double00090 iss >> d;0009100092 //Fazendo verificações de conversão00093 if ( !(iss && (iss >> std::ws).eof())) throw ConversionError();0009400095 //Caso haja falha na conversão uma exceção é lançada caso não o valor é retorna

do00096 return d;00097 }0009800099 //Funcao para conversão de numeros inteiros para string.00100 //@numero : Número que deve ser convertido00101 string IntToStr(int numero)00102 {00103 std::ostringstream osbuffer;00104 osbuffer << numero;00105 return osbuffer.str();00106 }0010700108 //Funcao para conversão de strings em numeros inteiros00109 //@str : String que deve ser convertida00110 long int StrToInt(const std::string& str)00111 {00112 //Declaração das variaveis de conversão00113 std::istringstream iss(str);00114 int i;0011500116 //Movendo o conteudo do stringstream para a variavel00117 iss >> i;0011800119 //Fazendo verificações de conversão00120 if ( !(iss && (iss >> std::ws).eof())) throw ConversionError();0012100122 //Caso haja falha na conversão uma exceção é lançada caso não o valor é retorna

do00123 return i;00124 }0012500126 //Função que remove espaços em branco da direira e da esquerda de uma string00127 //@str : String da qual devem ser retirados os espaços finais e iniciais

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 42: ID3 Algorithm - Reference Manual

36 File Documentation

00128 string TrimString(const std::string str)00129 {00130 string result = str;00131 std::remove(result.begin(),result.end(),’ ’);00132 return result;00133 }0013400135 //Função que retorna o sinal de um determinado número fornecido00136 int SignalNumber(long double value)00137 {00138 return (value >= 0)?(1):(-1);00139 }0014000144 int StrIndexOf(const std::string &str, const std::string &piece)00145 {00146 std::string::size_type loc = str.find(piece, 0);00147 return (loc != std::string::npos)?(loc):(-1);00148 }0014900154 bool StrStartsWith(const std::string &str, const std::string &piece)00155 {00156 return str.find(piece) == 0;00157 }0015800159 };00160 #endif /* LIBRARYUTILS_H_ */

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 43: ID3 Algorithm - Reference Manual

6.7 MyID3Algorithm.cpp File Reference 37

6.7 MyID3Algorithm.cpp File Reference

#include <cmath>

#include <iomanip>

#include <vector>

#include <fstream>

#include <cstdlib>

#include <iostream>

#include <exception>

#include "LibraryTime.h"

#include "LibraryUtils.h"

#include <cstdio>

#include <sstream>

#include <algorithm>

#include <stdio.h>

#include <stdlib.h>

#include <string>

Include dependency graph for MyID3Algorithm.cpp:

MyID3Algorithm.cpp

cmath iomanip vector fstream cstdlib iostream exception LibraryTime.h cstdio sstream algorithm stdio.h stdlib.h string

ctime

This graph shows which files directly or indirectly include this file:

MyID3Algorithm.cpp

Classes

• class ID3• class ID3::DataPoint• class ID3::TreeNode

Typedefs

• typedef std::vector< std::string > StringList• typedef std::vector< StringList > StringTable• typedef std::vector< int > IntegerList

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 44: ID3 Algorithm - Reference Manual

38 File Documentation

Functions

• int VectorIndexOf (const StringList v, const std::string element)• int main (int argc, char ∗argv[ ])

6.7.1 Typedef Documentation

6.7.1.1 typedef std::vector<int> IntegerList

Definição do tipo ’lista de inteiros’. Com esse tipo podemos manter uma lista de números inteiros atravésde uma definição mais enxuta.

Definition at line 38 of file MyID3Algorithm.cpp.

6.7.1.2 typedef std::vector<std::string> StringList

Definição do tipo ’lista de cadeias de caracteres’. Com esse tipo é possível manter listas de cadeias naforma de um vetor.

Definition at line 26 of file MyID3Algorithm.cpp.

6.7.1.3 typedef std::vector<StringList> StringTable

Definição do tipo ’lista de listas de cadeias de caracteres’. Com esse tipo podemos manter uma tabela decadeias de caracteres.

Definition at line 32 of file MyID3Algorithm.cpp.

6.7.2 Function Documentation

6.7.2.1 int main (int argc, char ∗ argv[ ])

Definição da função principal do programa.

Definition at line 481 of file MyID3Algorithm.cpp.

00482 {00483 //Resgata o número de argumentos.00484 int number_of_arguments = argc;00485 std::string str_file_path;0048600487 //Testando o número de argumentos00488 if (number_of_arguments < 2 )00489 {00490 std::cerr << std::endl << "[Você precisa especificar a base de testes!]" << s

td::endl << std::endl;00491 return EXIT_FAILURE;00492 }00493 else00494 {00495 str_file_path = argv[1];00496 }0049700498 //Declaração de um objeto do tipo LibraryTime00499 LibraryTime t;0050000501 //Inicio da captura de tempo

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 45: ID3 Algorithm - Reference Manual

6.7 MyID3Algorithm.cpp File Reference 39

00502 t.Start();0050300504 //Declarando objeto do tipo ID300505 ID3 myid3 = ID3();0050600507 //Verificando o status de leitura00508 if (!myid3.readData( str_file_path )) return EXIT_FAILURE;0050900510 //Executa a criação da árvore00511 myid3.createDecisionTree();0051200513 std::cerr << std::endl << "[Dataset]" << std::endl;00514 myid3.printDomains(); std::cerr << std::endl;0051500516 //Término da captura de tempo00517 t.Stop();0051800519 //Tempo consumido para execução do programa00520 std::cout << std::endl << "Tempo consumido: "<< std::setprecision(5) << t.Get()

<< std::endl;00521 return EXIT_SUCCESS;00522 }

Here is the call graph for this function:

main

ID3::createDecisionTree

LibraryTime::Get

ID3::printDomains

ID3::readData

LibraryTime::Start

LibraryTime::Stop

ID3::decomposeNode

ID3::printTree

ID3::alreadyUsedToDecompose

ID3::calculateEntropy

ID3::getSubset

ID3::getAllValues

VectorIndexOf

StringTokenizer::countTokens

ID3::getSymbolValue

StringTokenizer::nextToken

LibraryUtils::StrStartsWith

6.7.2.2 int VectorIndexOf (const StringList v, const std::string element)

Função que verifica se um determinado elemento pertence a uma lista e qual é a sua posição. Caso oelemento não seja encontrado a função retorna -1.

Definition at line 44 of file MyID3Algorithm.cpp.

00045 {00046 int index = -1;00047 for(unsigned int i = 0; i < v.size(); i++) { if(v.at(i) == element){ index = i;

break;} }00048 return index;00049 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 46: ID3 Algorithm - Reference Manual

40 File Documentation

Here is the caller graph for this function:

VectorIndexOf

ID3::getAllValues

ID3::getSymbolValue

ID3::printTree ID3::createDecisionTree

main

ID3::readData

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 47: ID3 Algorithm - Reference Manual

6.8 MyID3Algorithm.cpp 41

6.8 MyID3Algorithm.cpp

00001 //============================================================================00002 // Name : MyID3Algorithm00003 // Author : Michel Alves dos Santos00004 // Version : 1.0 Beta00005 // Description : Algoritmo de geração de árvores de decisão baseado no algoritmo00006 // original de Ross Quilan (1986)00007 //============================================================================0000800009 #include <cmath>00010 #include <iomanip>00011 #include <vector>00012 #include <fstream>00013 #include <cstdlib>00014 #include <iostream>00015 #include <exception>00016 #include "LibraryTime.h"00017 #include "LibraryUtils.h"00018 #include "StringTokenizer.h"0001900020 using namespace std;0002100026 typedef std::vector<std::string> StringList;0002700032 typedef std::vector<StringList> StringTable;0003300038 typedef std::vector<int> IntegerList;0003900044 int VectorIndexOf(const StringList v, const std::string element)00045 {00046 int index = -1;00047 for(unsigned int i = 0; i < v.size(); i++) { if(v.at(i) == element){ index = i;

break;} }00048 return index;00049 }0005000056 class ID300057 {00061 int number_of_attributes;0006200066 StringList attribute_names;0006700076 StringTable domains;0007700081 class DataPoint00082 {00083 public:00087 IntegerList attributes;0008800092 DataPoint(int number_of_attributes)00093 {00094 //attributes.reserve(number_of_attributes);00095 for(int i = 0; i < number_of_attributes; i++) attributes.push_back(0);00096 };00097 };0009800102 class TreeNode00103 {00104 public:00108 double entropy;0010900113 std::vector<DataPoint> data;0011400118 int decompositionAttribute;0011900123 int decompositionValue;

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 48: ID3 Algorithm - Reference Manual

42 File Documentation

0012400128 std::vector< TreeNode* > children;0012900133 TreeNode* parent;0013400138 TreeNode()00139 {00140 }00141 };0014200146 TreeNode* root;0014700148 public:00152 ID3()00153 {00154 root = new TreeNode();00155 };0015600161 int getSymbolValue(int attribute, std::string symbol)00162 {00163 int index = VectorIndexOf(domains.at(attribute), symbol);00164 if (index < 0)00165 {00166 domains[attribute].push_back(symbol);00167 return domains[attribute].size() - 1;00168 }00169 return index;00170 };0017100175 IntegerList getAllValues(std::vector<DataPoint> data, int attribute)00176 {00177 StringList values;00178 int num = data.size();0017900180 for (int i = 0; i < num; i++)00181 {00182 DataPoint point = data.at(i);00183 std::string symbol = domains[attribute].at( point.attributes[attribute] );00184 int index = VectorIndexOf(values, symbol);00185 if (index < 0) { values.push_back(symbol); }00186 }0018700188 int array[ values.size() ];0018900190 for (unsigned int i = 0; i < values.size(); i++)00191 {00192 std::string symbol = values.at(i);00193 array[i] = VectorIndexOf(domains[attribute], symbol);00194 }0019500196 IntegerList l;00197 for (unsigned int i = 0; i < values.size(); i++) l.push_back( array[i] );00198 return l;00199 }0020000204 std::vector<DataPoint> getSubset(std::vector<DataPoint> data, int attribute, in

t value)00205 {00206 std::vector<DataPoint> subset; //= new Vector();00207 int num = data.size();0020800209 for (int i = 0; i < num; i++)00210 {00211 DataPoint point = data.at(i);00212 if (point.attributes[attribute] == value) subset.push_back(point);00213 }00214 return subset;

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 49: ID3 Algorithm - Reference Manual

6.8 MyID3Algorithm.cpp 43

00215 };0021600220 double calculateEntropy(const std::vector<DataPoint> &data)00221 {00222 int numdata = data.size();00223 if (numdata == 0) return 0;0022400225 int attribute = number_of_attributes - 1;00226 int numvalues = domains[attribute].size();0022700228 double sum = 0;0022900230 for (int i = 0; i < numvalues; i++)00231 {00232 int count = 0;00233 for (int j = 0; j < numdata; j++)00234 {00235 DataPoint point = data.at(j);00236 if (point.attributes[attribute] == i) count++;00237 }0023800239 double probability = 1.0*count/numdata;00240 if (count > 0) sum += -probability*log2(probability);00241 }0024200243 return sum;00244 };0024500251 bool alreadyUsedToDecompose(TreeNode* node, int attribute)00252 {00253 if (node->children.size() != 0 )00254 {00255 if (node->decompositionAttribute == attribute ) return true;00256 }0025700258 if (node->parent == NULL) return false;00259 return alreadyUsedToDecompose(node->parent, attribute);00260 }0026100265 void decomposeNode(TreeNode* node)00266 {00267 double bestEntropy = 0;00268 bool selected = false;00269 int selectedAttribute = 0;0027000271 int numdata = node->data.size();00272 int numinputattributes = number_of_attributes - 1;0027300274 node->entropy = calculateEntropy(node->data);00275 if (node->entropy == 0) return;0027600280 for (int i = 0; i < numinputattributes; i++)00281 {00282 int numvalues = domains[i].size();00283 if ( alreadyUsedToDecompose(node, i) ) continue;0028400285 // Use a variável seguinte para armazenar a entropia para o nó de teste cri

ado com o atributo i00286 double averageentropy = 0;00287 for (int j = 0; j < numvalues; j++)00288 {00289 std::vector<DataPoint> subset = getSubset(node->data, i, j);00290 if (subset.size() == 0) continue;00291 double subentropy = calculateEntropy(subset);00292 averageentropy += subentropy * subset.size();00293 }00294

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 50: ID3 Algorithm - Reference Manual

44 File Documentation

00295 averageentropy = (double)averageentropy/numdata;00296 if (selected == false)00297 {00298 selected = true;00299 bestEntropy = averageentropy;00300 selectedAttribute = i;00301 }00302 else00303 {00304 if (averageentropy < bestEntropy)00305 {00306 selected = true;00307 bestEntropy = averageentropy;00308 selectedAttribute = i;00309 }00310 }0031100312 }0031300314 if (selected == false) return;0031500316 // Agora divide o conjunto de dados usando o atributo selecionado00317 int numvalues = domains[selectedAttribute].size();00318 node->decompositionAttribute = selectedAttribute;0031900320 for (int j = 0; j < numvalues; j++)00321 {00322 node->children.push_back( new TreeNode() );00323 node->children[j]->parent = node;00324 node->children[j]->data = getSubset(node->data, selectedAttribute, j);00325 node->children[j]->decompositionValue = j;00326 }0032700328 // Recursivamente divide nós filhos00329 for (int j = 0; j < numvalues; j++)00330 {00331 decomposeNode(node->children[j]);00332 }00333 };0033400338 bool readData(std::string filename)00339 {00340 /*Objetos para manipulação do arquivo*/00341 std::fstream myfile(filename.c_str());00342 std::string myline;0034300344 /*Verifica se o arquivo pôde ser aberto*/00345 if (!myfile.is_open())00346 {00347 std::cerr << "Unable to open data file: " + filename + "\n" << std::endl;00348 return EXIT_FAILURE;00349 }0035000351 /*Executa a primeira leitura - leitura do cabeçalho da base de testes*/00352 getline(myfile, myline);0035300354 /*Extração das strings de cabeçalho*/00355 StringTokenizer mytokenizer = StringTokenizer(myline, "\t");00356 number_of_attributes = mytokenizer.countTokens();0035700358 if (number_of_attributes <= 1)00359 {00360 std::cerr << "Read line: " + myline << std::endl;00361 std::cerr << "Could not obtain the names of attributes in the line" << std:

:endl;00362 std::cerr << "Expecting at least one input attribute and one output attribu

te" << std::endl;

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 51: ID3 Algorithm - Reference Manual

6.8 MyID3Algorithm.cpp 45

00363 return EXIT_FAILURE;00364 }0036500366 /*Alocando espaço para as listas de valores dos atributos e extraindo rótulos

de cada atributo*/00367 for (int i = 0; i < number_of_attributes; i++)00368 {00369 domains.push_back( StringList() );00370 attribute_names.push_back( mytokenizer.nextToken() );00371 }0037200373 /*Executa leitura das demais linhas da base de dados*/00374 while (!myfile.eof())00375 {00376 /*Extração da linha e atribuição a variável temporária*/00377 getline(myfile, myline);0037800379 /*Caso não encontre nenhum dado então não deve ser feita a quebra da cadeia

*/00380 bool can_tokenize = !(LibraryUtils::StrStartsWith(myline, "//") || (myline

== ""));0038100382 /*Tokenizando a string*/00383 if (can_tokenize)00384 {00385 /*Estabelecendo o token e o número de substrings*/00386 mytokenizer = StringTokenizer(myline, "\t");0038700388 /*Criação dos datapoints e nós*/00389 DataPoint point = DataPoint(number_of_attributes);00390 for(int i = 0; i < number_of_attributes; i++)00391 {00392 point.attributes[i] = getSymbolValue(i, mytokenizer.nextToken() );00393 }00394 root->data.push_back(point);00395 }00396 }0039700398 /*Fechando o arquivo*/00399 myfile.close();0040000401 /*Retorno da função*/00402 return true;00403 };0040400408 void printTree(TreeNode* node, std::string tab)00409 {00410 int outputattr = number_of_attributes - 1;0041100412 if (node->children.size() == 0)00413 {00414 IntegerList values = getAllValues(node->data, outputattr);0041500416 if (values.size() == 1)00417 {00418 std::cerr << tab + " " + attribute_names[outputattr] + " = \"" + domains[

outputattr].at(values[0]) + "\";" << std::endl;00419 return;00420 }0042100422 std::cerr << tab + "\t" + attribute_names[outputattr] + " = {" << std::endl

;00423 for (unsigned int i = 0; i < values.size(); i++)00424 {00425 std::cerr << "\"" + domains[outputattr].at(values[i]) + "\" " << std::end

l;00426 if ( i != values.size() - 1 ) std::cerr << " , ";

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 52: ID3 Algorithm - Reference Manual

46 File Documentation

00427 }0042800429 std::cerr << " };" << std::endl;00430 return;00431 }0043200433 unsigned int numvalues = node->children.size();00434 for (unsigned int i = 0; i < numvalues; i++)00435 {00436 std::cerr << tab + "if( " + attribute_names[node->decompositionAttribute] +

" == \"" + domains[node->decompositionAttribute].at(i) + "\")" + "{" << std::endl;

00437 printTree(node->children[i], tab + " ");00438 if (i != numvalues - 1) std::cerr << tab + "} " + "else ";00439 else std::cerr << tab + "}" << std::endl;00440 }00441 };0044200446 void createDecisionTree()00447 {00448 decomposeNode(root);00449 printTree(root, "");00450 };0045100455 void printMyLabels()00456 {00457 for(unsigned int i = 0; i < attribute_names.size(); i++)00458 {00459 std::cerr << "[" << attribute_names.at(i) << "]\t";00460 }00461 std::cerr << std::endl;00462 };0046300467 void printDomains()00468 {00469 for(unsigned int i = 0; i < domains.size(); i++)00470 {00471 std::cerr << "[" << attribute_names.at(i) << "]\t";00472 for(unsigned int j = 0; j < domains[i].size(); j++){ std::cerr << "[" << (d

omains[i]).at(j) << "]\t"; }00473 std::cerr << std::endl;00474 }00475 };00476 };0047700481 int main(int argc, char* argv[])00482 {00483 //Resgata o número de argumentos.00484 int number_of_arguments = argc;00485 std::string str_file_path;0048600487 //Testando o número de argumentos00488 if (number_of_arguments < 2 )00489 {00490 std::cerr << std::endl << "[Você precisa especificar a base de testes!]" << s

td::endl << std::endl;00491 return EXIT_FAILURE;00492 }00493 else00494 {00495 str_file_path = argv[1];00496 }0049700498 //Declaração de um objeto do tipo LibraryTime00499 LibraryTime t;0050000501 //Inicio da captura de tempo

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 53: ID3 Algorithm - Reference Manual

6.8 MyID3Algorithm.cpp 47

00502 t.Start();0050300504 //Declarando objeto do tipo ID300505 ID3 myid3 = ID3();0050600507 //Verificando o status de leitura00508 if (!myid3.readData( str_file_path )) return EXIT_FAILURE;0050900510 //Executa a criação da árvore00511 myid3.createDecisionTree();0051200513 std::cerr << std::endl << "[Dataset]" << std::endl;00514 myid3.printDomains(); std::cerr << std::endl;0051500516 //Término da captura de tempo00517 t.Stop();0051800519 //Tempo consumido para execução do programa00520 std::cout << std::endl << "Tempo consumido: "<< std::setprecision(5) << t.Get()

<< std::endl;00521 return EXIT_SUCCESS;00522 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 54: ID3 Algorithm - Reference Manual

48 File Documentation

6.9 StringTokenizer.cpp File Reference

#include "StringTokenizer.h"

Include dependency graph for StringTokenizer.cpp:

StringTokenizer.cpp

StringTokenizer.h

stdio.h stdlib.h iostream string

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 55: ID3 Algorithm - Reference Manual

6.10 StringTokenizer.cpp 49

6.10 StringTokenizer.cpp

00001 /*00002 ***********************************************************************00003 * Note: This library has been deprecated in favour of the C++ String *00004 ***********************************************************************00005 */0000600007 #include "StringTokenizer.h"0000800009 StringTokenizer::StringTokenizer(const std::string& _str, const std::string& _del

im)00010 {00011 if ((_str.length() == 0) || (_delim.length() == 0)) return;0001200013 token_str = _str;00014 delim = _delim;0001500016 /*00017 Remove sequential delimiter00018 */00019 unsigned int curr_pos = 0;0002000021 while(true)00022 {00023 if ((curr_pos = token_str.find(delim,curr_pos)) != std::string::npos)00024 {00025 curr_pos += delim.length();0002600027 while(token_str.find(delim,curr_pos) == curr_pos)00028 {00029 token_str.erase(curr_pos,delim.length());00030 }00031 }00032 else00033 break;00034 }0003500036 /*00037 Trim leading delimiter00038 */00039 if (token_str.find(delim,0) == 0)00040 {00041 token_str.erase(0,delim.length());00042 }0004300044 /*00045 Trim ending delimiter00046 */00047 curr_pos = 0;00048 if ((curr_pos = token_str.rfind(delim)) != std::string::npos)00049 {00050 if (curr_pos != (token_str.length() - delim.length())) return;00051 token_str.erase(token_str.length() - delim.length(),delim.length());00052 }00053 }0005400055 int StringTokenizer::countTokens()00056 {00057 unsigned int prev_pos = 0;00058 int num_tokens = 0;0005900060 if (token_str.length() > 0)00061 {00062 num_tokens = 0;0006300064 unsigned int curr_pos = 0;

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 56: ID3 Algorithm - Reference Manual

50 File Documentation

00065 while(true)00066 {00067 if ((curr_pos = token_str.find(delim,curr_pos)) != std::string::npos)00068 {00069 num_tokens++;00070 prev_pos = curr_pos;00071 curr_pos += delim.length();00072 }00073 else00074 break;00075 }00076 return ++num_tokens;00077 }00078 else00079 {00080 return 0;00081 }00082 }0008300084 bool StringTokenizer::hasMoreTokens()00085 {00086 return (token_str.length() > 0);00087 }0008800089 std::string StringTokenizer::nextToken()00090 {00091 if (token_str.length() == 0)00092 return "";0009300094 std::string tmp_str = "";00095 unsigned int pos = token_str.find(delim,0);0009600097 if (pos != std::string::npos)00098 {00099 tmp_str = token_str.substr(0,pos);00100 token_str = token_str.substr(pos+delim.length(),token_str.length()-pos);00101 }00102 else00103 {00104 tmp_str = token_str.substr(0,token_str.length());00105 token_str = "";00106 }00107 return tmp_str;00108 }0010900110 int StringTokenizer::nextIntToken()00111 {00112 return atoi(nextToken().c_str());00113 }0011400115 double StringTokenizer::nextFloatToken()00116 {00117 return atof(nextToken().c_str());00118 }0011900120 std::string StringTokenizer::nextToken(const std::string& delimiter)00121 {00122 if (token_str.length() == 0)00123 return "";0012400125 std::string tmp_str = "";00126 unsigned int pos = token_str.find(delimiter,0);0012700128 if (pos != std::string::npos)00129 {00130 tmp_str = token_str.substr(0,pos);00131 token_str = token_str.substr(pos + delimiter.length(),token_str.length() -

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 57: ID3 Algorithm - Reference Manual

6.10 StringTokenizer.cpp 51

pos);00132 }00133 else00134 {00135 tmp_str = token_str.substr(0,token_str.length());00136 token_str = "";00137 }0013800139 return tmp_str;00140 }0014100142 std::string StringTokenizer::remainingString()00143 {00144 return token_str;00145 }0014600147 std::string StringTokenizer::filterNextToken(const std::string& filterStr)00148 {00149 std::string tmp_str = nextToken();00150 unsigned int currentPos = 0;0015100152 while((currentPos = tmp_str.find(filterStr,currentPos)) != std::string::npos)00153 {00154 tmp_str.erase(currentPos,filterStr.length());00155 }0015600157 return tmp_str;00158 }

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 58: ID3 Algorithm - Reference Manual

52 File Documentation

6.11 StringTokenizer.h File Reference

#include <stdio.h>

#include <stdlib.h>

#include <iostream>

#include <string>

Include dependency graph for StringTokenizer.h:

StringTokenizer.h

stdio.h stdlib.h iostream string

This graph shows which files directly or indirectly include this file:

StringTokenizer.h

StringTokenizer.cpp

Classes

• class StringTokenizer

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 59: ID3 Algorithm - Reference Manual

6.12 StringTokenizer.h 53

6.12 StringTokenizer.h

00001 /*00002 ***********************************************************************00003 * Class: StringTokenizer *00004 ***********************************************************************00005 */000060000700008 #ifndef INCLUDE_STRINGTOKENIZER_H00009 #define INCLUDE_STRINGTOKENIZER_H000100001100012 #include <stdio.h>00013 #include <stdlib.h>00014 #include <iostream>00015 #include <string>000160001700018 class StringTokenizer00019 {00020 public:00021 StringTokenizer(const std::string& _str, const std::string& _delim);00022 ~StringTokenizer(){};0002300024 int countTokens();00025 bool hasMoreTokens();00026 std::string nextToken();00027 int nextIntToken();00028 double nextFloatToken();00029 std::string nextToken(const std::string& delim);00030 std::string remainingString();00031 std::string filterNextToken(const std::string& filterStr);0003200033 private:0003400035 std::string token_str;00036 std::string delim;00037 };0003800039 #endif00040

Generated on Fri Dec 16 16:50:04 2011 by Doxygen

Page 60: ID3 Algorithm - Reference Manual

Index

∼LibraryTimeLibraryTime, 22

∼StringTokenizerStringTokenizer, 25

alreadyUsedToDecomposeID3, 13

calculateEntropyID3, 14

countTokensStringTokenizer, 25

createDecisionTreeID3, 14

decomposeNodeID3, 15

DelayLibraryTime, 22

DoubleToStrLibraryUtils, 7

filterNextTokenStringTokenizer, 25

GetLibraryTime, 22

getAllValuesID3, 16

getSubsetID3, 17

getSymbolValueID3, 17

hasMoreTokensStringTokenizer, 26

ID3, 12alreadyUsedToDecompose, 13calculateEntropy, 14createDecisionTree, 14decomposeNode, 15getAllValues, 16getSubset, 17getSymbolValue, 17ID3, 13

printDomains, 18printMyLabels, 18printTree, 19readData, 20

IntegerListMyID3Algorithm.cpp, 38

IntToStrLibraryUtils, 7

IsNumericLibraryUtils, 8

LibraryTime, 22∼LibraryTime, 22Delay, 22Get, 22LibraryTime, 22Start, 23Stop, 23

LibraryTime.cxx, 29LibraryTime.h, 31LibraryUtils, 7

DoubleToStr, 7IntToStr, 7IsNumeric, 8SignalNumber, 8StrIndexOf, 8StrStartsWith, 8StrToFloat, 9StrToInt, 9TrimString, 9

LibraryUtils.h, 33LibraryUtils::ConversionError, 11

what, 11

mainMyID3Algorithm.cpp, 38

MyID3Algorithm.cpp, 37IntegerList, 38main, 38StringList, 38StringTable, 38VectorIndexOf, 39

nextFloatTokenStringTokenizer, 26

Page 61: ID3 Algorithm - Reference Manual

INDEX 55

nextIntTokenStringTokenizer, 26

nextTokenStringTokenizer, 27

printDomainsID3, 18

printMyLabelsID3, 18

printTreeID3, 19

readDataID3, 20

remainingStringStringTokenizer, 28

SignalNumberLibraryUtils, 8

StartLibraryTime, 23

StopLibraryTime, 23

StrIndexOfLibraryUtils, 8

StringListMyID3Algorithm.cpp, 38

StringTableMyID3Algorithm.cpp, 38

StringTokenizer, 24∼StringTokenizer, 25countTokens, 25filterNextToken, 25hasMoreTokens, 26nextFloatToken, 26nextIntToken, 26nextToken, 27remainingString, 28StringTokenizer, 24

StringTokenizer.cpp, 48StringTokenizer.h, 52StrStartsWith

LibraryUtils, 8StrToFloat

LibraryUtils, 9StrToInt

LibraryUtils, 9

TrimStringLibraryUtils, 9

VectorIndexOfMyID3Algorithm.cpp, 39

whatLibraryUtils::ConversionError, 11

Generated on Fri Dec 16 16:50:04 2011 by Doxygen