[libfann] 205/242: documentation and minor changes

Christian Kastner chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

chrisk-guest pushed a commit to tag Version2_0_0
in repository libfann.

commit 041189e22019fa5bdd873ae6783e73eff74bea6e
Author: Steffen Nissen <lukesky at diku.dk>
Date:   Tue Nov 15 19:47:39 2005 +0000

    documentation and minor changes
---
 ChangeLog                   |   3 +
 benchmarks/Makefile         |   4 +-
 examples/cascade_train.c    |  13 +-
 examples/xor_train.c        |  14 +-
 src/fann.c                  |  58 ++++----
 src/fann_cascade.c          |  37 ++++--
 src/fann_io.c               |   4 +-
 src/fann_train_data.c       |  20 +--
 src/include/fann.h          |  12 +-
 src/include/fann_cascade.h  | 317 +++++++++++++++++++++++++++++++++++++++++---
 src/include/fann_data.h     |  15 ++-
 src/include/fann_internal.h |   6 +-
 src/include/fann_train.h    |  10 +-
 13 files changed, 413 insertions(+), 100 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8aae180..b3718a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ libfann (2.0.0) stable; urgency=low
 	* Removed some depricated functions
 	* New set of fann_create functions
 	* Altered the way the callback function works
+	* Training can be stopped by counting the number of datasets that fail instead of just MSE
+	* Fixed a memory leak when copying training data
+	* More activation functions
 
 libfann (1.2.0) stable; urgency=low
 	* Fixes for better compability with different compilers
diff --git a/benchmarks/Makefile b/benchmarks/Makefile
index 7d54c0a..2fc20fe 100644
--- a/benchmarks/Makefile
+++ b/benchmarks/Makefile
@@ -9,9 +9,9 @@ CFLAGS = -O3 -finline-functions -funroll-loops -Werror
 
 LFLAGS = -lm
 
-JNEURALDIR = ../libraries/jneural/
+JNEURALDIR = ../../libraries/jneural/
 
-LWNNDIR = ../libraries/lwneuralnet-0.6/source/
+LWNNDIR = ../../libraries/lwneuralnet-0.6/source/
 
 all: $(TARGETS)
 
diff --git a/examples/cascade_train.c b/examples/cascade_train.c
index 06a7be4..324a18c 100644
--- a/examples/cascade_train.c
+++ b/examples/cascade_train.c
@@ -32,10 +32,10 @@ int FANN_API print_callback(struct fann *ann, struct fann_train_data *train,
 	float mse1, mse2;
 
 	mse2 = fann_test_data(ann, test_data);
-	bit2 = ann->num_bit_fail;
+	bit2 = fann_get_bit_fail(ann);
 
 	mse1 = fann_test_data(ann, train);
-	bit1 = ann->num_bit_fail;
+	bit1 = fann_get_bit_fail(ann);
 
 	printf("Nerons     %4d. Epochs: %7d ", 
 		fann_get_total_neurons(ann)-(fann_get_num_input(ann)+fann_get_num_output(ann)), epochs);
@@ -48,7 +48,6 @@ int main()
 	const float desired_error = (const float) 0.001;
 	unsigned int max_neurons = 40;
 	unsigned int neurons_between_reports = 1;
-	struct fann_train_data *test = NULL;
 
 	printf("Reading data.\n");
 
@@ -102,7 +101,7 @@ int main()
 
 	printf("Creating network.\n");
 
-	ann = fann_create_shortcut(2, train_data->num_input, train_data->num_output);
+	ann = fann_create_shortcut(2, fann_num_input_train_data(train_data), fann_num_input_train_data(train_data));
 
 	fann_set_training_algorithm(ann, FANN_TRAIN_BATCH);
 	fann_set_training_algorithm(ann, FANN_TRAIN_QUICKPROP);
@@ -121,8 +120,10 @@ int main()
 	fann_set_rprop_delta_min(ann, 0.0);
 	fann_set_rprop_delta_max(ann, 50.0);
 
-	fann_set_cascade_change_fraction(ann, 0.01);
-	fann_set_cascade_stagnation_epochs(ann, 12);
+	fann_set_cascade_output_change_fraction(ann, 0.01);
+	fann_set_cascade_output_stagnation_epochs(ann, 12);
+	fann_set_cascade_candidate_change_fraction(ann, 0.01);
+	fann_set_cascade_candidate_stagnation_epochs(ann, 12);
 	fann_set_cascade_weight_multiplier(ann, 0.4);
  	fann_set_cascade_candidate_limit(ann, 1000.0);
 	fann_set_cascade_max_out_epochs(ann, 150);
diff --git a/examples/xor_train.c b/examples/xor_train.c
index 5bb476d..44c4131 100644
--- a/examples/xor_train.c
+++ b/examples/xor_train.c
@@ -36,9 +36,9 @@ int main()
 	const unsigned int num_output = 1;
 	const unsigned int num_layers = 3;
 	const unsigned int num_neurons_hidden = 3;
-	const float desired_error = (const float) 0.00001;
-	const unsigned int max_epochs = 100000;
-	const unsigned int epochs_between_reports = 1000;
+	const float desired_error = (const float) 0;
+	const unsigned int max_epochs = 1000;
+	const unsigned int epochs_between_reports = 10;
 	struct fann *ann;
 	struct fann_train_data *data;
 
@@ -55,16 +55,14 @@ int main()
 
 	fann_set_activation_steepness_hidden(ann, 1);
 	fann_set_activation_steepness_output(ann, 1);
-	fann_set_rprop_delta_max(ann, 50);
 
 	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
 	fann_set_activation_function_output(ann, FANN_GAUSSIAN_SYMMETRIC);
 
-	fann_init_weights(ann, data);
+	fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
+	fann_set_bit_fail_limit(ann, 0.1);
 
-	/*fann_set_training_algorithm(ann, FANN_TRAIN_QUICKPROP); */
-	
-	fann_set_callback(ann, test_callback);
+	fann_init_weights(ann, data);
 	
 	fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error);
 
