Main Page | Modules | Data Structures | File List | Globals | Related Pages

ExampleSpec.h File Reference


Detailed Description

Schema for training data.

This is based off of Ross Quinlan's C4.5 format and can read and write that format to disk.

Bug:
Under Cygnus (and windows) lex doesn't seem to do the right thing with EOF rules, so you need to put an extra return at the end of your .names files.

Go to the source code of this file.

Data Structures

struct  _ExampleSpec_
 Schema for training data. More...


Defines

#define ExampleSpecGetAttributeType(es, num)   ( AttributeSpecGetType(((AttributeSpecPtr)VALIndex(es->attributes, num))) )
 Returns the type of the specified attribute.

#define ExampleSpecGetAttributeValueCount(es, attNum)   ( AttributeSpecGetNumValues(((AttributeSpecPtr)VALIndex(es->attributes, attNum))) )
 Returns the number of values of the attribute.

#define ExampleSpecGetAttributeValueName(es, attNum, valNum)   ( (char *)AttributeSpecGetValueName(((AttributeSpecPtr)VALIndex(es->attributes, attNum)), valNum) )
 Return the name of the specified value of the specified attribute.


Typedefs

typedef _ExampleSpec_ ExampleSpec
 Schema for training data.

typedef _ExampleSpec_ExampleSpecPtr
 Schema for training data.


Functions

ExampleSpecPtr ExampleSpecNew (void)
 Programmatically creates a new ExampleSpec.

void ExampleSpecFree (ExampleSpecPtr es)
 Frees all the memory being used by the ExampleSpec.

void ExampleSpecAddClass (ExampleSpecPtr es, char *className)
 Adds a new class to the ExampleSpec and gives it the specified name.

int ExampleSpecAddDiscreteAttribute (ExampleSpecPtr es, char *name)
 Adds a new discrete attribute to the ExampleSpec and gives it the specified name.

int ExampleSpecAddContinuousAttribute (ExampleSpecPtr es, char *name)
 Adds a new continuous attribute to the ExampleSpec and gives it the specified name.

void ExampleSpecAddAttributeValue (ExampleSpecPtr es, int attNum, char *name)
 Adds a new value to the specified attribute and gives it the specified name.

ExampleSpecPtr ExampleSpecRead (char *fileName)
 Reads a .names formated file and build an ExampleSpec.

int ExampleSpecGetNumAttributes (ExampleSpecPtr es)
 Returns the number of attributes that the example spec contains.

int ExampleSpecIsAttributeDiscrete (ExampleSpecPtr es, int num)
 Returns 1 if the specified attribute is discrete and 0 otherwise.

int ExampleSpecIsAttributeContinuous (ExampleSpecPtr es, int num)
 Returns 1 if the specified attribute is continuous and 0 otherwise.

int ExampleSpecIsAttributeIgnored (ExampleSpecPtr es, int num)
 Returns 1 if the specified attribute should be ignored and 0 otherwise.

char * ExampleSpecGetAttributeName (ExampleSpecPtr es, int attNum)
 If the attNum is valid, this returns the name of the associated attribute.

int ExampleSpecLookupAttributeName (ExampleSpecPtr es, char *valName)
 Returns the index of the named attribute.

int ExampleSpecLookupAttributeValueName (ExampleSpecPtr es, int attNum, char *valName)
 Returns the index of the named value.

int ExampleSpecLookupClassName (ExampleSpecPtr es, char *name)
 If name is a valid class name, this returns the index associated with the class.

char * ExampleSpecGetClassValueName (ExampleSpecPtr es, int classNum)
 If the classNum is valid, this returns the name of the associated class.

int ExampleSpecGetNumClasses (ExampleSpecPtr es)
 Returns the number of classes in the ExampleSpec.

void ExampleSpecWrite (ExampleSpecPtr es, FILE *out)
 Outputs the ExampleSpec in .names format.


Define Documentation

#define ExampleSpecGetAttributeType es,
num   )     ( AttributeSpecGetType(((AttributeSpecPtr)VALIndex(es->attributes, num))) )
 

Returns the type of the specified attribute.

There are currently four supported types:

  • asIgnore
  • asContinuous
  • asDiscreteNamed
  • asDiscreteNoName

The programmatic construction interface only supports asIgnore, asContinuous, and asDiscreteNamed, but the other is needed to fully support the C4.5 format.

#define ExampleSpecGetAttributeValueCount es,
attNum   )     ( AttributeSpecGetNumValues(((AttributeSpecPtr)VALIndex(es->attributes, attNum))) )
 

Returns the number of values of the attribute.

If the attNum is valid and ExampleSpecIsAttributeDiscrete(es, attNum) returns 1, this function will return the number of values that attribute has. Remember that these values will be 0 indexed.

#define ExampleSpecGetAttributeValueName es,
attNum,
valNum   )     ( (char *)AttributeSpecGetValueName(((AttributeSpecPtr)VALIndex(es->attributes, attNum)), valNum) )
 

Return the name of the specified value of the specified attribute.

If attNum is valid, and ExampleSpecIsAttributeDiscrete(es, attNum) returns 1, and valNum is valid, this returns the name of the specified value of the specified attribute.


Typedef Documentation

typedef struct _ExampleSpec_ ExampleSpec
 

Schema for training data.

typedef struct _ExampleSpec_ * ExampleSpecPtr
 

Schema for training data.


Function Documentation

void ExampleSpecAddAttributeValue ExampleSpecPtr  es,
int  attNum,
char *  name
 

