FANN C++ Training Data

Summary
FANN C++ Training Data
training_datatraining_data is used to create and manipulate training data used by the neural_net
Functions
training_dataDefault constructor creates an empty training data.
training_dataCopy constructor constructs a copy of the training data.
~training_dataProvides automatic cleanup of data.
destroyDestructs the training data.
read_train_from_fileReads a file that stores training data.
save_trainSave the training structure to a file, with the format as specified in read_train_from_file
save_train_to_fixedSaves the training structure to a fixed point data file.
shuffle_train_dataShuffles training data, randomizing the order.
merge_train_dataMerges the data into the data contained in the training_data.
length_train_dataReturns the number of training patterns in the training_data.
num_input_train_dataReturns the number of inputs in each of the training patterns in the training_data.
num_output_train_dataReturns the number of outputs in each of the training patterns in the struct fann_train_data.
get_inputGrant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions
get_outputGrant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions
get_train_inputGets the training input data at the given position
get_train_outputGets the training output data at the given position
set_train_dataSet the training data to the input and output data provided.
set_train_dataSet the training data to the input and output data provided.
create_train_from_callbackCreates the training data struct from a user supplied function.
get_min_inputGet the minimum value of all in the input data
get_max_inputGet the maximum value of all in the input data
get_min_outputGet the minimum value of all in the output data
get_max_outputGet the maximum value of all in the output data
scale_input_train_dataScales the inputs in the training data to the specified range.
scale_output_train_dataScales the outputs in the training data to the specified range.
scale_train_dataScales the inputs and outputs in the training data to the specified range.
subset_train_dataChanges the training data to a subset, starting at position pos and length elements forward.

training_data

class training_data

training_data is used to create and manipulate training data used by the neural_net

Encapsulation of a training data set struct fann_train_data and associated C API functions.

Summary
Functions
training_dataDefault constructor creates an empty training data.
training_dataCopy constructor constructs a copy of the training data.
~training_dataProvides automatic cleanup of data.
destroyDestructs the training data.
read_train_from_fileReads a file that stores training data.
save_trainSave the training structure to a file, with the format as specified in read_train_from_file
save_train_to_fixedSaves the training structure to a fixed point data file.
shuffle_train_dataShuffles training data, randomizing the order.
merge_train_dataMerges the data into the data contained in the training_data.
length_train_dataReturns the number of training patterns in the training_data.
num_input_train_dataReturns the number of inputs in each of the training patterns in the training_data.
num_output_train_dataReturns the number of outputs in each of the training patterns in the struct fann_train_data.
get_inputGrant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions
get_outputGrant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions
get_train_inputGets the training input data at the given position
get_train_outputGets the training output data at the given position
set_train_dataSet the training data to the input and output data provided.
set_train_dataSet the training data to the input and output data provided.
create_train_from_callbackCreates the training data struct from a user supplied function.
get_min_inputGet the minimum value of all in the input data
get_max_inputGet the maximum value of all in the input data
get_min_outputGet the minimum value of all in the output data
get_max_outputGet the maximum value of all in the output data
scale_input_train_dataScales the inputs in the training data to the specified range.
scale_output_train_dataScales the outputs in the training data to the specified range.
scale_train_dataScales the inputs and outputs in the training data to the specified range.
subset_train_dataChanges the training data to a subset, starting at position pos and length elements forward.

Functions

training_data

training_data() : train_data(NULL)

Default constructor creates an empty training data.  Use read_train_from_file, set_train_data or create_train_from_callback to initialize.

training_data

training_data(const training_data &data)

Copy constructor constructs a copy of the training data.  Corresponds to the C API fann_duplicate_train_data function.

~training_data

#ifdef USE_VIRTUAL_DESTRUCTOR virtual #endif ~training_data()

Provides automatic cleanup of data.  Define USE_VIRTUAL_DESTRUCTOR if you need the destructor to be virtual.

See also

destroy

destroy

void destroy_train()

Destructs the training data.  Called automatically by the destructor.

See also

~training_data

read_train_from_file

bool read_train_from_file(const std::string &filename)

Reads a file that stores training data.

The file must be formatted like

num_train_data num_input num_output
inputdata seperated by space
outputdata seperated by space