diff --git a/src/fann.c b/src/fann.c
index 3fccdb6..404d7c6 100644
--- a/src/fann.c
+++ b/src/fann.c
@@ -958,36 +958,38 @@ FANN_EXTERNAL void FANN_API fann_print_parameters(struct fann *ann)
 				   layer_it->last_neuron - layer_it->first_neuron - 1);
 		}
 	}
-	printf("Output layer               :%4d neurons\n", ann->num_output);
-	printf("Total neurons and biases   :%4d\n", fann_get_total_neurons(ann));
-	printf("Total connections          :%4d\n", ann->total_connections);
-	printf("Connection rate            :  %5.2f\n", ann->connection_rate);
-	printf("Shortcut connections       :%4d\n", ann->shortcut_connections);
+	printf("Output layer                         :%4d neurons\n", ann->num_output);
+	printf("Total neurons and biases             :%4d\n", fann_get_total_neurons(ann));
+	printf("Total connections                    :%4d\n", ann->total_connections);
+	printf("Connection rate                      :  %5.2f\n", ann->connection_rate);
+	printf("Shortcut connections                 :%4d\n", ann->shortcut_connections);
 #ifdef FIXEDFANN
-	printf("Decimal point              :%4d\n", ann->decimal_point);
-	printf("Multiplier                 :%4d\n", ann->multiplier);
+	printf("Decimal point                        :%4d\n", ann->decimal_point);
+	printf("Multiplier                           :%4d\n", ann->multiplier);
 #else
-	printf("Training algorithm         :   %s\n", FANN_TRAIN_NAMES[ann->training_algorithm]);
-	printf("Training error function    :   %s\n", FANN_ERRORFUNC_NAMES[ann->train_error_function]);
-	printf("Training stop function     :   %s\n", FANN_STOPFUNC_NAMES[ann->train_stop_function]);
+	printf("Training algorithm                   :   %s\n", FANN_TRAIN_NAMES[ann->training_algorithm]);
+	printf("Training error function              :   %s\n", FANN_ERRORFUNC_NAMES[ann->train_error_function]);
+	printf("Training stop function               :   %s\n", FANN_STOPFUNC_NAMES[ann->train_stop_function]);
 #endif
 #ifdef FIXEDFANN
-	printf("Bit fail limit             :%4d\n", ann->bit_fail_limit);
+	printf("Bit fail limit                       :%4d\n", ann->bit_fail_limit);
 #else
-	printf("Learning rate              :  %5.2f\n", ann->learning_rate);
-	printf("Learning momentum          :  %5.2f\n", ann->learning_momentum);
-	printf("Quickprop decay            :  %9.6f\n", ann->quickprop_decay);
-	printf("Quickprop mu               :  %5.2f\n", ann->quickprop_mu);
-	printf("RPROP increase factor      :  %5.2f\n", ann->rprop_increase_factor);
-	printf("RPROP decrease factor      :  %5.2f\n", ann->rprop_decrease_factor);
-	printf("RPROP delta min            :  %5.2f\n", ann->rprop_delta_min);
-	printf("RPROP delta max            :  %5.2f\n", ann->rprop_delta_max);
-	printf("Cascade change fraction    :  %9.6f\n", ann->cascade_change_fraction);
-	printf("Cascade weight multiplier  :  %9.6f\n", ann->cascade_weight_multiplier);
-	printf("Cascade candidate limit    :  %9.6f\n", ann->cascade_candidate_limit);
-	printf("Cascade stagnation epochs  :%4d\n", ann->cascade_stagnation_epochs);
-	printf("Cascade max output epochs  :%4d\n", ann->cascade_max_out_epochs);
-	printf("Cascade max cand epochs    :%4d\n", ann->cascade_max_cand_epochs);
+	printf("Learning rate                        :  %5.2f\n", ann->learning_rate);
+	printf("Learning momentum                    :  %5.2f\n", ann->learning_momentum);
+	printf("Quickprop decay                      :  %9.6f\n", ann->quickprop_decay);
+	printf("Quickprop mu                         :  %5.2f\n", ann->quickprop_mu);
+	printf("RPROP increase factor                :  %5.2f\n", ann->rprop_increase_factor);
+	printf("RPROP decrease factor                :  %5.2f\n", ann->rprop_decrease_factor);
+	printf("RPROP delta min                      :  %5.2f\n", ann->rprop_delta_min);
+	printf("RPROP delta max                      :  %5.2f\n", ann->rprop_delta_max);
+	printf("Cascade output change fraction       :  %9.6f\n", ann->cascade_output_change_fraction);
+	printf("Cascade candidate change fraction    :  %9.6f\n", ann->cascade_candidate_change_fraction);
+	printf("Cascade output stagnation epochs     :%4d\n", ann->cascade_output_stagnation_epochs);
+	printf("Cascade candidate stagnation epochs  :%4d\n", ann->cascade_candidate_stagnation_epochs);
+	printf("Cascade max output epochs            :%4d\n", ann->cascade_max_out_epochs);
+	printf("Cascade max candidate epochs         :%4d\n", ann->cascade_max_cand_epochs);
+	printf("Cascade weight multiplier            :  %9.6f\n", ann->cascade_weight_multiplier);
+	printf("Cascade candidate limit              :  %9.6f\n", ann->cascade_candidate_limit);
 	for(i = 0; i < ann->cascade_activation_functions_count; i++)
 		printf("Cascade activation func[%d] :   %s\n", i,
 			FANN_ACTIVATIONFUNC_NAMES[ann->cascade_activation_functions[i]]);
