next up previous contents
Next: The Class CSupport Up: The Neural Network Library Previous: New Data Types

The Class CData

Objects of this class can be used as a fast file interface. The basic task performed by this object is to load the data file into the memory. It makes it possible that each input tuple can be accessed in any order without reading the file again. The important methods of this object are shown below.

CData::CData();  // constructor

// method to read the file into memory
// returns the number of records in the file
int    CData::Read(char * filename,    // the data-file name
                   int input_length,   // number of input attributes
                   int output_length); // number of output attributes
                                       // if a class number is used 1

// methods to access the data
TVector CData::GetInV(TVector vect, int no); // read the input vector
TVector CData::GetOutV(TVector vect, int no);// read the output vector

To use the facilities a CData-object is created in the application code, the function to read the file into the object memory is called; after this the data is available for use. The following example will explain the use of this class and also shows the necessary memory allocation.

...
int no_inputs  = 10;  // number of input attributes in the file
int no_outputs = 2;   // number of output attributes in the file
int no_records;       // variable to store the number of records
CData aDataObj;       // the data object
// the vectors to store the returned tuples
TVector inputVec  = new double[no_inputs];
TVector outputVec = new double[no_outputs];
...
// read the file "file.dat"
no_records = aDataObj.Read("file.dat", no_inputs, no_outputs);
...
for(i=0;i<no_records;i++)
{
    inputVec  = aDataObj.GetInV(inputVec, i);  // get input tuple  i
    outputVec = aDataObj.GetOutV(outputVec, i);// get output tuple i
    ...
}
...
// free the memory
delete[] inputVec;
delete[] outputVec;


next up previous contents
Next: The Class CSupport Up: The Neural Network Library Previous: New Data Types

Albrecht Schmidt
Mit Okt 4 16:45:34 CEST 2000