[libfann] 179/242: better working copy of cascade

Christian Kastner chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:40 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 f17d20cc9c9103a9fc94d2f2e67c5ad8a12efe46
Author: Steffen Nissen <lukesky at diku.dk>
Date:   Mon May 23 23:19:10 2005 +0000

    better working copy of cascade
---
 examples/cascade_train.c | 14 +++++++-------
 examples/xor.data        | 14 +++++++-------
 src/fann_cascade.c       | 18 ++++++++++--------
 src/fann_train.c         |  7 +++++--
 4 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/examples/cascade_train.c b/examples/cascade_train.c
index ac37d9f..66c963b 100644
--- a/examples/cascade_train.c
+++ b/examples/cascade_train.c
@@ -25,9 +25,9 @@ int main()
 {
 	const float learning_rate = (const float)0.7;
 	const float desired_error = (const float)0.001;
-	unsigned int max_out_epochs = 500;
-	unsigned int max_cand_epochs = 500;
-	unsigned int max_neurons = 20;
+	unsigned int max_out_epochs = 100;
+	unsigned int max_cand_epochs = 100;
+	unsigned int max_neurons = 40;
 	unsigned int neurons_between_reports = 1;
 	struct fann *ann;
 	struct fann_train_data *train_data, *test_data;
@@ -41,14 +41,14 @@ int main()
 	/*
 	*/
 	
-	train_data = fann_read_train_from_file("../benchmarks/datasets/two-spiral2.train");
-	test_data = fann_read_train_from_file("../benchmarks/datasets/two-spiral2.test");
+	train_data = fann_read_train_from_file("../benchmarks/datasets/parity4.train");
+	test_data = fann_read_train_from_file("../benchmarks/datasets/parity4.test");
 	
 	train_data = fann_read_train_from_file("xor.data");
 	test_data = fann_read_train_from_file("xor.data");
 
-	train_data = fann_read_train_from_file("../benchmarks/datasets/parity4.train");
-	test_data = fann_read_train_from_file("../benchmarks/datasets/parity4.test");
+	train_data = fann_read_train_from_file("../benchmarks/datasets/two-spiral2.train");
+	test_data = fann_read_train_from_file("../benchmarks/datasets/two-spiral2.test");
 	
 	printf("Creating network.\n");
 
diff --git a/examples/xor.data b/examples/xor.data
index e831fc6..dcacd1a 100644
--- a/examples/xor.data
+++ b/examples/xor.data
@@ -1,9 +1,9 @@
 4 2 1
--1 -1
--1
--1 1
-1
-1 -1
-1
+0 0
+-2
+0 1
+2
+1 0
+2
 1 1
--1
+-2
diff --git a/src/fann_cascade.c b/src/fann_cascade.c
index 3bff1ac..5d94af1 100644
--- a/src/fann_cascade.c
+++ b/src/fann_cascade.c
@@ -287,8 +287,8 @@ float fann_train_outputs_epoch(struct fann *ann, struct fann_train_data *data)
 	/* TODO this should actually use the algorithm selected by
 	   ann->training_algorithm
 	*/
-	/*fann_update_weights_irpropm(ann, (ann->last_layer-1)->first_neuron->first_con, ann->total_connections);*/
-	fann_update_weights_quickprop(ann, data->num_data, (ann->last_layer-1)->first_neuron->first_con, ann->total_connections);
+	fann_update_weights_irpropm(ann, (ann->last_layer-1)->first_neuron->first_con, ann->total_connections);
+	/*fann_update_weights_quickprop(ann, data->num_data, (ann->last_layer-1)->first_neuron->first_con, ann->total_connections);*/
 
 	return fann_get_MSE(ann);
 }
@@ -584,7 +584,7 @@ void fann_update_candidate_slopes(struct fann *ann)
 #ifdef CASCADE_DEBUG
 			/* printf("diff = %f = (%f * %f) - %f;\n", diff, activation, cand_out_weights[j], output_train_errors[j]); */
 #endif
-			cand_out_slopes[j] += diff * activation;
+			cand_out_slopes[j] -= 2.0 * diff * activation;
 #ifdef CASCADE_DEBUG
 			/* printf("cand_out_slopes[%d] <= %f += %f * %f;\n", j, cand_out_slopes[j], diff, activation); */
 #endif