@@ -1123,8 +1125,10 @@ struct fann *fann_allocate_structure(unsigned int num_layers)
 	ann->callback = NULL;
 
 	/* variables used for cascade correlation (reasonable defaults) */
-	ann->cascade_change_fraction = 0.01;
-	ann->cascade_stagnation_epochs = 12;
+	ann->cascade_output_change_fraction = 0.01;
+	ann->cascade_candidate_change_fraction = 0.01;
+	ann->cascade_output_stagnation_epochs = 12;
+	ann->cascade_candidate_stagnation_epochs = 12;
 	ann->cascade_num_candidate_groups = 2;
 	ann->cascade_weight_multiplier = 0.4;
 	ann->cascade_candidate_limit = 1000.0;
diff --git a/src/fann_cascade.c b/src/fann_cascade.c
index 7cf62d7..bb94c9a 100644
--- a/src/fann_cascade.c
+++ b/src/fann_cascade.c
@@ -59,7 +59,7 @@ void fann_print_connections_raw(struct fann *ann)
    The connected_neurons pointers are not valid during training,
    but they will be again after training.
  */
-void fann_cascadetrain_on_data(struct fann *ann, struct fann_train_data *data,
+FANN_EXTERNAL void FANN_API fann_cascadetrain_on_data(struct fann *ann, struct fann_train_data *data,
 										unsigned int max_neurons,
 										unsigned int neurons_between_reports,
 										float desired_error)
@@ -164,6 +164,21 @@ void fann_cascadetrain_on_data(struct fann *ann, struct fann_train_data *data,
 	fann_set_shortcut_connections(ann);
 }
 
+FANN_EXTERNAL void FANN_API fann_cascadetrain_on_file(struct fann *ann, const char *filename,
+													  unsigned int max_neurons,
+													  unsigned int neurons_between_reports,
+													  float desired_error)
+{
+	struct fann_train_data *data = fann_read_train_from_file(filename);
+
+	if(data == NULL)
+	{
+		return;
+	}
+	fann_cascadetrain_on_data(ann, data, max_neurons, neurons_between_reports, desired_error);
+	fann_destroy_train(data);
+}
+
 int fann_train_outputs(struct fann *ann, struct fann_train_data *data, float desired_error)
 {
 	float error, initial_error, error_improvement;
@@ -205,9 +220,9 @@ int fann_train_outputs(struct fann *ann, struct fann_train_data *data, float des
 		{
 			/*printf("error_improvement=%f, target_improvement=%f, backslide_improvement=%f, stagnation=%d\n", error_improvement, target_improvement, backslide_improvement, stagnation); */
 
-			target_improvement = error_improvement * (1.0 + ann->cascade_change_fraction);
-			backslide_improvement = error_improvement * (1.0 - ann->cascade_change_fraction);
-			stagnation = i + ann->cascade_stagnation_epochs;
+			target_improvement = error_improvement * (1.0 + ann->cascade_output_change_fraction);
+			backslide_improvement = error_improvement * (1.0 - ann->cascade_output_change_fraction);
+			stagnation = i + ann->cascade_output_stagnation_epochs;
 		}
 
 		/* No improvement in allotted period, so quit */
@@ -500,8 +515,10 @@ int fann_train_candidates(struct fann *ann, struct fann_train_data *data)
 
 		if(best_cand_score / ann->MSE_value > ann->cascade_candidate_limit)
 		{
+#ifdef CASCADE_DEBUG
 			printf("above candidate limit %f/%f > %f", best_cand_score, ann->MSE_value,
 				   ann->cascade_candidate_limit);
+#endif
 			return i + 1;
 		}
 
@@ -513,9 +530,9 @@ int fann_train_candidates(struct fann *ann, struct fann_train_data *data)
 			/* printf("best_cand_score=%f, target_cand_score=%f, backslide_cand_score=%f, stagnation=%d\n", best_cand_score, target_cand_score, backslide_cand_score, stagnation); */
 #endif
 
-			target_cand_score = best_cand_score * (1.0 + ann->cascade_change_fraction);
-			backslide_cand_score = best_cand_score * (1.0 - ann->cascade_change_fraction);
-			stagnation = i + ann->cascade_stagnation_epochs;
+			target_cand_score = best_cand_score * (1.0 + ann->cascade_candidate_change_fraction);
+			backslide_cand_score = best_cand_score * (1.0 - ann->cascade_candidate_change_fraction);
+			stagnation = i + ann->cascade_candidate_stagnation_epochs;
 		}
 
 		/* No improvement in allotted period, so quit */
@@ -954,8 +971,10 @@ FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidates(struct fann
 		ann->cascade_num_candidate_groups;
 }
 
-FANN_GET_SET(float, cascade_change_fraction)
-FANN_GET_SET(unsigned int, cascade_stagnation_epochs)
+FANN_GET_SET(float, cascade_output_change_fraction)
+FANN_GET_SET(unsigned int, cascade_output_stagnation_epochs)
+FANN_GET_SET(float, cascade_candidate_change_fraction)
+FANN_GET_SET(unsigned int, cascade_candidate_stagnation_epochs)
 FANN_GET_SET(unsigned int, cascade_num_candidate_groups)
 FANN_GET_SET(fann_type, cascade_weight_multiplier)
 FANN_GET_SET(fann_type, cascade_candidate_limit)
diff --git a/src/fann_io.c b/src/fann_io.c
index 5487434..42d2094 100644
--- a/src/fann_io.c
+++ b/src/fann_io.c
@@ -271,7 +271,7 @@ int fann_save_internal_fd(struct fann *ann, FILE * conf, const char *configurati
 /* INTERNAL FUNCTION
    Save the train data structure.
  */
-void fann_save_train_internal(struct fann_train_data *data, char *filename,
+void fann_save_train_internal(struct fann_train_data *data, const char *filename,
 							  unsigned int save_as_fixed, unsigned int decimal_point)
 {
 	FILE *file = fopen(filename, "w");
@@ -288,7 +288,7 @@ void fann_save_train_internal(struct fann_train_data *data, char *filename,
 /* INTERNAL FUNCTION
    Save the train data structure.
  */
-void fann_save_train_internal_fd(struct fann_train_data *data, FILE * file, char *filename,
+void fann_save_train_internal_fd(struct fann_train_data *data, FILE * file, const char *filename,
 								 unsigned int save_as_fixed, unsigned int decimal_point)
 {
 	unsigned int num_data = data->num_data;
diff --git a/src/fann_train_data.c b/src/fann_train_data.c
index 0432c1b..1de8d0f 100644
--- a/src/fann_train_data.c
+++ b/src/fann_train_data.c
@@ -28,7 +28,7 @@
 /*
  * Reads training data from a file. 
  */
-FANN_EXTERNAL struct fann_train_data *FANN_API fann_read_train_from_file(char *configuration_file)
+FANN_EXTERNAL struct fann_train_data *FANN_API fann_read_train_from_file(const char *configuration_file)
 {
 	struct fann_train_data *data;
 	FILE *file = fopen(configuration_file, "r");
@@ -47,7 +47,7 @@ FANN_EXTERNAL struct fann_train_data *FANN_API fann_read_train_from_file(char *c
 /*
  * Save training data to a file 
  */
-FANN_EXTERNAL void FANN_API fann_save_train(struct fann_train_data *data, char *filename)
+FANN_EXTERNAL void FANN_API fann_save_train(struct fann_train_data *data, const char *filename)
 {
 	fann_save_train_internal(data, filename, 0, 0);
 }
@@ -56,7 +56,7 @@ FANN_EXTERNAL void FANN_API fann_save_train(struct fann_train_data *data, char *
  * Save training data to a file in fixed point algebra. (Good for testing
  * a network in fixed point) 
  */
-FANN_EXTERNAL void FANN_API fann_save_train_to_fixed(struct fann_train_data *data, char *filename,
+FANN_EXTERNAL void FANN_API fann_save_train_to_fixed(struct fann_train_data *data, const char *filename,
 													 unsigned int decimal_point)
 {
 	fann_save_train_internal(data, filename, 1, decimal_point);
@@ -69,8 +69,10 @@ FANN_EXTERNAL void FANN_API fann_destroy_train(struct fann_train_data *data)
 {
 	if(data == NULL)
 		return;
-	fann_safe_free(data->input[0]);
-	fann_safe_free(data->output[0]);
+	if(data->input != NULL)
+		fann_safe_free(data->input[0]);
+	if(data->output != NULL)
+		fann_safe_free(data->output[0]);
 	fann_safe_free(data->input);
 	fann_safe_free(data->output);
 	fann_safe_free(data);
@@ -259,7 +261,7 @@ FANN_EXTERNAL void FANN_API fann_train_on_data(struct fann *ann, struct fann_tra
 	}
 }
 
-FANN_EXTERNAL void FANN_API fann_train_on_file(struct fann *ann, char *filename,
+FANN_EXTERNAL void FANN_API fann_train_on_file(struct fann *ann, const char *filename,
 											   unsigned int max_epochs,
 											   unsigned int epochs_between_reports,
 											   float desired_error)
@@ -628,7 +630,7 @@ FANN_EXTERNAL unsigned int FANN_API fann_num_output_train_data(struct fann_train
 /*
  * INTERNAL FUNCTION Reads training data from a file descriptor. 
  */
-struct fann_train_data *fann_read_train_from_fd(FILE * file, char *filename)
+struct fann_train_data *fann_read_train_from_fd(FILE * file, const char *filename)
 {
 	unsigned int num_input, num_output, num_data, i, j;
 	unsigned int line = 1;
@@ -728,11 +730,11 @@ int fann_desired_error_reached(struct fann *ann, float desired_error)
 	switch (ann->train_stop_function)
 	{
 	case FANN_STOPFUNC_MSE:
-		if(fann_get_MSE(ann) < desired_error)
+		if(fann_get_MSE(ann) <= desired_error)
 			return 0;
 		break;
 	case FANN_STOPFUNC_BIT:
-		if(ann->num_bit_fail < desired_error)
+		if(ann->num_bit_fail <= (unsigned int)desired_error)
 			return 0;
 		break;
 	}
diff --git a/src/include/fann.h b/src/include/fann.h
index 93e6be0..f12c82d 100644
--- a/src/include/fann.h
+++ b/src/include/fann.h
@@ -305,10 +305,12 @@ FANN_EXTERNAL void FANN_API fann_init_weights(struct fann *ann, struct fann_trai
 	of the ann.
 
 	The output from fann_print_connections on a small (2 2 1) network trained on the xor problem
-	> Layer / Neuron 012345
-	> L   1 / N    3 ddb...
-	> L   1 / N    4 bbb...
-	> L   2 / N    6 ...cda
+	>Layer / Neuron 012345
+	>L   1 / N    3 BBa...
+	>L   1 / N    4 BBA...
+	>L   1 / N    5 ......
+	>L   2 / N    6 ...BBA
+	>L   2 / N    7 ......
 		  
 	This network have five real neurons and two bias neurons. This gives a total of seven neurons 
 	named from 0 to 6. The connections between these neurons can be seen in the matrix. "." is a 
@@ -316,7 +318,7 @@ FANN_EXTERNAL void FANN_API fann_init_weights(struct fann *ann, struct fann_trai
 	scale from a-z. The two real neurons in the hidden layer (neuron 3 and 4 in layer 1) has 
 	connection from the three neurons in the previous layer as is visible in the first two lines. 
 	The output neuron (6) has connections form the three neurons in the hidden layer 3 - 5 as is 
-	visible in the last line.
+	visible in the fourth line.
 
 	To simplify the matrix output neurons is not visible as neurons that connections can come from, 
 	and input and bias neurons are not visible as neurons that connections can go to.
diff --git a/src/include/fann_cascade.h b/src/include/fann_cascade.h
index 4fd1ded..31ebfc7 100644
--- a/src/include/fann_cascade.h
+++ b/src/include/fann_cascade.h
@@ -21,116 +21,353 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #define __fann_cascade_h__
 
 /* Section: FANN Cascade Training
-   test info about cascade training
+   Cascade training differs from ordinary training in the sense that it starts with an empty neural network
+   and then adds neurons one by one, while it trains the neural network. The main benefit of this approach,
+   is that you do not have to guess the number of hidden layers and neurons prior to training, but cascade 
+   training have also proved better at solving some problems.
+   
+   The basic idea of cascade training is that a number of candidate neurons are trained separate from the 
+   real network, then the most promissing of these candidate neurons is inserted into the neural network. 
+   Then the output connections are trained and new candidate neurons is prepared. The candidate neurons are 
+   created as shorcut connected neurons in a new hidden layer, which means that the final neural network
+   will consist of a number of hidden layers with one shorcut connected neuron in each.
 */
 
 /* Group: Cascade Training */
 
 /* Function: fann_cascadetrain_on_data
+
+   Trains on an entire dataset, for a period of time using the Cascade2 training algorithm.
+   This algorithm adds neurons to the neural network while training, which means that it
+   needs to start with an ANN without any hidden layers. The neural network should also use
+   shortcut connections, so <fann_create_shortcut> should be used to create the ANN like this:
+   >struct fann *ann = fann_create_shortcut(2, fann_num_input_train_data(train_data), fann_num_input_train_data(train_data));
+   
+   This training uses the parameters set using the fann_set_cascade_..., but it also uses another
+   training algorithm as it's internal training algorithm. This algorithm can be set to either
+   FANN_TRAIN_RPROP or FANN_TRAIN_QUICKPROP by <fann_set_training_algorithm>, and the parameters 
+   set for these training algorithms will also affect the cascade training.
+   
+   Parameters:
+   		ann - The neural network
+   		data - The data, which should be used during training
+   		max_neuron - The maximum number of neurons to be added to neural network
+   		neurons_between_reports - The number of neurons between printing a status report to stdout.
+   			A value of zero means no reports should be printed.
+   		desired_error - The desired <fann_get_MSE> or <fann_get_bit_fail>, depending on which stop function
+   			is chosen by <fann_set_train_stop_function>.
+
+	Instead of printing out reports every neurons_between_reports, a callback function can be called 
+	(see <fann_set_callback>).
+	
+	See also:
+		<fann_train_on_data>, <fann_cascadetrain_on_file>, <Parameters>
+
+	This function appears in FANN >= 2.0.0. 
 */
-FANN_EXTERNAL void fann_cascadetrain_on_data(struct fann *ann,
+FANN_EXTERNAL void FANN_API fann_cascadetrain_on_data(struct fann *ann,
 													  struct fann_train_data *data,
 													  unsigned int max_neurons,
 													  unsigned int neurons_between_reports,
 													  float desired_error);
 
+/* Function: fann_cascadetrain_on_file
+   
+   Does the same as <fann_cascadetrain_on_data>, but reads the training data directly from a file.
+   
+   See also:
+   		<fann_cascadetrain_on_data>
+
+	This function appears in FANN >= 2.0.0.
+*/ 
+FANN_EXTERNAL void FANN_API fann_cascadetrain_on_file(struct fann *ann, const char *filename,
+													  unsigned int max_neurons,
+													  unsigned int neurons_between_reports,
+													  float desired_error);
+
 /* Group: Parameters */
 													  
-/* Function: fann_get_cascade_num_candidates
+/* Function: fann_get_cascade_output_change_fraction
+
+   The cascade output change fraction is a number between 0 and 1 determining how large a fraction
+   the <fann_get_MSE> value should change within <fann_get_cascade_output_stagnation_epochs> during
+   training of the output connections, in order for the training not to stagnate. If the training 
+   stagnates, the training of the output connections will be ended and new candidates will be prepared.
+   
+   This means:
+   If the MSE does not change by a fraction of <fann_get_cascade_output_change_fraction> during a 
+   period of <fann_get_cascade_output_stagnation_epochs>, the training of the output connections
+   is stopped because the training has stagnated.
+
+   If the cascade output change fraction is low, the output connections will be trained more and if the
+   fraction is high they will be trained less.
+   
+   The default cascade output change fraction is 0.01, which is equalent to a 1% change in MSE.
+
+   See also:
+   		<fann_set_cascade_output_change_fraction>, <fann_get_MSE>, <fann_get_cascade_output_stagnation_epochs>
+
+	This function appears in FANN >= 2.0.0.
+ */
+FANN_EXTERNAL float FANN_API fann_get_cascade_output_change_fraction(struct fann *ann);
 
-   The number of candidates (calculated from cascade_activation_functions_count,
-   cascade_activation_steepnesses_count and cascade_num_candidate_groups). 
- */ 
-FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidates(struct fann *ann);
 
-/* Function: fann_get_cascade_change_fraction
+/* Function: fann_set_cascade_output_change_fraction
+
+   Sets the cascade output change fraction.
+   
+   See also:
+   		<fann_get_cascade_output_change_fraction>
+
+	This function appears in FANN >= 2.0.0.
  */
-FANN_EXTERNAL float FANN_API fann_get_cascade_change_fraction(struct fann *ann);
+FANN_EXTERNAL void FANN_API fann_set_cascade_output_change_fraction(struct fann *ann, 
+															 float cascade_output_change_fraction);
+
+/* Function: fann_get_cascade_output_stagnation_epochs
+
+   The number of cascade output stagnation epochs determines the number of epochs training is allowed to
+   continue without changing the MSE by a fraction of <fann_get_cascade_output_change_fraction>.
+   
+   See more info about this parameter in <fann_get_cascade_output_change_fraction>.
+   
+   The default number of cascade output stagnation epochs is 12.
 
+   See also:
+   		<fann_set_cascade_output_stagnation_epochs>, <fann_get_cascade_output_change_fraction>
 
-/* Function: fann_set_cascade_change_fraction
+	This function appears in FANN >= 2.0.0.
  */
-FANN_EXTERNAL void FANN_API fann_set_cascade_change_fraction(struct fann *ann, 
-															 float cascade_change_fraction);
+FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_output_stagnation_epochs(struct fann *ann);
+
+
+/* Function: fann_set_cascade_output_stagnation_epochs
+
+   Sets the number of cascade output stagnation epochs.
+   
+   See also:
+   		<fann_get_cascade_output_stagnation_epochs>
 
-/* Function: fann_get_cascade_stagnation_epochs
+	This function appears in FANN >= 2.0.0.
  */
-FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_stagnation_epochs(struct fann *ann);
+FANN_EXTERNAL void FANN_API fann_set_cascade_output_stagnation_epochs(struct fann *ann, 
+															 unsigned int cascade_output_stagnation_epochs);
 
 
-/* Function: fann_set_cascade_stagnation_epochs
+/* Function: fann_get_cascade_candidate_change_fraction
+
+   The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction
+   the <fann_get_MSE> value should change within <fann_get_cascade_candidate_stagnation_epochs> during
+   training of the candidate neurons, in order for the training not to stagnate. If the training 
+   stagnates, the training of the candidate neurons will be ended and the best candidate will be selected.
+   
+   This means:
+   If the MSE does not change by a fraction of <fann_get_cascade_candidate_change_fraction> during a 
+   period of <fann_get_cascade_candidate_stagnation_epochs>, the training of the candidate neurons
+   is stopped because the training has stagnated.
+
+   If the cascade candidate change fraction is low, the candidate neurons will be trained more and if the
+   fraction is high they will be trained less.
+   
+   The default cascade candidate change fraction is 0.01, which is equalent to a 1% change in MSE.
+
+   See also:
+   		<fann_set_cascade_candidate_change_fraction>, <fann_get_MSE>, <fann_get_cascade_candidate_stagnation_epochs>
+
+	This function appears in FANN >= 2.0.0.
  */
-FANN_EXTERNAL void FANN_API fann_set_cascade_stagnation_epochs(struct fann *ann, 
-															 unsigned int cascade_stagnation_epochs);
+FANN_EXTERNAL float FANN_API fann_get_cascade_candidate_change_fraction(struct fann *ann);
 
 
-/* Function: fann_get_cascade_num_candidate_groups
+/* Function: fann_set_cascade_candidate_change_fraction
+
+   Sets the cascade candidate change fraction.
+   
+   See also:
+   		<fann_get_cascade_candidate_change_fraction>
+
+	This function appears in FANN >= 2.0.0.
  */
-FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidate_groups(struct fann *ann);
+FANN_EXTERNAL void FANN_API fann_set_cascade_candidate_change_fraction(struct fann *ann, 
+															 float cascade_candidate_change_fraction);
 
+/* Function: fann_get_cascade_candidate_stagnation_epochs
 
-/* Function: fann_set_cascade_num_candidate_groups
+   The number of cascade candidate stagnation epochs determines the number of epochs training is allowed to
+   continue without changing the MSE by a fraction of <fann_get_cascade_candidate_change_fraction>.
+   
+   See more info about this parameter in <fann_get_cascade_candidate_change_fraction>.
+
+   The default number of cascade candidate stagnation epochs is 12.
+
+   See also:
+   		<fann_set_cascade_candidate_stagnation_epochs>, <fann_get_cascade_candidate_change_fraction>
+
+	This function appears in FANN >= 2.0.0.
  */
-FANN_EXTERNAL void FANN_API fann_set_cascade_num_candidate_groups(struct fann *ann, 
-															 unsigned int cascade_num_candidate_groups);
+FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_candidate_stagnation_epochs(struct fann *ann);
+
+
+/* Function: fann_set_cascade_candidate_stagnation_epochs
+
+   Sets the number of cascade candidate stagnation epochs.
+   
+   See also:
+   		<fann_get_cascade_candidate_stagnation_epochs>
+
+	This function appears in FANN >= 2.0.0.
+ */
+FANN_EXTERNAL void FANN_API fann_set_cascade_candidate_stagnation_epochs(struct fann *ann, 
+															 unsigned int cascade_candidate_stagnation_epochs);
 
 
 /* Function: fann_get_cascade_weight_multiplier
+
+   The weight multiplier is a parameter which is used to multiply the weights from the candidate neuron
+   before adding the neuron to the neural network. This parameter is usually between 0 and 1, and is used
+   to make the training a bit less aggressive.
+
+   The default weight multiplier is 0.4
+
+   See also:
+   		<fann_set_cascade_weight_multiplier>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL fann_type FANN_API fann_get_cascade_weight_multiplier(struct fann *ann);
 
 
 /* Function: fann_set_cascade_weight_multiplier
+   
+   Sets the weight multiplier.
+   
+   See also:
+   		<fann_get_cascade_weight_multiplier>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL void FANN_API fann_set_cascade_weight_multiplier(struct fann *ann, 
 															 fann_type cascade_weight_multiplier);
 
 
 /* Function: fann_get_cascade_candidate_limit
+
+   The candidate limit is a limit for how much the candidate neuron may be trained.
+   The limit is a limit on the proportion between the MSE and candidate score.
+   
+   Set this to a lower value to avoid overfitting and to a higher if overfitting is
+   not a problem.
+   
+   The default candidate limit is 1000.0
+
+   See also:
+   		<fann_set_cascade_candidate_limit>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL fann_type FANN_API fann_get_cascade_candidate_limit(struct fann *ann);
 
 
 /* Function: fann_set_cascade_candidate_limit
+
+   Sets the candidate limit.
+  
+   See also:
+   		<fann_get_cascade_candidate_limit>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL void FANN_API fann_set_cascade_candidate_limit(struct fann *ann, 
 															 fann_type cascade_candidate_limit);
 
 
 /* Function: fann_get_cascade_max_out_epochs
+
+   The maximum out epochs determines the maximum number of epochs the output connections
+   may be trained after adding a new candidate neuron.
+   
+   The default
+
+   See also:
+   		<fann_set_cascade_max_out_epochs>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_max_out_epochs(struct fann *ann);
 
 
 /* Function: fann_set_cascade_max_out_epochs
+
+   See also:
+   		<fann_get_cascade_max_out_epochs>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL void FANN_API fann_set_cascade_max_out_epochs(struct fann *ann, 
 															 unsigned int cascade_max_out_epochs);
 
 
 /* Function: fann_get_cascade_max_cand_epochs
+
+   See also:
+   		<fann_set_cascade_max_cand_epochs>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_max_cand_epochs(struct fann *ann);
 
 
 /* Function: fann_set_cascade_max_cand_epochs
+
+   See also:
+   		<fann_get_cascade_max_cand_epochs>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL void FANN_API fann_set_cascade_max_cand_epochs(struct fann *ann, 
 															 unsigned int cascade_max_cand_epochs);
 
 
+/* Function: fann_get_cascade_num_candidates
+
+   The number of candidates used during training (calculated from cascade_activation_functions_count,
+   cascade_activation_steepnesses_count and cascade_num_candidate_groups). 
+
+   See also:
+   		<fann_get_cascade_activation_functions_count>, <fann_get_cascade_activation_steepnesses_count>,
+   		<fann_get_cascade_num_candidate_groups>
+
+	This function appears in FANN >= 2.0.0.
+ */ 
+FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidates(struct fann *ann);
+
 /* Function: fann_get_cascade_activation_functions_count
+
+   See also:
+   		<fann_get_cascade_activation_functions>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_activation_functions_count(struct fann *ann);
 
 
 /* Function: fann_get_cascade_activation_functions
+
+   See also:
+   		<fann_get_cascade_activation_functions_count>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL enum fann_activationfunc_enum * FANN_API fann_get_cascade_activation_functions(
 															struct fann *ann);
 
 
 /* Function: fann_set_cascade_activation_functions
+
+   See also:
+   		<fann_get_cascade_activation_steepnesses_count>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL void fann_set_cascade_activation_functions(struct fann *ann,
 														 enum fann_activationfunc_enum *
@@ -140,16 +377,31 @@ FANN_EXTERNAL void fann_set_cascade_activation_functions(struct fann *ann,
 
 
 /* Function: fann_get_cascade_activation_steepnesses_count
+
+   See also:
+   		<fann_set_cascade_activation_functions>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_activation_steepnesses_count(struct fann *ann);
 
 
 /* Function: fann_get_cascade_activation_steepnesses
+
+   See also:
+   		<fann_set_cascade_activation_steepnesses>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL fann_type * FANN_API fann_get_cascade_activation_steepnesses(struct fann *ann);
 																
 
 /* Function: fann_set_cascade_activation_steepnesses
+
+   See also:
+   		<fann_get_cascade_activation_steepnesses>
+
+	This function appears in FANN >= 2.0.0.
  */
 FANN_EXTERNAL void fann_set_cascade_activation_steepnesses(struct fann *ann,
 														   fann_type *
@@ -157,4 +409,25 @@ FANN_EXTERNAL void fann_set_cascade_activation_steepnesses(struct fann *ann,
 														   unsigned int 
 														   cascade_activation_steepnesses_count);
 
+/* Function: fann_get_cascade_num_candidate_groups
+
+   See also:
+   		<fann_set_cascade_num_candidate_groups>
+
+	This function appears in FANN >= 2.0.0.
+ */
+FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidate_groups(struct fann *ann);
+
+
+/* Function: fann_set_cascade_num_candidate_groups
+
+   See also:
+   		<fann_get_cascade_num_candidate_groups>
+
+	This function appears in FANN >= 2.0.0.
+ */
+FANN_EXTERNAL void FANN_API fann_set_cascade_num_candidate_groups(struct fann *ann, 
+															 unsigned int cascade_num_candidate_groups);
+
+
 #endif
diff --git a/src/include/fann_data.h b/src/include/fann_data.h
index 4744ce7..65ec36c 100644
--- a/src/include/fann_data.h
+++ b/src/include/fann_data.h
@@ -531,12 +531,23 @@ struct fann
 	 * fraction of its old value to count as a
 	 * significant change.
 	 */
-	float cascade_change_fraction;
+	float cascade_output_change_fraction;
 
 	/* No change in this number of epochs will cause
 	 * stagnation.
 	 */
-	unsigned int cascade_stagnation_epochs;
+	unsigned int cascade_output_stagnation_epochs;
+
+	/* The error must change by at least this
+	 * fraction of its old value to count as a
+	 * significant change.
+	 */
+	float cascade_candidate_change_fraction;
+
+	/* No change in this number of epochs will cause
+	 * stagnation.
+	 */
+	unsigned int cascade_candidate_stagnation_epochs;
 
 	/* The current best candidate, which will be installed.
 	 */
diff --git a/src/include/fann_internal.h b/src/include/fann_internal.h
index 1d900f6..ad0835b 100644
--- a/src/include/fann_internal.h
+++ b/src/include/fann_internal.h
@@ -63,9 +63,9 @@ int fann_save_internal(struct fann *ann, const char *configuration_file,
 					   unsigned int save_as_fixed);
 int fann_save_internal_fd(struct fann *ann, FILE * conf, const char *configuration_file,
 						  unsigned int save_as_fixed);
-void fann_save_train_internal(struct fann_train_data *data, char *filename,
+void fann_save_train_internal(struct fann_train_data *data, const char *filename,
 							  unsigned int save_as_fixed, unsigned int decimal_point);
-void fann_save_train_internal_fd(struct fann_train_data *data, FILE * file, char *filename,
+void fann_save_train_internal_fd(struct fann_train_data *data, FILE * file, const char *filename,
 								 unsigned int save_as_fixed, unsigned int decimal_point);
 
 void fann_seed_rand();
@@ -76,7 +76,7 @@ void fann_error(struct fann_error *errdat, const enum fann_errno_enum errno_f, .
 void fann_init_error_data(struct fann_error *errdat);
 
 struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file);
-struct fann_train_data *fann_read_train_from_fd(FILE * file, char *filename);
+struct fann_train_data *fann_read_train_from_fd(FILE * file, const char *filename);
 
 void fann_compute_MSE(struct fann *ann, fann_type * desired_output);
 void fann_update_output_weights(struct fann *ann);
diff --git a/src/include/fann_train.h b/src/include/fann_train.h
index 34261d8..3a78183 100644
--- a/src/include/fann_train.h
+++ b/src/include/fann_train.h
@@ -187,7 +187,7 @@ FANN_EXTERNAL void FANN_API fann_train_on_data(struct fann *ann, struct fann_tra
 
 	This function appears in FANN >= 1.0.0.
 */ 
-FANN_EXTERNAL void FANN_API fann_train_on_file(struct fann *ann, char *filename,
+FANN_EXTERNAL void FANN_API fann_train_on_file(struct fann *ann, const char *filename,
 											   unsigned int max_epochs,
 											   unsigned int epochs_between_reports,
 											   float desired_error);
@@ -249,7 +249,7 @@ FANN_EXTERNAL float FANN_API fann_test_data(struct fann *ann, struct fann_train_
 
     This function appears in FANN >= 1.0.0
 */ 
-FANN_EXTERNAL struct fann_train_data *FANN_API fann_read_train_from_file(char *filename);
+FANN_EXTERNAL struct fann_train_data *FANN_API fann_read_train_from_file(const char *filename);
 
 
 /* Function: fann_destroy_train
@@ -366,7 +366,7 @@ FANN_EXTERNAL unsigned int FANN_API fann_length_train_data(struct fann_train_dat
  */ 
 FANN_EXTERNAL unsigned int FANN_API fann_num_input_train_data(struct fann_train_data *data);
 	
-/* Function: fann_num_input_train_data
+/* Function: fann_num_output_train_data
    
    Returns the number of outputs in each of the training patterns in the <struct fann_train_data>.
    
@@ -386,7 +386,7 @@ FANN_EXTERNAL unsigned int FANN_API fann_num_output_train_data(struct fann_train
 	
    This function appears in FANN >= 1.0.0.   	
  */ 
-FANN_EXTERNAL void FANN_API fann_save_train(struct fann_train_data *data, char *filename);
+FANN_EXTERNAL void FANN_API fann_save_train(struct fann_train_data *data, const char *filename);
 
 
 /* Function: fann_save_train_to_fixed
@@ -400,7 +400,7 @@ FANN_EXTERNAL void FANN_API fann_save_train(struct fann_train_data *data, char *
 
    This function appears in FANN >= 1.0.0.   	
  */ 
-FANN_EXTERNAL void FANN_API fann_save_train_to_fixed(struct fann_train_data *data, char *filename,
+FANN_EXTERNAL void FANN_API fann_save_train_to_fixed(struct fann_train_data *data, const char *filename,
 													 unsigned int decimal_point);
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/libfann.git



More information about the debian-science-commits mailing list