.
.
.

inputdata seperated by space
outputdata seperated by space

See also

neural_net::train_on_data, save_train, fann_read_train_from_file

This function appears in FANN >= 1.0.0

save_train

bool save_train(const std::string &filename)

Save the training structure to a file, with the format as specified in read_train_from_file

Return

The function returns true on success and false on failure.

See also

read_train_from_file, save_train_to_fixed, fann_save_train

This function appears in FANN >= 1.0.0.

save_train_to_fixed

bool save_train_to_fixed(const std::string &filename,
unsigned int decimal_point)

Saves the training structure to a fixed point data file.

This function is very useful for testing the quality of a fixed point network.

Return

The function returns true on success and false on failure.

See also

save_train, fann_save_train_to_fixed

This function appears in FANN >= 1.0.0.

shuffle_train_data

void shuffle_train_data()

Shuffles training data, randomizing the order.  This is recommended for incremental training, while it have no influence during batch training.

This function appears in FANN >= 1.1.0.

merge_train_data

void merge_train_data(const training_data &data)

Merges the data into the data contained in the training_data.

This function appears in FANN >= 1.1.0.

length_train_data

unsigned int length_train_data()

Returns the number of training patterns in the training_data.

See also

num_input_train_data, num_output_train_data, fann_length_train_data

This function appears in FANN >= 2.0.0.

num_input_train_data

unsigned int num_input_train_data()

Returns the number of inputs in each of the training patterns in the training_data.

See also

num_output_train_data, length_train_data, fann_num_input_train_data

This function appears in FANN >= 2.0.0.

num_output_train_data

unsigned int num_output_train_data()

Returns the number of outputs in each of the training patterns in the struct fann_train_data.

See also

num_input_train_data, length_train_data, fann_num_output_train_data

This function appears in FANN >= 2.0.0.

get_input

fann_type **get_input()

Grant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions

Returns

A pointer to the array of input training data

See also

get_output, set_train_data

This function appears in FANN >= 2.0.0.

get_output

fann_type **get_output()

Grant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions

Returns

A pointer to the array of output training data

See also

get_input, set_train_data

This function appears in FANN >= 2.0.0.

get_train_input

fann_type *get_train_input(unsigned int position)

Gets the training input data at the given position

Returns

A pointer to the array of input training data at the given position

See also

get_train_output, set_train_data

This function appears in FANN >= 2.3.0.

get_train_output

fann_type *get_train_output(unsigned int position)

Gets the training output data at the given position

Returns

A pointer to the array of output training data at the given position

See also

get_train_input

This function appears in FANN >= 2.3.0.

set_train_data

void set_train_data(unsigned int num_data,
unsigned int num_input,
fann_type **input,
unsigned int num_output,
fann_type **output)

Set the training data to the input and output data provided.

A copy of the data is made so there are no restrictions on the allocation of the input/output data and the caller is responsible for the deallocation of the data pointed to by input and output.

Parameters

num_dataThe number of training data
num_inputThe number of inputs per training data
num_outputThe number of ouputs per training data
inputThe set of inputs (a pointer to an array of pointers to arrays of floating point data)
outputThe set of desired outputs (a pointer to an array of pointers to arrays of floating point data)

See also

get_input, get_output

set_train_data

void set_train_data(unsigned int num_data,
unsigned int num_input,
fann_type *input,
unsigned int num_output,
fann_type *output)

Set the training data to the input and output data provided.

A copy of the data is made so there are no restrictions on the allocation of the input/output data and the caller is responsible for the deallocation of the data pointed to by input and output.

Parameters

num_dataThe number of training data
num_inputThe number of inputs per training data
num_outputThe number of ouputs per training data
inputThe set of inputs (an array with the dimension num_data*num_input)
outputThe set of desired outputs (an array with the dimension num_data*num_output)

See also

get_input, get_output

create_train_from_callback

void create_train_from_callback(
   unsigned int num_data,
   unsigned int num_input,
   unsigned int num_output,
   void (FANN_API *user_function)(unsigned int, unsigned int, unsigned int, fann_type *, fann_type *)
)

Creates the training data struct from a user supplied function.  As the training data are numerable (data 1, data 2...), the user must write a function that receives the number of the training data set (input,output) and returns the set.

