[libfann] 166/242: more work done on cascade correlation
Christian Kastner
chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:38 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 66b38b1702f51b2a61bf66c28c18ffc846179c9f
Author: Steffen Nissen <lukesky at diku.dk>
Date: Thu Oct 14 06:44:30 2004 +0000
more work done on cascade correlation
---
config.guess | 18 ++---
examples/cascade_train.c | 25 +++---
examples/mushroom.c | 4 +-
examples/xor_train.c | 2 +-
src/fann.c | 2 +-
src/fann_cascade.c | 186 +++++++++++++++++++++++++++++---------------
src/fann_options.c | 53 +++++++------
src/fann_train.c | 45 ++---------
src/fann_train_data.c | 7 +-
src/include/fann_internal.h | 6 +-
10 files changed, 184 insertions(+), 164 deletions(-)
diff --git a/config.guess b/config.guess
index 6641456..77c7cba 100755
--- a/config.guess
+++ b/config.guess
@@ -3,7 +3,7 @@
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
-timestamp='2004-07-19'
+timestamp='2004-08-13'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@@ -203,9 +203,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
amiga:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
- arc:OpenBSD:*:*)
- echo mipsel-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
cats:OpenBSD:*:*)
echo arm-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
@@ -230,18 +227,12 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
mvmeppc:OpenBSD:*:*)
echo powerpc-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
- pmax:OpenBSD:*:*)
- echo mipsel-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
sgi:OpenBSD:*:*)
- echo mipseb-unknown-openbsd${UNAME_RELEASE}
+ echo mips64-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sun3:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
- wgrisc:OpenBSD:*:*)
- echo mipsel-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
*:OpenBSD:*:*)
echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
@@ -1179,9 +1170,10 @@ EOF
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
exit 0 ;;
*:Darwin:*:*)
- case `uname -p` in
+ UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+ case $UNAME_PROCESSOR in
*86) UNAME_PROCESSOR=i686 ;;
- powerpc) UNAME_PROCESSOR=powerpc ;;
+ unknown) UNAME_PROCESSOR=powerpc ;;
esac
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
exit 0 ;;
diff --git a/examples/cascade_train.c b/examples/cascade_train.c
index 097b3d9..1ef9b8d 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 = 1000;
- unsigned int max_cand_epochs = 200;
- unsigned int max_neurons = 32;
+ unsigned int max_out_epochs = 10000;
+ unsigned int max_cand_epochs = 10000;
+ unsigned int max_neurons = 50;
unsigned int neurons_between_reports = 1;
unsigned int i = 0;
fann_type *calc_out;
@@ -36,20 +36,17 @@ int main()
printf("Reading data.\n");
- 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/building.train");
+ test_data = fann_read_train_from_file("../benchmarks/datasets/building.test");
printf("Creating network.\n");
ann = fann_create_shortcut(learning_rate, 2, train_data->num_input, train_data->num_output);
- fann_set_activation_steepness_hidden(ann, 1.0);
- fann_set_activation_steepness_output(ann, 1.0);
+ fann_set_activation_function_hidden(ann, FANN_SIGMOID);
+ fann_set_activation_function_output(ann, FANN_SIGMOID);
- fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC_STEPWISE);
- fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC_STEPWISE);
-
- fann_print_connections(ann);
+ /*fann_print_connections(ann);*/
fann_print_parameters(ann);
printf("Training network.\n");
@@ -62,15 +59,17 @@ int main()
printf("\nTrain error: %f, Test error: %f\n\n", fann_test_data(ann, train_data), fann_test_data(ann, test_data));
fann_print_connections(ann);
- fann_print_parameters(ann);
+ /*fann_print_parameters(ann);*/
- printf("Testing network.\n");
+ /*
+ printf("\nTesting network.\n");
for(i = 0; i < test_data->num_data; i++){
calc_out = fann_run(ann, test_data->input[i]);
printf("XOR test (%f,%f) -> %f, should be %f, difference=%f\n",
test_data->input[i][0], test_data->input[i][1], *calc_out, test_data->output[i][0], fann_abs(*calc_out - test_data->output[i][0]));
}
+ */
printf("Saving network.\n");
diff --git a/examples/mushroom.c b/examples/mushroom.c
index 65087dc..f02b528 100644
--- a/examples/mushroom.c
+++ b/examples/mushroom.c
@@ -35,7 +35,7 @@ int main()
const unsigned int num_neurons_hidden = 32;
const float desired_error = (const float)0.0001;
const unsigned int max_iterations = 300;
- const unsigned int iterations_between_reports = 1;
+ const unsigned int iterations_between_reports = 10;
struct fann *ann;
struct fann_train_data *train_data, *test_data;
@@ -55,7 +55,7 @@ int main()
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC_STEPWISE);
fann_set_activation_function_output(ann, FANN_SIGMOID_STEPWISE);
- fann_set_training_algorithm(ann, FANN_TRAIN_INCREMENTAL);
+ /*fann_set_training_algorithm(ann, FANN_TRAIN_INCREMENTAL);*/
fann_train_on_data(ann, train_data, max_iterations, iterations_between_reports, desired_error);
diff --git a/examples/xor_train.c b/examples/xor_train.c
index 80ea0ea..3878e6c 100644
--- a/examples/xor_train.c
+++ b/examples/xor_train.c
@@ -65,7 +65,7 @@ int main()
fann_init_weights(ann, data);
- /*fann_set_training_algorithm(ann, FANN_TRAIN_QUICKPROP);*/
+ fann_set_training_algorithm(ann, FANN_TRAIN_QUICKPROP);
fann_train_on_data(ann, data, max_iterations, iterations_between_reports, desired_error);
/*fann_train_on_data_callback(ann, data, max_iterations, iterations_between_reports, desired_error, print_callback);*/
diff --git a/src/fann.c b/src/fann.c
index a3abbfa..7058564 100644
--- a/src/fann.c
+++ b/src/fann.c
@@ -833,7 +833,7 @@ struct fann * fann_allocate_structure(float learning_rate, unsigned int num_laye
/* variables used for cascade correlation (reasonable defaults) */
ann->cascade_change_fraction = 0.001;
- ann->cascade_stagnation_epochs = 32;
+ ann->cascade_stagnation_epochs = 64;
ann->cascade_num_candidates = 8;
ann->cascade_candidate_scores = NULL;
diff --git a/src/fann_cascade.c b/src/fann_cascade.c
index 53f4566..1551d59 100644
--- a/src/fann_cascade.c
+++ b/src/fann_cascade.c
@@ -90,8 +90,12 @@ void fann_cascadetrain_on_data_callback(struct fann *ann, struct fann_train_data
fann_install_candidate(ann);
}
- /* Train outputs one last time */
- total_epochs += fann_train_outputs(ann, data, desired_error, max_out_epochs);
+ /* Train outputs one last time but without any desired error */
+ total_epochs += fann_train_outputs(ann, data, 0.0, max_out_epochs);
+
+ if(neurons_between_reports && callback == NULL){
+ printf("Train outputs Current error: %.6f. Epochs %6d\n", fann_get_MSE(ann), total_epochs);
+ }
/* Set pointers in connected_neurons
This is ONLY done in the end of cascade training,
@@ -121,7 +125,9 @@ int fann_train_outputs(struct fann *ann, struct fann_train_data *data, float des
error = fann_train_outputs_epoch(ann, data);
if(error < desired_error){
- printf("Error %f < %f (%f)\n", error, desired_error, fann_get_MSE(ann));
+#ifdef CASCADE_DEBUG
+ printf("Error %f < %f\n", error, desired_error);
+#endif
return i+1;
}
@@ -152,7 +158,6 @@ int fann_train_outputs(struct fann *ann, struct fann_train_data *data, float des
float fann_train_outputs_epoch(struct fann *ann, struct fann_train_data *data)
{
- return fann_train_epoch_quickprop(ann, data); /* TODO remove this line */
unsigned int i;
fann_reset_MSE(ann);
@@ -164,7 +169,7 @@ 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_quickprop(ann, data->num_data, ann->last_layer-1, ann->last_layer-1);
+ fann_update_weights_quickprop(ann, data->num_data, (ann->last_layer-1)->first_neuron->first_con, ann->total_connections);
return fann_get_MSE(ann);
}
@@ -259,10 +264,11 @@ int fann_initialize_candidates(struct fann *ann)
*/
unsigned int neurons_to_allocate, connections_to_allocate;
unsigned int num_neurons = ann->total_neurons + ann->cascade_num_candidates + 1;
- /* the number of connections going into a and out of a candidate is at maximum
+ unsigned int candidate_connections_in = ann->total_neurons - ann->num_output;
+ unsigned int candidate_connections_out = ann->num_output;
+ /* the number of connections going into a and out of a candidate is
ann->total_neurons */
- unsigned int candidate_connections = ann->total_neurons * (ann->cascade_num_candidates + 1);
- unsigned int num_connections = ann->total_connections + candidate_connections;
+ unsigned int num_connections = ann->total_connections + (ann->total_neurons * (ann->cascade_num_candidates + 1));
unsigned int first_candidate_connection = ann->total_connections + ann->total_neurons;
unsigned int first_candidate_neuron = ann->total_neurons + 1;
unsigned int connection_it, i;
@@ -310,14 +316,19 @@ int fann_initialize_candidates(struct fann *ann)
*/
neurons[i].value = 0;
neurons[i].first_con = connection_it;
- connection_it += candidate_connections;
+ connection_it += candidate_connections_in;
neurons[i].last_con = connection_it;
+ /* We have no specific pointers to the output weights, but they are
+ available after last_con */
+ connection_it += candidate_connections_out;
ann->train_errors[i] = 0;
}
/* Now randomize the weights and zero out the arrays that needs zeroing out.
*/
+#ifdef CASCADE_DEBUG
printf("random cand weight [%d ... %d]\n", first_candidate_connection, num_connections-1);
+#endif
for(i = first_candidate_connection; i < num_connections; i++){
ann->weights[i] = fann_random_weight();
ann->train_slopes[i] = 0;
@@ -344,21 +355,18 @@ int fann_train_candidates(struct fann *ann, struct fann_train_data *data, unsign
}
}
- /* TODO remove, just sets to first candidate neuron and returns.
- */
- ann->cascade_best_candidate = ann->total_neurons+1;
- return 0;
-
for(i = 0; i < max_epochs; i++){
best_cand_score = fann_train_candidates_epoch(ann, data);
if ((best_cand_score > target_cand_score) ||
(best_cand_score < backslide_cand_score))
{
- /*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);*/
+#ifdef CASCADE_DEBUG
+ 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 * (ann->cascade_change_fraction + 1);
- backslide_cand_score = best_cand_score * (ann->cascade_change_fraction - 1);
+ target_cand_score = best_cand_score * (ann->cascade_change_fraction + 1.0);
+ backslide_cand_score = best_cand_score * (1.0 - ann->cascade_change_fraction);
stagnation = i + ann->cascade_stagnation_epochs;
}
@@ -374,60 +382,90 @@ int fann_train_candidates(struct fann *ann, struct fann_train_data *data, unsign
void fann_update_candidate_slopes(struct fann *ann)
{
- struct fann_neuron * neurons = ann->first_layer->first_neuron;
- struct fann_neuron * first_cand = neurons + ann->total_neurons + 1;
- struct fann_neuron * last_cand = first_cand + ann->cascade_num_candidates;
- struct fann_neuron * neuron_it;
- unsigned int i, num_connections;
- fann_type neuron_value, activation, derived;
- fann_type *weights;
-
- for(neuron_it = first_cand; neuron_it < last_cand; neuron_it++){
+ struct fann_neuron *neurons = ann->first_layer->first_neuron;
+ struct fann_neuron *first_cand = neurons + ann->total_neurons + 1;
+ struct fann_neuron *last_cand = first_cand + ann->cascade_num_candidates;
+ struct fann_neuron *cand_it;
+ unsigned int i, j, num_connections;
+ unsigned int num_output = ann->num_output;
+ fann_type cand_value, activation, derived, error_value, diff, cand_score;
+ fann_type *weights, *out_weights, *cand_slopes;
+ fann_type *output_train_errors = ann->train_errors + (ann->total_neurons - ann->num_output);
+
+ for(cand_it = first_cand; cand_it < last_cand; cand_it++){
+ cand_score = 0.0;
+ error_value = 0.0;
/* code more or less stolen from fann_run to fast forward pass
*/
+ cand_value = 0.0;
+ num_connections = cand_it->last_con - cand_it->first_con;
+ weights = ann->weights + cand_it->first_con;
- neuron_value = 0.0;
- num_connections = neuron_it->last_con - neuron_it->first_con;
- weights = ann->weights + neuron_it->first_con;
-
+ /* unrolled loop start */
i = num_connections & 3; /* same as modulo 4 */
switch(i) {
case 3:
- neuron_value += weights[2] * neurons[2].value;
+ cand_value += weights[2] * neurons[2].value;
case 2:
- neuron_value += weights[1] * neurons[1].value;
+ cand_value += weights[1] * neurons[1].value;
case 1:
- neuron_value += weights[0] * neurons[0].value;
+ cand_value += weights[0] * neurons[0].value;
case 0:
break;
}
for(;i != num_connections; i += 4){
- neuron_value +=
+ cand_value +=
weights[i] * neurons[i].value +
weights[i+1] * neurons[i+1].value +
weights[i+2] * neurons[i+2].value +
weights[i+3] * neurons[i+3].value;
}
- }
+ /* unrolled loop end */
- activation = fann_activation(ann, 0, neuron_value);
- derived = fann_activation_derived(ann->activation_function_hidden,
- ann->activation_steepness_hidden, activation);
+ activation = fann_activation(ann, 0, cand_value);
+ derived = fann_activation_derived(ann->activation_function_hidden,
+ ann->activation_steepness_hidden, activation);
- /* BIG TODO add more here do stuff for the output */
+ /* The output weights is located right after the input weights in
+ the weight array.
+ */
+ out_weights = weights + num_connections;
+
+ for(j = 0; j < num_output; j++){
+ diff = (activation * out_weights[j]) - output_train_errors[j];
+ /*printf("%f = (%f * %f) - %f;\n", diff, activation, out_weights[j], output_train_errors[j]);*/
+ cand_score += (diff * diff);
+ error_value += diff * out_weights[j];
+ }
+
+ ann->cascade_candidate_scores[cand_it - first_cand] = cand_score;
+ error_value *= derived;
+ cand_slopes = ann->train_slopes + cand_it->first_con;
+ for(i = 0; i < num_connections; i++){
+ cand_slopes[i] += error_value * neurons[i].value;
+ }
+ }
+}
+
+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_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)
{
- /* TODO this should actually train the candidates, but first I will need to decide how the candidates should be allocated */
-
unsigned int i;
+ fann_type best_score = ann->cascade_candidate_scores[0];
+ unsigned int best_candidate = 0;
+ unsigned int num_cand = ann->cascade_num_candidates;
float MSE = fann_get_MSE(ann);
- unsigned int num_cand = ann->cascade_num_candidates;
for(i = 0; i < num_cand; i++){
ann->cascade_candidate_scores[i] = (fann_type)MSE;
}
@@ -440,9 +478,21 @@ float fann_train_candidates_epoch(struct fann *ann, struct fann_train_data *data
fann_update_candidate_slopes(ann);
}
- /* fann_update_candidate_weights */
+ fann_update_candidate_weights(ann, data->num_data);
+
+ /* find the best candidate score */
+ for(i = 1; i < num_cand; i++){
+ if(ann->cascade_candidate_scores[i] > best_score){
+ best_candidate = i;
+ best_score = ann->cascade_candidate_scores[i];
+ }
+ }
+
+ ann->cascade_best_candidate = ann->total_neurons + best_candidate + 1;
+ /*printf("Best candidate: %d(%d) with score %f\n", ann->cascade_best_candidate, best_candidate, best_score);*/
- return fann_get_MSE(ann); /* TODO return the score of the best candidate */
+ return best_score;
+
}
/* add a layer ad the position pointed to by *layer */
@@ -501,17 +551,16 @@ void fann_set_shortcut_connections(struct fann *ann)
}
}
-void fann_add_shortcut_neuron(struct fann *ann, struct fann_layer *layer)
+void fann_add_candidate_neuron(struct fann *ann, struct fann_layer *layer)
{
unsigned int num_connections_in = layer->first_neuron - ann->first_layer->first_neuron;
unsigned int num_connections_out = (ann->last_layer-1)->last_neuron - (layer+1)->first_neuron;
unsigned int num_connections_move = num_connections_out + num_connections_in;
- unsigned int neurons_to_allocate = 0;
- unsigned int connections_to_allocate = 0;
- int i, candidate_con;
+
+ int i, candidate_con, candidate_output_weight;
struct fann_layer *layer_it;
- struct fann_neuron *neuron_it, *neuron_place;
+ struct fann_neuron *neuron_it, *neuron_place, *candidate;
/* We know that there is enough room for the new neuron
(the candidates are in the same arrays), so move
@@ -538,8 +587,15 @@ void fann_add_shortcut_neuron(struct fann *ann, struct fann_layer *layer)
/* this is the place that should hold the new neuron */
neuron_place = layer->last_neuron-1;
- printf("num_connections_in=%d, num_connections_out=%d, neurons_to_allocate=%d, connections_to_allocate=%d\n", num_connections_in, num_connections_out, neurons_to_allocate, connections_to_allocate);
+#ifdef CASCADE_DEBUG
+ printf("num_connections_in=%d, num_connections_out=%d\n", num_connections_in, num_connections_out);
+#endif
+ candidate = ann->first_layer->first_neuron + ann->cascade_best_candidate;
+
+ /* the output weights for the candidates are located after the input weights */
+ candidate_output_weight = candidate->last_con;
+
/* move the actual neurons and the indexes to the connection arrays */
for(neuron_it = (ann->last_layer-1)->last_neuron-1;
neuron_it != neuron_place; neuron_it--){
@@ -549,12 +605,10 @@ void fann_add_shortcut_neuron(struct fann *ann, struct fann_layer *layer)
#endif
*neuron_it = *(neuron_it-1);
-#ifdef CASCADE_DEBUG
- printf("move connection first(%d -> %d), last(%d -> %d)\n", neuron_it->first_con, neuron_it->first_con + num_connections_move-1, neuron_it->last_con, neuron_it->last_con + num_connections_move);
-#endif
-
/* move the weights */
+#ifdef CASCADE_DEBUG
printf("move weight[%d ... %d] -> weight[%d ... %d]\n", neuron_it->first_con, neuron_it->last_con-1, neuron_it->first_con + num_connections_move - 1, neuron_it->last_con + num_connections_move - 2);
+#endif
for(i = neuron_it->last_con - 1; i >= (int)neuron_it->first_con; i--){
#ifdef CASCADE_DEBUG
printf("move weight[%d] = weight[%d]\n", i + num_connections_move - 1, i);
@@ -568,14 +622,12 @@ void fann_add_shortcut_neuron(struct fann *ann, struct fann_layer *layer)
neuron_it->first_con += num_connections_move;
/* set the new weight to the newly allocated neuron */
- printf("random weight[%d]\n", neuron_it->last_con-1);
#ifdef CASCADE_DEBUG
- printf("random weight[%d]\n", neuron_it->last_con-1);
+ printf("cadidate output weight set to weight[%d] = weight[%d] = %f\n", neuron_it->last_con-1, candidate_output_weight, 0.0 - ann->weights[candidate_output_weight]);
#endif
- /* TODO this should be the weights into the candidate
- neuron, don't really know how to get this.
- */
- ann->weights[neuron_it->last_con-1] = (fann_type)fann_random_weight();
+
+ ann->weights[neuron_it->last_con-1] = 0.0 - ann->weights[candidate_output_weight];
+ candidate_output_weight++;
}
/* Now inititalize the actual neuron */
@@ -583,13 +635,15 @@ void fann_add_shortcut_neuron(struct fann *ann, struct fann_layer *layer)
neuron_place->last_con = (neuron_place+1)->first_con;
neuron_place->first_con = neuron_place->last_con - num_connections_in;
#ifdef CASCADE_DEBUG
- printf("neuron[%d] = (%d - %d)\n", neuron_place - ann->first_layer->first_neuron, neuron_place->first_con, neuron_place->last_con);
+ printf("neuron[%d] = weights[%d ... %d]\n", neuron_place - ann->first_layer->first_neuron, neuron_place->first_con, neuron_place->last_con-1);
#endif
- candidate_con = ann->first_layer->first_neuron[ann->cascade_best_candidate].first_con;
+ candidate_con = candidate->first_con;
/* initialize the input weights at random */
+#ifdef CASCADE_DEBUG
printf("move cand weights[%d ... %d] -> [%d ... %d]\n", candidate_con, candidate_con + num_connections_in-1, neuron_place->first_con, neuron_place->last_con-1);
-
+#endif
+
for(i = 0; i < num_connections_in; i++){
ann->weights[i + neuron_place->first_con] = ann->weights[i + candidate_con];
#ifdef CASCADE_DEBUG
@@ -606,9 +660,13 @@ void fann_add_shortcut_neuron(struct fann *ann, struct fann_layer *layer)
void fann_install_candidate(struct fann *ann)
{
+ /* TODO the candidate should be installed correctly,
+ with input and output weights.
+ */
+
struct fann_layer *layer;
layer = fann_add_layer(ann, ann->last_layer-1);
- fann_add_shortcut_neuron(ann, layer);
+ fann_add_candidate_neuron(ann, layer);
return;
}
diff --git a/src/fann_options.c b/src/fann_options.c
index 25df6a2..85e2ea7 100644
--- a/src/fann_options.c
+++ b/src/fann_options.c
@@ -31,41 +31,44 @@ FANN_EXTERNAL void FANN_API fann_print_parameters(struct fann *ann)
{
struct fann_layer *layer_it;
- printf("Input layer : %2d neurons, 1 bias\n", ann->num_input);
+ printf("Input layer :%4d neurons, 1 bias\n", ann->num_input);
for(layer_it = ann->first_layer+1; layer_it != ann->last_layer-1; layer_it++){
if(ann->shortcut_connections){
- printf(" Hidden layer : %2d neurons, 0 bias\n",
+ printf(" Hidden layer :%4d neurons, 0 bias\n",
layer_it->last_neuron - layer_it->first_neuron);
} else {
- printf(" Hidden layer : %2d neurons, 1 bias\n",
+ printf(" Hidden layer :%4d neurons, 1 bias\n",
layer_it->last_neuron - layer_it->first_neuron - 1);
}
}
- printf("Output layer : %2d neurons\n", ann->num_output);
- printf("Total neurons and biases : %2d\n", fann_get_total_neurons(ann));
- printf("Total connections : %2d\n", ann->total_connections);
- printf("Connection rate : %5.2f\n", ann->connection_rate);
- printf("Shortcut connections : %2d\n", ann->shortcut_connections);
- printf("Training algorithm : %s\n", FANN_TRAIN_NAMES[ann->training_algorithm]);
- printf("Learning rate : %5.2f\n", ann->learning_rate);
- printf("Activation function hidden : %s\n", FANN_ACTIVATION_NAMES[ann->activation_function_hidden]);
- printf("Activation function output : %s\n", FANN_ACTIVATION_NAMES[ann->activation_function_output]);
+ 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("Training algorithm : %s\n", FANN_TRAIN_NAMES[ann->training_algorithm]);
+ printf("Learning rate : %5.2f\n", ann->learning_rate);
+ printf("Activation function hidden : %s\n", FANN_ACTIVATION_NAMES[ann->activation_function_hidden]);
+ printf("Activation function output : %s\n", FANN_ACTIVATION_NAMES[ann->activation_function_output]);
#ifndef FIXEDFANN
- printf("Activation steepness hidden: %5.2f\n", ann->activation_steepness_hidden);
- printf("Activation steepness output: %5.2f\n", ann->activation_steepness_output);
+ printf("Activation steepness hidden: %5.2f\n", ann->activation_steepness_hidden);
+ printf("Activation steepness output: %5.2f\n", ann->activation_steepness_output);
#else
- printf("Activation steepness hidden: %d\n", ann->activation_steepness_hidden);
- printf("Activation steepness output: %d\n", ann->activation_steepness_output);
- printf("Decimal point : %2d\n", ann->decimal_point);
- printf("Multiplier : %2d\n", ann->multiplier);
+ printf("Activation steepness hidden: %d\n", ann->activation_steepness_hidden);
+ printf("Activation steepness output: %d\n", ann->activation_steepness_output);
+ printf("Decimal point :%4d\n", ann->decimal_point);
+ printf("Multiplier :%4d\n", ann->multiplier);
#endif
- printf("Training error function : %s\n", FANN_ERRORFUNC_NAMES[ann->train_error_function]);
- 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("Training error function : %s\n", FANN_ERRORFUNC_NAMES[ann->train_error_function]);
+ 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 stagnation epochs :%4d\n", ann->cascade_stagnation_epochs);
+ printf("Cascade no. of candidates :%4d\n", ann->cascade_num_candidates);
}
FANN_EXTERNAL unsigned int FANN_API fann_get_training_algorithm(struct fann *ann)
diff --git a/src/fann_train.c b/src/fann_train.c
index d17c6a0..6ad8f9f 100644
--- a/src/fann_train.c
+++ b/src/fann_train.c
@@ -561,23 +561,12 @@ void fann_clear_train_arrays(struct fann *ann)
/* INTERNAL FUNCTION
Update weights for batch training
*/
-void fann_update_weights_batch(struct fann *ann, unsigned int num_data, struct fann_layer *layer_begin, struct fann_layer *layer_end)
+void fann_update_weights_batch(struct fann *ann, unsigned int num_data, unsigned int first_weight, unsigned int past_end)
{
fann_type *train_slopes = ann->train_slopes;
fann_type *weights = ann->weights;
const float epsilon = ann->learning_rate/num_data;
- unsigned int i, past_end;
-
- if(layer_begin == NULL){
- layer_begin = ann->first_layer+1;
- }
-
- if(layer_end == NULL){
- layer_end = ann->last_layer-1;
- }
-
- i = layer_begin->first_neuron->first_con;
- past_end = (layer_end->last_neuron - 1)->last_con;
+ unsigned int i = first_weight;
for(;i != past_end; i++){
weights[i] += train_slopes[i] * epsilon;
@@ -588,7 +577,7 @@ void fann_update_weights_batch(struct fann *ann, unsigned int num_data, struct f
/* INTERNAL FUNCTION
The quickprop training algorithm
*/
-void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, struct fann_layer *layer_begin, struct fann_layer *layer_end)
+void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, unsigned int first_weight, unsigned int past_end)
{
fann_type *train_slopes = ann->train_slopes;
fann_type *weights = ann->weights;
@@ -602,18 +591,7 @@ void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, stru
float mu = ann->quickprop_mu; /*1.75;*/
float shrink_factor = (float)(mu / (1.0 + mu));
- unsigned int i, past_end;
-
- if(layer_begin == NULL){
- layer_begin = ann->first_layer+1;
- }
-
- if(layer_end == NULL){
- layer_end = ann->last_layer-1;
- }
-
- i = layer_begin->first_neuron->first_con;
- past_end = (layer_end->last_neuron - 1)->last_con;
+ unsigned int i = first_weight;
for(;i != past_end; i++){
w = weights[i];
@@ -666,7 +644,7 @@ void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, stru
/* INTERNAL FUNCTION
The iRprop- algorithm
*/
-void fann_update_weights_irpropm(struct fann *ann, unsigned int num_data, struct fann_layer *layer_begin, struct fann_layer *layer_end)
+void fann_update_weights_irpropm(struct fann *ann, unsigned int first_weight, unsigned int past_end)
{
fann_type *train_slopes = ann->train_slopes;
fann_type *weights = ann->weights;
@@ -681,18 +659,7 @@ void fann_update_weights_irpropm(struct fann *ann, unsigned int num_data, struct
float delta_min = ann->rprop_delta_min;/*0.0;*/
float delta_max = ann->rprop_delta_max;/*50.0;*/
- unsigned int i, past_end;
-
- if(layer_begin == NULL){
- layer_begin = ann->first_layer+1;
- }
-
- if(layer_end == NULL){
- layer_end = ann->last_layer-1;
- }
-
- i = layer_begin->first_neuron->first_con;
- past_end = (layer_end->last_neuron - 1)->last_con;
+ unsigned int i = first_weight;
for(;i != past_end; i++){
prev_step = fann_max(prev_steps[i], (fann_type)0.001); /* prev_step may not be zero because then the training will stop */
diff --git a/src/fann_train_data.c b/src/fann_train_data.c
index 068d102..f5cf30d 100644
--- a/src/fann_train_data.c
+++ b/src/fann_train_data.c
@@ -89,7 +89,7 @@ float fann_train_epoch_quickprop(struct fann *ann, struct fann_train_data *data)
fann_backpropagate_MSE(ann);
fann_update_slopes_batch(ann, ann->first_layer+1, ann->last_layer-1);
}
- fann_update_weights_quickprop(ann, data->num_data, ann->first_layer+1, ann->last_layer-1);
+ fann_update_weights_quickprop(ann, data->num_data, 0, ann->total_connections);
return fann_get_MSE(ann);
}
@@ -111,7 +111,8 @@ float fann_train_epoch_irpropm(struct fann *ann, struct fann_train_data *data)
fann_backpropagate_MSE(ann);
fann_update_slopes_batch(ann, ann->first_layer+1, ann->last_layer-1);
}
- fann_update_weights_irpropm(ann, data->num_data, ann->first_layer+1, ann->last_layer-1);
+
+ fann_update_weights_irpropm(ann, 0, ann->total_connections);
return fann_get_MSE(ann);
}
@@ -128,7 +129,7 @@ float fann_train_epoch_batch(struct fann *ann, struct fann_train_data *data)
fann_backpropagate_MSE(ann);
fann_update_slopes_batch(ann, ann->first_layer+1, ann->last_layer-1);
}
- fann_update_weights_batch(ann, data->num_data, ann->first_layer+1, ann->last_layer-1);
+ fann_update_weights_batch(ann, data->num_data, 0, ann->total_connections);
return fann_get_MSE(ann);
}
diff --git a/src/include/fann_internal.h b/src/include/fann_internal.h
index ffece5c..04d6b27 100644
--- a/src/include/fann_internal.h
+++ b/src/include/fann_internal.h
@@ -61,9 +61,9 @@ void fann_update_output_weights(struct fann *ann);
void fann_backpropagate_MSE(struct fann *ann);
void fann_update_weights(struct fann *ann);
void fann_update_slopes_batch(struct fann *ann, struct fann_layer *layer_begin, struct fann_layer *layer_end);
-void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, struct fann_layer *layer_begin, struct fann_layer *layer_end);
-void fann_update_weights_batch(struct fann *ann, unsigned int num_data, struct fann_layer *layer_begin, struct fann_layer *layer_end);
-void fann_update_weights_irpropm(struct fann *ann, unsigned int num_data, struct fann_layer *layer_begin, struct fann_layer *layer_end);
+void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data, unsigned int first_weight, unsigned int past_end);
+void fann_update_weights_batch(struct fann *ann, unsigned int num_data, unsigned int first_weight, unsigned int past_end);
+void fann_update_weights_irpropm(struct fann *ann, unsigned int first_weight, unsigned int past_end);
void fann_clear_train_arrays(struct fann *ann);
--
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