Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/fann_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,6 @@ struct fann *fann_create_from_fd_1_1(FILE *conf, const char *configuration_file)
} \
}

/* Optional scanf that sets a default value if the field is not present in the file.
* This is used for new parameters to maintain backward compatibility with older saved networks.
*/
#define fann_scanf_optional(type, name, val, default_val) \
{ \
long pos = ftell(conf); \
if (fscanf(conf, name "=" type "\n", val) != 1) { \
fseek(conf, pos, SEEK_SET); \
*(val) = (default_val); \
} \
}

#define fann_skip(name) \
{ \
if (fscanf(conf, name) != 0) { \
Expand All @@ -363,6 +351,8 @@ struct fann *fann_create_from_fd(FILE *conf, const char *configuration_file) {
struct fann *ann = NULL;

char *read_version;
/* only the current version stores the adam parameters */
int file_has_adam = 0;

read_version = (char *)calloc(strlen(FANN_CONF_VERSION "\n"), 1);
if (read_version == NULL) {
Expand Down Expand Up @@ -400,6 +390,8 @@ struct fann *fann_create_from_fd(FILE *conf, const char *configuration_file) {

return NULL;
}
} else {
file_has_adam = 1;
}

free(read_version);
Expand Down Expand Up @@ -435,10 +427,12 @@ struct fann *fann_create_from_fd(FILE *conf, const char *configuration_file) {
fann_scanf("%f", "rprop_delta_min", &ann->rprop_delta_min);
fann_scanf("%f", "rprop_delta_max", &ann->rprop_delta_max);
fann_scanf("%f", "rprop_delta_zero", &ann->rprop_delta_zero);
/* Adam parameters are optional for backward compatibility with older saved networks */
fann_scanf_optional("%f", "adam_beta1", &ann->adam_beta1, 0.9f);
fann_scanf_optional("%f", "adam_beta2", &ann->adam_beta2, 0.999f);
fann_scanf_optional("%f", "adam_epsilon", &ann->adam_epsilon, 1e-8f);
/* adam parameters are only present in the current version */
if (file_has_adam) {
fann_scanf("%f", "adam_beta1", &ann->adam_beta1);
fann_scanf("%f", "adam_beta2", &ann->adam_beta2);
fann_scanf("%f", "adam_epsilon", &ann->adam_epsilon);
}
fann_scanf("%u", "cascade_output_stagnation_epochs", &ann->cascade_output_stagnation_epochs);
fann_scanf("%f", "cascade_candidate_change_fraction", &ann->cascade_candidate_change_fraction);
fann_scanf("%u", "cascade_candidate_stagnation_epochs",
Expand Down
4 changes: 2 additions & 2 deletions src/include/fann_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdlib.h>
#include "fann_data.h"

#define FANN_FIX_VERSION "FANN_FIX_2.0"
#define FANN_FLO_VERSION "FANN_FLO_2.1"
#define FANN_FIX_VERSION "FANN_FIX_2.2"
#define FANN_FLO_VERSION "FANN_FLO_2.2"

#ifdef FIXEDFANN
#define FANN_CONF_VERSION FANN_FIX_VERSION
Expand Down
Loading