Parameters

num_dataThe number of training data
num_inputThe number of inputs per training data
num_outputThe number of ouputs per training data
user_functionThe user suplied function

Parameters for the user function

numThe number of the training data set
num_inputThe number of inputs per training data
num_outputThe number of ouputs per training data
inputThe set of inputs
outputThe set of desired outputs

See also

training_data::read_train_from_file, neural_net::train_on_data, fann_create_train_from_callback

This function appears in FANN >= 2.1.0

get_min_input

fann_type get_min_input()

Get the minimum value of all in the input data

This function appears in FANN >= 2.3.0

get_max_input

fann_type get_max_input()

Get the maximum value of all in the input data

This function appears in FANN >= 2.3.0

get_min_output

fann_type get_min_output()

Get the minimum value of all in the output data

This function appears in FANN >= 2.3.0

get_max_output

fann_type get_max_output()

Get the maximum value of all in the output data

This function appears in FANN >= 2.3.0

scale_input_train_data

void scale_input_train_data(fann_type new_min,
fann_type new_max)

Scales the inputs in the training data to the specified range.

A simplified scaling method, which is mostly useful in examples where it’s known that all the data will be in one range and it should be transformed to another range.

It is not recommended to use this on subsets of data as the complete input range might not be available in that subset.

For more powerful scaling, please consider neural_net::scale_train

See also

scale_output_train_data, scale_train_data, fann_scale_input_train_data

This function appears in FANN >= 2.0.0.

scale_output_train_data

void scale_output_train_data(fann_type new_min,
fann_type new_max)

Scales the outputs in the training data to the specified range.

A simplified scaling method, which is mostly useful in examples where it’s known that all the data will be in one range and it should be transformed to another range.

It is not recommended to use this on subsets of data as the complete input range might not be available in that subset.

For more powerful scaling, please consider neural_net::scale_train

See also

scale_input_train_data, scale_train_data, fann_scale_output_train_data

This function appears in FANN >= 2.0.0.

scale_train_data

void scale_train_data(fann_type new_min,
fann_type new_max)

Scales the inputs and outputs in the training data to the specified range.

A simplified scaling method, which is mostly useful in examples where it’s known that all the data will be in one range and it should be transformed to another range.

It is not recommended to use this on subsets of data as the complete input range might not be available in that subset.

For more powerful scaling, please consider neural_net::scale_train

See also

scale_output_train_data, scale_input_train_data, fann_scale_train_data

This function appears in FANN >= 2.0.0.

subset_train_data

void subset_train_data(unsigned int pos,
unsigned int length)

Changes the training data to a subset, starting at position pos and length elements forward.  Use the copy constructor to work on a new copy of the training data.

FANN::training_data full_data_set;
full_data_set.read_train_from_file("somefile.train");
FANN::training_data *small_data_set = new FANN::training_data(full_data_set);
small_data_set->subset_train_data(0, 2); // Only use first two
// Use small_data_set ...
delete small_data_set;

See also

fann_subset_train_data

This function appears in FANN >= 2.0.0.

class training_data
training_data is used to create and manipulate training data used by the neural_net
training_data() : train_data(NULL)
Default constructor creates an empty training data.
class neural_net
neural_net is the main neural network class used for both training and execution
#ifdef USE_VIRTUAL_DESTRUCTOR virtual #endif ~training_data()
Provides automatic cleanup of data.
void destroy_train()
Destructs the training data.
bool read_train_from_file(const std::string &filename)
Reads a file that stores training data.
bool save_train(const std::string &filename)
Save the training structure to a file, with the format as specified in read_train_from_file
bool save_train_to_fixed(const std::string &filename,
unsigned int decimal_point)
Saves the training structure to a fixed point data file.
void shuffle_train_data()
Shuffles training data, randomizing the order.
void merge_train_data(const training_data &data)
Merges the data into the data contained in the training_data.
unsigned int length_train_data()
Returns the number of training patterns in the training_data.
unsigned int num_input_train_data()
Returns the number of inputs in each of the training patterns in the training_data.
unsigned int num_output_train_data()
Returns the number of outputs in each of the training patterns in the struct fann_train_data.
struct fann_train_data
Structure used to store data, for use with training.
fann_type **get_input()
Grant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions
fann_type **get_output()
Grant access to the encapsulated data since many situations and applications creates the data from sources other than files or uses the training data for testing and related functions
fann_type *get_train_input(unsigned int position)
Gets the training input data at the given position
fann_type *get_train_output(unsigned int position)
Gets the training output data at the given position
void set_train_data(unsigned int num_data,
unsigned int num_input,
fann_type **input,
unsigned int num_output,
fann_type **output)
Set the training data to the input and output data provided.
void create_train_from_callback(
   unsigned int num_data,
   unsigned int num_input,
   unsigned int num_output,
   void (FANN_API *user_function)(unsigned int, unsigned int, unsigned int, fann_type *, fann_type *)
)
Creates the training data struct from a user supplied function.
fann_type get_min_input()
Get the minimum value of all in the input data
fann_type get_max_input()
Get the maximum value of all in the input data
fann_type get_min_output()
Get the minimum value of all in the output data
fann_type get_max_output()
Get the maximum value of all in the output data
void scale_input_train_data(fann_type new_min,
fann_type new_max)
Scales the inputs in the training data to the specified range.
void scale_output_train_data(fann_type new_min,
fann_type new_max)
Scales the outputs in the training data to the specified range.
void scale_train_data(fann_type new_min,
fann_type new_max)
Scales the inputs and outputs in the training data to the specified range.
void subset_train_data(unsigned int pos,
unsigned int length)
Changes the training data to a subset, starting at position pos and length elements forward.
FANN_EXTERNAL struct fann_train_data *FANN_API fann_duplicate_train_data(
   struct fann_train_data *data
)
Returns an exact copy of a struct fann_train_data.
void train_on_data(const training_data &data,
unsigned int max_epochs,
unsigned int epochs_between_reports,
float desired_error)
Trains on an entire dataset, for a period of time.
FANN_EXTERNAL struct fann_train_data *FANN_API fann_read_train_from_file(
   const char *filename
)
Reads a file that stores training data.
FANN_EXTERNAL int FANN_API fann_save_train(struct fann_train_data *data,
const char *filename)
Save the training structure to a file, with the format as specified in fann_read_train_from_file
FANN_EXTERNAL int FANN_API fann_save_train_to_fixed(
   struct fann_train_data *data,
   const char *filename,
   unsigned int decimal_point
)
Saves the training structure to a fixed point data file.
FANN_EXTERNAL unsigned int FANN_API fann_length_train_data(
   struct fann_train_data *data
)
Returns the number of training patterns in the struct fann_train_data.
FANN_EXTERNAL unsigned int FANN_API fann_num_input_train_data(
   struct fann_train_data *data
)
Returns the number of inputs in each of the training patterns in the struct fann_train_data.
FANN_EXTERNAL unsigned int FANN_API fann_num_output_train_data(
   struct fann_train_data *data
)
Returns the number of outputs in each of the training patterns in the struct fann_train_data.
FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_callback(
   unsigned int num_data,
   unsigned int num_input,
   unsigned int num_output,
   void (FANN_API *user_function)( unsigned int, unsigned int, unsigned int, fann_type * , fann_type * )
)
Creates the training data struct from a user supplied function.
void scale_train(training_data &data)
Scale input and output data based on previously calculated parameters.
FANN_EXTERNAL void FANN_API fann_scale_input_train_data(
   struct fann_train_data *train_data,
   fann_type new_min,
   fann_type new_max
)
Scales the inputs in the training data to the specified range.
FANN_EXTERNAL void FANN_API fann_scale_output_train_data(
   struct fann_train_data *train_data,
   fann_type new_min,
   fann_type new_max
)
Scales the outputs in the training data to the specified range.
FANN_EXTERNAL void FANN_API fann_scale_train_data(
   struct fann_train_data *train_data,
   fann_type new_min,
   fann_type new_max
)
Scales the inputs and outputs in the training data to the specified range.
FANN_EXTERNAL struct fann_train_data *FANN_API fann_subset_train_data(
   struct fann_train_data *data,
   unsigned int pos,
   unsigned int length
)
Returns an copy of a subset of the struct fann_train_data, starting at position pos and length elements forward.
Close