2 Fast Artificial Neural Network Library (fann)
3 Copyright (C) 2003 Steffen Nissen (lukesky@diku.dk)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef __fann_cascade_h__
21 #define __fann_cascade_h__
23 /* Section: FANN Cascade Training
24 Cascade training differs from ordinary training in the sense that it starts with an empty neural network
25 and then adds neurons one by one, while it trains the neural network. The main benefit of this approach,
26 is that you do not have to guess the number of hidden layers and neurons prior to training, but cascade
27 training have also proved better at solving some problems.
29 The basic idea of cascade training is that a number of candidate neurons are trained separate from the
30 real network, then the most promissing of these candidate neurons is inserted into the neural network.
31 Then the output connections are trained and new candidate neurons is prepared. The candidate neurons are
32 created as shorcut connected neurons in a new hidden layer, which means that the final neural network
33 will consist of a number of hidden layers with one shorcut connected neuron in each.
36 /* Group: Cascade Training */
38 /* Function: fann_cascadetrain_on_data
40 Trains on an entire dataset, for a period of time using the Cascade2 training algorithm.
41 This algorithm adds neurons to the neural network while training, which means that it
42 needs to start with an ANN without any hidden layers. The neural network should also use
43 shortcut connections, so <fann_create_shortcut> should be used to create the ANN like this:
44 >struct fann *ann = fann_create_shortcut(2, fann_num_input_train_data(train_data), fann_num_input_train_data(train_data));
46 This training uses the parameters set using the fann_set_cascade_..., but it also uses another
47 training algorithm as it's internal training algorithm. This algorithm can be set to either
48 FANN_TRAIN_RPROP or FANN_TRAIN_QUICKPROP by <fann_set_training_algorithm>, and the parameters
49 set for these training algorithms will also affect the cascade training.
52 ann - The neural network
53 data - The data, which should be used during training
54 max_neuron - The maximum number of neurons to be added to neural network
55 neurons_between_reports - The number of neurons between printing a status report to stdout.
56 A value of zero means no reports should be printed.
57 desired_error - The desired <fann_get_MSE> or <fann_get_bit_fail>, depending on which stop function
58 is chosen by <fann_set_train_stop_function>.
60 Instead of printing out reports every neurons_between_reports, a callback function can be called
61 (see <fann_set_callback>).
64 <fann_train_on_data>, <fann_cascadetrain_on_file>, <Parameters>
66 This function appears in FANN >= 2.0.0.
68 FANN_EXTERNAL void FANN_API fann_cascadetrain_on_data(struct fann *ann,
69 struct fann_train_data *data,
70 unsigned int max_neurons,
71 unsigned int neurons_between_reports,
74 /* Function: fann_cascadetrain_on_file
76 Does the same as <fann_cascadetrain_on_data>, but reads the training data directly from a file.
79 <fann_cascadetrain_on_data>
81 This function appears in FANN >= 2.0.0.
83 FANN_EXTERNAL void FANN_API fann_cascadetrain_on_file(struct fann *ann, const char *filename,
84 unsigned int max_neurons,
85 unsigned int neurons_between_reports,
88 /* Group: Parameters */
90 /* Function: fann_get_cascade_output_change_fraction
92 The cascade output change fraction is a number between 0 and 1 determining how large a fraction
93 the <fann_get_MSE> value should change within <fann_get_cascade_output_stagnation_epochs> during
94 training of the output connections, in order for the training not to stagnate. If the training
95 stagnates, the training of the output connections will be ended and new candidates will be prepared.
98 If the MSE does not change by a fraction of <fann_get_cascade_output_change_fraction> during a
99 period of <fann_get_cascade_output_stagnation_epochs>, the training of the output connections
100 is stopped because the training has stagnated.
102 If the cascade output change fraction is low, the output connections will be trained more and if the
103 fraction is high they will be trained less.
105 The default cascade output change fraction is 0.01, which is equalent to a 1% change in MSE.
108 <fann_set_cascade_output_change_fraction>, <fann_get_MSE>, <fann_get_cascade_output_stagnation_epochs>
110 This function appears in FANN >= 2.0.0.
112 FANN_EXTERNAL float FANN_API fann_get_cascade_output_change_fraction(struct fann *ann);
115 /* Function: fann_set_cascade_output_change_fraction
117 Sets the cascade output change fraction.
120 <fann_get_cascade_output_change_fraction>
122 This function appears in FANN >= 2.0.0.
124 FANN_EXTERNAL void FANN_API fann_set_cascade_output_change_fraction(struct fann *ann,
125 float cascade_output_change_fraction);
127 /* Function: fann_get_cascade_output_stagnation_epochs
129 The number of cascade output stagnation epochs determines the number of epochs training is allowed to
130 continue without changing the MSE by a fraction of <fann_get_cascade_output_change_fraction>.
132 See more info about this parameter in <fann_get_cascade_output_change_fraction>.
134 The default number of cascade output stagnation epochs is 12.
137 <fann_set_cascade_output_stagnation_epochs>, <fann_get_cascade_output_change_fraction>
139 This function appears in FANN >= 2.0.0.
141 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_output_stagnation_epochs(struct fann *ann);
144 /* Function: fann_set_cascade_output_stagnation_epochs
146 Sets the number of cascade output stagnation epochs.
149 <fann_get_cascade_output_stagnation_epochs>
151 This function appears in FANN >= 2.0.0.
153 FANN_EXTERNAL void FANN_API fann_set_cascade_output_stagnation_epochs(struct fann *ann,
154 unsigned int cascade_output_stagnation_epochs);
157 /* Function: fann_get_cascade_candidate_change_fraction
159 The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction
160 the <fann_get_MSE> value should change within <fann_get_cascade_candidate_stagnation_epochs> during
161 training of the candidate neurons, in order for the training not to stagnate. If the training
162 stagnates, the training of the candidate neurons will be ended and the best candidate will be selected.
165 If the MSE does not change by a fraction of <fann_get_cascade_candidate_change_fraction> during a
166 period of <fann_get_cascade_candidate_stagnation_epochs>, the training of the candidate neurons
167 is stopped because the training has stagnated.
169 If the cascade candidate change fraction is low, the candidate neurons will be trained more and if the
170 fraction is high they will be trained less.
172 The default cascade candidate change fraction is 0.01, which is equalent to a 1% change in MSE.
175 <fann_set_cascade_candidate_change_fraction>, <fann_get_MSE>, <fann_get_cascade_candidate_stagnation_epochs>
177 This function appears in FANN >= 2.0.0.
179 FANN_EXTERNAL float FANN_API fann_get_cascade_candidate_change_fraction(struct fann *ann);
182 /* Function: fann_set_cascade_candidate_change_fraction
184 Sets the cascade candidate change fraction.
187 <fann_get_cascade_candidate_change_fraction>
189 This function appears in FANN >= 2.0.0.
191 FANN_EXTERNAL void FANN_API fann_set_cascade_candidate_change_fraction(struct fann *ann,
192 float cascade_candidate_change_fraction);
194 /* Function: fann_get_cascade_candidate_stagnation_epochs
196 The number of cascade candidate stagnation epochs determines the number of epochs training is allowed to
197 continue without changing the MSE by a fraction of <fann_get_cascade_candidate_change_fraction>.
199 See more info about this parameter in <fann_get_cascade_candidate_change_fraction>.
201 The default number of cascade candidate stagnation epochs is 12.
204 <fann_set_cascade_candidate_stagnation_epochs>, <fann_get_cascade_candidate_change_fraction>
206 This function appears in FANN >= 2.0.0.
208 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_candidate_stagnation_epochs(struct fann *ann);
211 /* Function: fann_set_cascade_candidate_stagnation_epochs
213 Sets the number of cascade candidate stagnation epochs.
216 <fann_get_cascade_candidate_stagnation_epochs>
218 This function appears in FANN >= 2.0.0.
220 FANN_EXTERNAL void FANN_API fann_set_cascade_candidate_stagnation_epochs(struct fann *ann,
221 unsigned int cascade_candidate_stagnation_epochs);
224 /* Function: fann_get_cascade_weight_multiplier
226 The weight multiplier is a parameter which is used to multiply the weights from the candidate neuron
227 before adding the neuron to the neural network. This parameter is usually between 0 and 1, and is used
228 to make the training a bit less aggressive.
230 The default weight multiplier is 0.4
233 <fann_set_cascade_weight_multiplier>
235 This function appears in FANN >= 2.0.0.
237 FANN_EXTERNAL fann_type FANN_API fann_get_cascade_weight_multiplier(struct fann *ann);
240 /* Function: fann_set_cascade_weight_multiplier
242 Sets the weight multiplier.
245 <fann_get_cascade_weight_multiplier>
247 This function appears in FANN >= 2.0.0.
249 FANN_EXTERNAL void FANN_API fann_set_cascade_weight_multiplier(struct fann *ann,
250 fann_type cascade_weight_multiplier);
253 /* Function: fann_get_cascade_candidate_limit
255 The candidate limit is a limit for how much the candidate neuron may be trained.
256 The limit is a limit on the proportion between the MSE and candidate score.
258 Set this to a lower value to avoid overfitting and to a higher if overfitting is
261 The default candidate limit is 1000.0
264 <fann_set_cascade_candidate_limit>
266 This function appears in FANN >= 2.0.0.
268 FANN_EXTERNAL fann_type FANN_API fann_get_cascade_candidate_limit(struct fann *ann);
271 /* Function: fann_set_cascade_candidate_limit
273 Sets the candidate limit.
276 <fann_get_cascade_candidate_limit>
278 This function appears in FANN >= 2.0.0.
280 FANN_EXTERNAL void FANN_API fann_set_cascade_candidate_limit(struct fann *ann,
281 fann_type cascade_candidate_limit);
284 /* Function: fann_get_cascade_max_out_epochs
286 The maximum out epochs determines the maximum number of epochs the output connections
287 may be trained after adding a new candidate neuron.
289 The default max out epochs is 150
292 <fann_set_cascade_max_out_epochs>
294 This function appears in FANN >= 2.0.0.
296 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_max_out_epochs(struct fann *ann);
299 /* Function: fann_set_cascade_max_out_epochs
301 Sets the maximum out epochs.
304 <fann_get_cascade_max_out_epochs>
306 This function appears in FANN >= 2.0.0.
308 FANN_EXTERNAL void FANN_API fann_set_cascade_max_out_epochs(struct fann *ann,
309 unsigned int cascade_max_out_epochs);
312 /* Function: fann_get_cascade_max_cand_epochs
314 The maximum candidate epochs determines the maximum number of epochs the input
315 connections to the candidates may be trained before adding a new candidate neuron.
317 The default max candidate epochs is 150
320 <fann_set_cascade_max_cand_epochs>
322 This function appears in FANN >= 2.0.0.
324 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_max_cand_epochs(struct fann *ann);
327 /* Function: fann_set_cascade_max_cand_epochs
329 Sets the max candidate epochs.
332 <fann_get_cascade_max_cand_epochs>
334 This function appears in FANN >= 2.0.0.
336 FANN_EXTERNAL void FANN_API fann_set_cascade_max_cand_epochs(struct fann *ann,
337 unsigned int cascade_max_cand_epochs);
340 /* Function: fann_get_cascade_num_candidates
342 The number of candidates used during training (calculated by multiplying <fann_get_cascade_activation_functions_count>,
343 <fann_get_cascade_activation_steepnesses_count> and <fann_get_cascade_num_candidate_groups>).
345 The actual candidates is defined by the <fann_get_cascade_activation_functions> and
346 <fann_get_cascade_activation_steepnesses> arrays. These arrays define the activation functions
347 and activation steepnesses used for the candidate neurons. If there are 2 activation functions
348 in the activation function array and 3 steepnesses in the steepness array, then there will be
349 2x3=6 different candidates which will be trained. These 6 different candidates can be copied into
350 several candidate groups, where the only difference between these groups is the initial weights.
351 If the number of groups is set to 2, then the number of candidate neurons will be 2x3x2=12. The
352 number of candidate groups is defined by <fann_set_cascade_num_candidate_groups>.
354 The default number of candidates is 6x4x2 = 48
357 <fann_get_cascade_activation_functions>, <fann_get_cascade_activation_functions_count>,
358 <fann_get_cascade_activation_steepnesses>, <fann_get_cascade_activation_steepnesses_count>,
359 <fann_get_cascade_num_candidate_groups>
361 This function appears in FANN >= 2.0.0.
363 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidates(struct fann *ann);
365 /* Function: fann_get_cascade_activation_functions_count
367 The number of activation functions in the <fann_get_cascade_activation_functions> array.
369 The default number of activation functions is 6.
372 <fann_get_cascade_activation_functions>, <fann_set_cascade_activation_functions>
374 This function appears in FANN >= 2.0.0.
376 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_activation_functions_count(struct fann *ann);
379 /* Function: fann_get_cascade_activation_functions
381 The cascade activation functions array is an array of the different activation functions used by
384 See <fann_get_cascade_num_candidates> for a description of which candidate neurons will be
385 generated by this array.
387 The default activation functions is {FANN_SIGMOID, FANN_SIGMOID_SYMMETRIC, FANN_GAUSSIAN, FANN_GAUSSIAN_SYMMETRIC, FANN_ELLIOT, FANN_ELLIOT_SYMMETRIC}
390 <fann_get_cascade_activation_functions_count>, <fann_set_cascade_activation_functions>,
391 <fann_activationfunc_enum>
393 This function appears in FANN >= 2.0.0.
395 FANN_EXTERNAL enum fann_activationfunc_enum * FANN_API fann_get_cascade_activation_functions(
399 /* Function: fann_set_cascade_activation_functions
401 Sets the array of cascade candidate activation functions. The array must be just as long
402 as defined by the count.
404 See <fann_get_cascade_num_candidates> for a description of which candidate neurons will be
405 generated by this array.
408 <fann_get_cascade_activation_steepnesses_count>, <fann_get_cascade_activation_steepnesses>
410 This function appears in FANN >= 2.0.0.
412 FANN_EXTERNAL void fann_set_cascade_activation_functions(struct fann *ann,
413 enum fann_activationfunc_enum *
414 cascade_activation_functions,
416 cascade_activation_functions_count);
419 /* Function: fann_get_cascade_activation_steepnesses_count
421 The number of activation steepnesses in the <fann_get_cascade_activation_functions> array.
423 The default number of activation steepnesses is 4.
426 <fann_get_cascade_activation_steepnesses>, <fann_set_cascade_activation_functions>
428 This function appears in FANN >= 2.0.0.
430 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_activation_steepnesses_count(struct fann *ann);
433 /* Function: fann_get_cascade_activation_steepnesses
435 The cascade activation steepnesses array is an array of the different activation functions used by
438 See <fann_get_cascade_num_candidates> for a description of which candidate neurons will be
439 generated by this array.
441 The default activation steepnesses is {0.25, 0.50, 0.75, 1.00}
444 <fann_set_cascade_activation_steepnesses>, <fann_get_cascade_activation_steepnesses_count>
446 This function appears in FANN >= 2.0.0.
448 FANN_EXTERNAL fann_type * FANN_API fann_get_cascade_activation_steepnesses(struct fann *ann);
451 /* Function: fann_set_cascade_activation_steepnesses
453 Sets the array of cascade candidate activation steepnesses. The array must be just as long
454 as defined by the count.
456 See <fann_get_cascade_num_candidates> for a description of which candidate neurons will be
457 generated by this array.
460 <fann_get_cascade_activation_steepnesses>, <fann_get_cascade_activation_steepnesses_count>
462 This function appears in FANN >= 2.0.0.
464 FANN_EXTERNAL void fann_set_cascade_activation_steepnesses(struct fann *ann,
466 cascade_activation_steepnesses,
468 cascade_activation_steepnesses_count);
470 /* Function: fann_get_cascade_num_candidate_groups
472 The number of candidate groups is the number of groups of identical candidates which will be used
475 This number can be used to have more candidates without having to define new parameters for the candidates.
477 See <fann_get_cascade_num_candidates> for a description of which candidate neurons will be
478 generated by this parameter.
480 The default number of candidate groups is 2
483 <fann_set_cascade_num_candidate_groups>
485 This function appears in FANN >= 2.0.0.
487 FANN_EXTERNAL unsigned int FANN_API fann_get_cascade_num_candidate_groups(struct fann *ann);
490 /* Function: fann_set_cascade_num_candidate_groups
492 Sets the number of candidate groups.
495 <fann_get_cascade_num_candidate_groups>
497 This function appears in FANN >= 2.0.0.
499 FANN_EXTERNAL void FANN_API fann_set_cascade_num_candidate_groups(struct fann *ann,
500 unsigned int cascade_num_candidate_groups);