Adds a new value to the specified attribute and gives it the specified name.

The specified attribute had better be a discrete attribute. The main use of the name is to read/write Examples and ExampleSpecs in human readable format.

Note that this function takes over the memory associated with the name argument and will free it later. This means that you shouldn't pass in static strings, or strings that were allocated on the stack.

void ExampleSpecAddClass ExampleSpecPtr  es,
char *  className
 

Adds a new class to the ExampleSpec and gives it the specified name.

The main use of the name is to read/write Examples and ExampleSpecs in human readable format. The new class is assigned a value which you can retrieve by calling: ExampleSpecLookupClassName(es, className).

Note that this function takes over the memory associated with the className argument and will free it later. This means that you shouldn't pass in static strings, or strings that were allocated on the stack.

int ExampleSpecAddContinuousAttribute ExampleSpecPtr  es,
char *  name
 

Adds a new continuous attribute to the ExampleSpec and gives it the specified name.

The main use of the name is to read/write ExampleSpecs in human readable format. The function returns the index of the new attribute.

Note that this function takes over the memory associated with the name argument and will free it later. This means that you shouldn't pass in static strings, or strings that were allocated on the stack.

int ExampleSpecAddDiscreteAttribute ExampleSpecPtr  es,
char *  name
 

Adds a new discrete attribute to the ExampleSpec and gives it the specified name.

The main use of the name is to read/write ExampleSpecs in human readable format. The function returns the index of the new attribute, you can use the index to add values to the attribute using ExampleSpecAddAttributeValue.

Note that this function takes over the memory associated with the name argument and will free it later. This means that you shouldn't pass in static strings, or strings that were allocated on the stack.

void ExampleSpecFree ExampleSpecPtr  es  ) 
 

Frees all the memory being used by the ExampleSpec.

Note that all the Examples created with an ExampleSpec maintain a pointer to the ExampleSpec, so you shouldn't free it or modify the ExampleSpec until you are done with all the Examples referencing it.

char* ExampleSpecGetAttributeName ExampleSpecPtr  es,
int  attNum
 

If the attNum is valid, this returns the name of the associated attribute.

char* ExampleSpecGetClassValueName ExampleSpecPtr  es,
int  classNum
 

If the classNum is valid, this returns the name of the associated class.

int ExampleSpecGetNumAttributes ExampleSpecPtr  es  ) 
 

Returns the number of attributes that the example spec contains.

Remember that the attributes are indexed in a 0-based fashion (like C arrays) so the actual valid index for the attributes will be from 0 to ExampleSpecGetNumAttributes(es) - 1.

int ExampleSpecGetNumClasses ExampleSpecPtr  es  ) 
 

Returns the number of classes in the ExampleSpec.

Remember that the classes will have indexes 0 - ExampleSpecGetNumClasses(es) - 1.

int ExampleSpecIsAttributeContinuous ExampleSpecPtr  es,
int  num
 

Returns 1 if the specified attribute is continuous and 0 otherwise.

Be sure not to ask for an attribute numbered >= ExampleSpecGetNumAttributes(es).

int ExampleSpecIsAttributeDiscrete ExampleSpecPtr  es,
int  num
 

Returns 1 if the specified attribute is discrete and 0 otherwise.

Be sure not to ask for an attribute numbered >= ExampleSpecGetNumAttributes(es).

int ExampleSpecIsAttributeIgnored ExampleSpecPtr  es,
int  num
 

Returns 1 if the specified attribute should be ignored and 0 otherwise.

Be sure not to ask for an attribute numbered >= ExampleSpecGetNumAttributes(es).

int ExampleSpecLookupAttributeName ExampleSpecPtr  es,
char *  valName
 

Returns the index of the named attribute.

Does a linear search through the ExampleSpec's attributes looking for the first one named attributeName. Returns the index of the first matching attribute or -1 if there is no match.

int ExampleSpecLookupAttributeValueName ExampleSpecPtr  es,
int  attNum,
char *  valName
 

Returns the index of the named value.

If attribNum is a valid attribute index this does a linear search through the associated attribute's values for one named attributeName. Returns the index or -1 if there is no match.

int ExampleSpecLookupClassName ExampleSpecPtr  es,
char *  name
 

If name is a valid class name, this returns the index associated with the class.

ExampleSpecPtr ExampleSpecNew void   ) 
 

Programmatically creates a new ExampleSpec.

Use the ExampleSpecAddFOO functions to add classes, attributes, and their values to the spec.

This function allocates memory which should be freed by calling ExampleSpecFree.

ExampleSpecPtr ExampleSpecRead char *  fileName  ) 
 

Reads a .names formated file and build an ExampleSpec.

Attempts to read an example from the passed FILE *, which should be opened for reading. The file should contain an ExampleSpec in C4.5 format, that is the file should be a C4.5 names file.

This function will return 0 (NULL) if it is unable to read an ExampleSpec from the file (bad input or the file does not exist). If the input is badly formed, the function will also output an error to the console.

Note that you could pass stdin to the function to read an ExampleSpec from the console.

This function allocates memory which should be freed by calling ExampleSpecFree.

void ExampleSpecWrite ExampleSpecPtr  es,
FILE *  out
 

Outputs the ExampleSpec in .names format.

Writes the example to the passed FILE *, which should be opened for writing. The example will be written in C4.5 names format, and could later be read in using ExampleSpecRead.

Note that you could pass stdout to the function to write an ExampleSpec to the console.


Generated for VFML by doxygen hosted by SourceForge.net Logo