@@ -592,6 +592,8 @@ void fann_update_candidate_slopes(struct fann *ann)
 			cand_score -= (diff * diff);
 #ifdef CASCADE_DEBUG
 			/* printf("cand_score[%d][%d] = %f -= (%f * %f)\n", cand_it - first_cand, j, cand_score, diff, diff); */
+
+			printf("cand[%d]: error=%f, activation=%f, diff=%f, slope=%f\n", cand_it - first_cand, output_train_errors[j], (activation * cand_out_weights[j]), diff, -2.0 * diff * activation);
 #endif
 		}
 
@@ -600,7 +602,7 @@ void fann_update_candidate_slopes(struct fann *ann)
 		
 		cand_slopes = ann->train_slopes + cand_it->first_con;
 		for(i = 0; i < num_connections; i++){
-			cand_slopes[i] += error_value * neurons[i].value;
+			cand_slopes[i] -= error_value * neurons[i].value;
 		}
 	}
 }
@@ -610,7 +612,7 @@ void fann_update_candidate_weights(struct fann *ann, unsigned int num_data)
 	struct fann_neuron *first_cand = (ann->last_layer-1)->last_neuron + 1; /* there is an empty neuron between the actual neurons and the candidate neuron */
 	struct fann_neuron *last_cand = first_cand + ann->cascade_num_candidates-1;
 
-	fann_update_weights_special_quickprop(ann, num_data, first_cand->first_con, last_cand->last_con+ann->num_output);
+	fann_update_weights_quickprop(ann, num_data, first_cand->first_con, last_cand->last_con+ann->num_output);
 }
 
 float fann_train_candidates_epoch(struct fann *ann, struct fann_train_data *data)
@@ -641,7 +643,7 @@ float fann_train_candidates_epoch(struct fann *ann, struct fann_train_data *data
 			output_train_errors[j] = ann->output[j] - data->output[i][j];
 			*/
 
-			output_train_errors[j] = (ann->output[j] - data->output[i][j]);
+			output_train_errors[j] = (data->output[i][j] - ann->output[j]);
 
 			if(ann->activation_function_output == FANN_SIGMOID_SYMMETRIC ||
 				ann->activation_function_output == FANN_SIGMOID_SYMMETRIC_STEPWISE){
@@ -665,7 +667,7 @@ float fann_train_candidates_epoch(struct fann *ann, struct fann_train_data *data
 	}
 
 	ann->cascade_best_candidate = ann->total_neurons + best_candidate + 1;
-	printf("Best candidate: %d(%d) with score %f, real score: %f\n", ann->cascade_best_candidate, best_candidate, ann->MSE_value-best_score, best_score);
+	printf("Best candidate[%d]: with score %f, real score: %f\n", best_candidate, ann->MSE_value-best_score, best_score);
 	
 	return best_score;
 }
@@ -802,7 +804,7 @@ void fann_add_candidate_neuron(struct fann *ann, struct fann_layer *layer)
 		printf("cadidate output weight set to weight[%d] = weight[%d] = %f %f\n", neuron_it->last_con-1, candidate_output_weight, -(ann->weights[candidate_output_weight]), (ann->weights[candidate_output_weight]));
 #endif
 
-		ann->weights[neuron_it->last_con-1] =  -(ann->weights[candidate_output_weight]) * ann->cascade_weight_multiplier;
+		ann->weights[neuron_it->last_con-1] = -(ann->weights[candidate_output_weight]) * ann->cascade_weight_multiplier;
 		candidate_output_weight++;
 	}
 
diff --git a/src/fann_train.c b/src/fann_train.c
index c03938d..f9f17db 100644
--- a/src/fann_train.c
+++ b/src/fann_train.c
@@ -278,7 +278,6 @@ void fann_compute_MSE(struct fann *ann, fann_type *desired_output)
 	
 		*error_it = fann_activation_derived(ann->activation_function_output,
 			ann->activation_steepness_output, neuron_value) * neuron_diff;
-
 		
 		desired_output++;
 		error_it++;
@@ -644,8 +643,12 @@ void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, unsi
 			next_step += epsilon * slope;
 		}
 
-		if(next_step > 1000 || next_step < -1000){
+		if(next_step > 100 || next_step < -100){
 			printf("quickprop[%d] weight=%f, slope=%f, next_step=%f, prev_step=%f\n", i, weights[i], slope, next_step, prev_step);
+			if(next_step > 100)
+				next_step = 100;
+			else
+				next_step = -100;
 		}
 
 		/* update global data arrays */

-- 
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