📄 mybase.h
字号:
/*************************************************************************/
/* */
/* Get names of classes, attributes and attribute values */
/* ----------------------------------------------------- */
/* */
/*************************************************************************/
// MyDiag.h : header file
//
#if !defined(AFX_MYDIAG_H__0C77D11B_84AE_450C_BBEWEWEWESDFRF4EBF44F075E__INCLUDED_MMMMM)
#define AFX_MYDIAG_H__0C77D11B_84AE_450C_BBEWEWEWESDFRF4EBF44F075E__INCLUDED_MMMMM
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "defns.h"
#include "types.h"
#include "extern.h"
#define Space(s) (s == ' ' || s == '\n' || s == '\t')
#define SkipComment while ( ( c = getc(f) ) != '\n' )
#define Inc 2048
/*************************************************************************/
/* */
/* Read a name from file f into string s, setting Delimiter. */
/* */
/* - Embedded periods are permitted, but periods followed by space */
/* characters act as delimiters. */
/* - Embedded spaces are permitted, but multiple spaces are replaced */
/* by a single space. */
/* - Any character can be escaped by '\'. */
/* - The remainder of a line following '|' is ignored. */
/* */
/*************************************************************************/
BOOL ReadName(FILE *f, String s);
/*************************************************************************/
/* */
/* Read the names of classes, attributes and legal attribute values. */
/* On completion, these names are stored in: */
/* ClassName - class names */
/* AttName - attribute names */
/* AttValName - attribute value names */
/* with: */
/* MaxAttVal - number of values for each attribute */
/* */
/* Other global variables set are: */
/* MaxAtt - maximum attribute number */
/* MaxClass - maximum class number */
/* MaxDiscrVal - maximum discrete values for any attribute */
/* */
/* Note: until the number of attributes is known, the name */
/* information is assembled in local arrays */
/* */
/*************************************************************************/
void GetNames();
/*************************************************************************/
/* */
/* Locate value Val in List[First] to List[Last] */
/* */
/*************************************************************************/
int Which(String Val, String List, short First, short Last);
String CopyString(String x);
void Error(short n, char * s1, char *s2);
/*************************************************************************/
/* */
/* Read raw case descriptions from file with given extension. */
/* */
/* On completion, cases are stored in array Item in the form */
/* of Descriptions (i.e. arrays of attribute values), and */
/* MaxItem is set to the number of data items. */
/* */
/*************************************************************************/
void GetData(String Extension);
/***********************************************************************/
/* */
/* Read a raw case description from file Df. */
/* */
/* For each attribute, read the attribute value from the file. */
/* If it is a discrete valued attribute, find the associated no. */
/* of this attribute value (if the value is unknown this is 0). */
/* */
/* Returns the Description of the case (i.e. the array of */
/* attribute values). */
/* */
/*************************************************************************/
Description GetDescription(FILE * Df);
/*************************************************************************/
/* From BestTree.c
/* */
/* Routines to manage tree growth, pruning and evaluation */
/* ------------------------------------------------------ */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* Grow and prune a single tree from all data */
/* */
/*************************************************************************/
void OneTree();
/*************************************************************************/
/* */
/* Grow and prune TRIALS trees and select the best of them */
/* */
/*************************************************************************/
short BestTree();
/*************************************************************************/
/* */
/* The windowing approach seems to work best when the class */
/* distribution of the initial window is as close to uniform as */
/* possible. FormTarget generates this initial target distribution, */
/* setting up a TargetClassFreq value for each class. */
/* */
/*************************************************************************/
void FormTarget(ItemNo Size);
/*************************************************************************/
/* */
/* Form initial window, attempting to obtain the target class profile */
/* in TargetClassFreq. This is done by placing the targeted number */
/* of items of each class at the beginning of the set of data items. */
/* */
/*************************************************************************/
void FormInitialWindow();
/*************************************************************************/
/* */
/* Shuffle the data items randomly */
/* */
/*************************************************************************/
void Shuffle();
/*************************************************************************/
/* */
/* Grow a tree iteratively with initial window size Window and */
/* initial window increment IncExceptions. */
/* */
/* Construct a classifier tree using the data items in the */
/* window, then test for the successful classification of other */
/* data items by this tree. If there are misclassified items, */
/* put them immediately after the items in the window, increase */
/* the size of the window and build another classifier tree, and */
/* so on until we have a tree which successfully classifies all */
/* of the test items or no improvement is apparent. */
/* */
/* On completion, return the tree which produced the least errors. */
/* */
/*************************************************************************/
Tree Iterate(ItemNo Window, ItemNo IncExceptions);
/*************************************************************************/
/* */
/* Print report of errors for each of the trials */
/* */
/*************************************************************************/
void Evaluate(Boolean CMInfo, short Saved);
/*************************************************************************/
/* From Built.c */
/* */
/* */
/* Allocate space for tree tables */
/* */
/*************************************************************************/
void InitialiseTreeData();
/*************************************************************************/
/* */
/* Initialise the weight of each item */
/* */
/*************************************************************************/
void InitialiseWeights();
/*************************************************************************/
/* */
/* Build a decision tree for the cases Fp through Lp: */
/* */
/* - if all cases are of the same class, the tree is a leaf and so */
/* the leaf is returned labelled with this class */
/* */
/* - for each attribute, calculate the potential information provided */
/* by a test on the attribute (based on the probabilities of each */
/* case having a particular value for the attribute), and the gain */
/* in information that would result from a test on the attribute */
/* (based on the probabilities of each case with a particular */
/* value for the attribute being of a particular class) */
/* */
/* - on the basis of these figures, and depending on the current */
/* selection criterion, find the best attribute to branch on. */
/* Note: this version will not allow a split on an attribute */
/* unless two or more subsets have at least MINOBJS items. */
/* */
/* - try branching and test whether better than forming a leaf */
/* */
/*************************************************************************/
Tree FormTree(ItemNo Fp, ItemNo Lp);
/*************************************************************************/
/* */
/* Group together the items corresponding to branch V of a test */
/* and return the index of the last such */
/* */
/* Note: if V equals zero, group the unknown values */
/* */
/*************************************************************************/
ItemNo Group(DiscrValue V,ItemNo Fp,ItemNo Lp,Tree TestNode);
/*************************************************************************/
/* */
/* Return the total weight of items from Fp to Lp */
/* */
/*************************************************************************/
ItemCount CountItems(ItemNo Fp,ItemNo Lp);
/*************************************************************************/
/* */
/* Exchange items at a and b */
/* */
/*************************************************************************/
void Swap(ItemNo a,ItemNo b);
void SwapUnweighted(ItemNo a, ItemNo b);
/*************************************************************************/
/* From Built.c */
/* */
/* */
/* Central tree-forming algorithm incorporating all criteria */
/* --------------------------------------------------------- */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* Allocate space for tree tables */
/* */
/*************************************************************************/
void InitialiseTreeData();
/*************************************************************************/
/* */
/* Initialise the weight of each item */
/* */
/*************************************************************************/
void InitialiseWeights();
/*************************************************************************/
/* */
/* Build a decision tree for the cases Fp through Lp: */
/* */
/* - if all cases are of the same class, the tree is a leaf and so */
/* the leaf is returned labelled with this class */
/* */
/* - for each attribute, calculate the potential information provided */
/* by a test on the attribute (based on the probabilities of each */
/* case having a particular value for the attribute), and the gain */
/* in information that would result from a test on the attribute */
/* (based on the probabilities of each case with a particular */
/* value for the attribute being of a particular class) */
/* */
/* - on the basis of these figures, and depending on the current */
/* selection criterion, find the best attribute to branch on. */
/* Note: this version will not allow a split on an attribute */
/* unless two or more subsets have at least MINOBJS items. */
/* */
/* - try branching and test whether better than forming a leaf */
/* */
/*************************************************************************/
Tree FormTree(ItemNo Fp, ItemNo Lp);
/*************************************************************************/
/* */
/* Group together the items corresponding to branch V of a test */
/* and return the index of the last such */
/* */
/* Note: if V equals zero, group the unknown values */
/* */
/*************************************************************************/
ItemNo Group(DiscrValue V,ItemNo Fp,ItemNo Lp,Tree TestNode);
/*************************************************************************/
/* */
/* Return the total weight of items from Fp to Lp */
/* */
/*************************************************************************/
ItemCount CountItems(ItemNo Fp,ItemNo Lp);
/*************************************************************************/
/* */
/* Exchange items at a and b */
/* */
/*************************************************************************/
void Swap(ItemNo a,ItemNo b);
/*************************************************************************/
/* */
/* From Trees.c */
/* */
/* */
/* Routines for displaying, building, saving and restoring trees */
/* ------------------------------------------------------------- */
/* */
/*************************************************************************/
#define Tab "| "
#define TabSize 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -