Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
steffennissen committed Jul 6, 2013
1 parent cdf7c9e commit 881e35c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/fann_train_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void fann_scale_data(fann_type ** data, unsigned int num_data, unsigned int num_
fann_type new_min, fann_type new_max)
{
unsigned int dat, elem;
fann_type old_min, old_max, temp, old_span, new_span, factor;
fann_type old_min, old_max, temp;

old_min = old_max = data[0][0];

Expand All @@ -369,6 +369,18 @@ void fann_scale_data(fann_type ** data, unsigned int num_data, unsigned int num_
}
}

fann_scale_data_to_range(data, num_data, num_elem, old_min, old_max, new_min, new_max);
}

/*
* INTERNAL FUNCTION Scales data to a specific range
*/
FANN_EXTERNAL void FANN_API fann_scale_data_to_range(fann_type ** data, unsigned int num_data, unsigned int num_elem,
fann_type old_min, fann_type old_max, fann_type new_min, fann_type new_max)
{
unsigned int dat, elem;
fann_type temp, old_span, new_span, factor;

old_span = old_max - old_min;
new_span = new_max - new_min;
factor = new_span / old_span;
Expand Down Expand Up @@ -401,6 +413,7 @@ void fann_scale_data(fann_type ** data, unsigned int num_data, unsigned int num_
}
}


/*
* Scales the inputs in the training data to the specified range
*/
Expand Down Expand Up @@ -884,6 +897,21 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_callback(
return data;
}

FANN_EXTERNAL fann_type * FANN_API fann_get_train_input(struct fann_train_data * data, unsigned int position)
{
if(position >= data->num_data)
return NULL;
return data->input[position];
}

FANN_EXTERNAL fann_type * FANN_API fann_get_train_output(struct fann_train_data * data, unsigned int position)
{
if(position >= data->num_data)
return NULL;
return data->output[position];
}


/*
* INTERNAL FUNCTION Reads training data from a file descriptor.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/include/fann_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void fann_set_shortcut_connections(struct fann *ann);

int fann_allocate_scale(struct fann *ann);

FANN_EXTERNAL void FANN_API fann_scale_data_to_range(fann_type ** data, unsigned int num_data, unsigned int num_elem,
fann_type old_min, fann_type old_max, fann_type new_min, fann_type new_max);

/* called fann_max, in order to not interferre with predefined versions of max */
#define fann_max(x, y) (((x) > (y)) ? (x) : (y))
#define fann_min(x, y) (((x) < (y)) ? (x) : (y))
Expand Down
20 changes: 20 additions & 0 deletions src/include/fann_train.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,26 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_callback(
*/
FANN_EXTERNAL void FANN_API fann_destroy_train(struct fann_train_data *train_data);

/* Function: fann_get_train_input
Gets the training input data at the given position
See also:
<fann_get_train_output>
This function appears in FANN >= 2.3.0
*/
FANN_EXTERNAL fann_type * FANN_API fann_get_train_input(struct fann_train_data * data, unsigned int position);

/* Function: fann_get_train_output
Gets the training output data at the given position
See also:
<fann_get_train_output>
This function appears in FANN >= 2.3.0
*/
FANN_EXTERNAL fann_type * FANN_API fann_get_train_output(struct fann_train_data * data, unsigned int position);


/* Function: fann_shuffle_train_data
Expand Down

0 comments on commit 881e35c

Please sign in to comment.