This is the interface for working with instances of the Example ADT. Note that all access to attributes is 0 based (just like C arrays).
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.
Go to the source code of this file.
Data Structures | |
struct | _Example_ |
ADT for working with examples. More... | |
Defines | |
#define | ExampleIsAttributeUnknown(e, attNum) ( VALIndex(e->attributes, attNum) == 0 ) |
Returns 1 if the specified attribute is marked as unknown and 0 otherwise. | |
#define | ExampleGetNumAttributes(e) (VALLength(((ExamplePtr)e)->attributes)) |
Returns the number of attributes that this example has. | |
#define | ExampleGetClass(e) (((ExamplePtr)e)->myclass) |
Returns the value of the example's class. | |
Typedefs | |
typedef _Example_ | Example |
ADT for working with examples. | |
typedef _Example_ * | ExamplePtr |
ADT for working with examples. | |
Functions | |
ExamplePtr | ExampleNew (ExampleSpecPtr es) |
Programmatically creates a new example. | |
void | ExampleFree (ExamplePtr e) |
Frees all the memory being used by the passed example. | |
ExamplePtr | ExampleClone (ExamplePtr e) |
Allocates memory and copies the example into it. | |
void | ExampleSetAttributeUnknown (ExamplePtr e, int attNum) |
Marks the specified attribute value as unknown. | |
void | ExampleSetDiscreteAttributeValue (ExamplePtr e, int attNum, int value) |
Considers the specified attribute to be discrete and sets its value to the specified value. | |
void | ExampleSetContinuousAttributeValue (ExamplePtr e, int attNum, double value) |
Considers the specified attribute to be continuous and sets its value to the specified value. | |
void | ExampleSetClass (ExamplePtr e, int theClass) |
Sets the example's class to the specified class. | |
void | ExampleSetClassUnknown (ExamplePtr e) |
Marks the example's class as unknown. | |
void | ExampleAddNoise (ExamplePtr e, float p, int doClass, int attrib) |
Randomly corrupts the attributes and class of the example. | |
ExamplePtr | ExampleRead (FILE *file, ExampleSpecPtr es) |
Attempts to read an example from the passed file pointer. | |
VoidListPtr | ExamplesRead (FILE *file, ExampleSpecPtr es) |
Reads as many examples as possible from the file pointer. | |
int | ExampleIsAttributeDiscrete (ExamplePtr e, int attNum) |
Returns 1 if the specified attribute is discrete and 0 otherwise. | |
int | ExampleIsAttributeContinuous (ExamplePtr e, int attNum) |
Returns 1 if the specified attribute is continuous and 0 otherwise. | |
int | ExampleGetDiscreteAttributeValue (ExamplePtr e, int attNum) |
Returns the value of the indicated discrete attribute. | |
double | ExampleGetContinuousAttributeValue (ExamplePtr e, int attNum) |
Returns the value of the indicated continuous attribute. | |
int | ExampleIsClassUnknown (ExamplePtr e) |
Returns 1 if the value of the example's class is known, and 0 otherwise. | |
float | ExampleDistance (ExamplePtr e, ExamplePtr dst) |
Returns the euclidian distance between the two examples. | |
void | ExampleWrite (ExamplePtr e, FILE *out) |
Writes the example to the passed file point.er. |
|
Returns the value of the example's class. If the value of the example's class is known this returns the value, otherwise this returns -1. |
|
Returns the number of attributes that this example has. This will be equal to the number of attributes that were in the ExampleSpec used to construct the example. |
|
Returns 1 if the specified attribute is marked as unknown and 0 otherwise. Be sure not to ask for an attNum >= ExampleGetNumAttributes(e). |
|
ADT for working with examples. See Example.h for more detail. |
|
ADT for working with examples. See Example.h for more detail. |
|
Randomly corrupts the attributes and class of the example. p should be a number between 0-1, which is interpreted as a probability (e.g. a value of .732 would be interpreted as 73.2%). class and attrib are flags which should be 1 if you want noise added to that part of the example and 0 otherwise. Then, for each discrete thing selected by the flags, this function will have the specified probability of changing it, without replacement, to a randomly selected value. This function changes the value of each continuous attribute by adding to it a value drawn from a normal distribution with mean 0 and with standard deviation p. |
|
Allocates memory and copies the example into it.
|
|
Returns the euclidian distance between the two examples. This ignores discrete attributes. |
|
Frees all the memory being used by the passed example.
|
|
Returns the value of the indicated continuous attribute. If the attNum is valid, and ExampleGetAttributeUnknown(e, attNum) returns 0, and ExampleIsAttributeContinuous(e, attNum) returns 1, this function will return the value of the attribute. If the conditions aren't met, there is a good chance that calling this will crash your program. |
|
Returns the value of the indicated discrete attribute. If the attNum is valid, and ExampleGetAttributeUnknown(e, attNum) returns 0, and ExampleIsAttributeDiscrete(e, attNum) returns 1, this function will return the value of the attribute. If the conditions aren't met, there is a good chance that calling this will crash your program. |
|
Returns 1 if the specified attribute is continuous and 0 otherwise. Be sure not to ask for an attNum >= ExampleGetNumAttributes(e). |
|
Returns 1 if the specified attribute is discrete and 0 otherwise. Be sure not to ask for an attNum >= ExampleGetNumAttributes(e). |
|
Returns 1 if the value of the example's class is known, and 0 otherwise.
|
|
Programmatically creates a new example. Allocates enough memory to hold all the attributes mentioned in the ExampleSpec passed. Use the ExampleSetFoo functions (see below) to set the values of the attributes and class. This function allocates memory which should be freed by calling ExampleFree. |
|
Attempts to read an example from the passed file pointer. FILE * should be opened for reading. The file should contain examples in C4.5 format. Uses the ExampleSpec to determine how many, what types, and how to interpret the attributes it needs to read. This function will return 0 (NULL) if it is unable to read an example from the file (bad input or EOF). 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 example from the console. This function allocates memory which should be freed by calling ExampleFree. |
|
Marks the specified attribute value as unknown. Future calls to ExampleGetAttributeUnknown for that attribute will return 1. |
|
Sets the example's class to the specified class. The function doesn't do much error checking so be sure that you call it consistent with ExampleSpecGetNumClasses. If you don't, there is a chance the example could cause your program to crash. |
|
Marks the example's class as unknown.
|
|
Considers the specified attribute to be continuous and sets its value to the specified value. This function doesn't do much error checking so be sure that you call it consistent with ExampleIsAttributeDiscrete, and ExampleIsAttributeContinuous. If you don't, there is a chance the example could cause your program to crash. |
|
Considers the specified attribute to be discrete and sets its value to the specified value. This function doesn't do much error checking so be sure that you call it consistent with ExampleIsAttributeDiscrete, ExampleIsAttributeContinuous and ExampleSpecGetAttributeValueCount. If you don't, there is a chance the example could cause your program to crash. |
|
Reads as many examples as possible from the file pointer. Calls ExampleRead until it gets a 0, allocates a list and adds each example to it. You are responsible for freeing the examples and the list. |
|
Writes the example to the passed file point.er. FILE * should be opened for writing. The example will be written in C4.5 format, and could later be read in using ExampleRead. Note that you could pass stdout to the function to write an example to the console. |