]> ruin.nu Git - germs.git/blob - fann/src/include/fann_internal.h
Make it possible to build statically against the included fann library.
[germs.git] / fann / src / include / fann_internal.h
1 /*
2 Fast Artificial Neural Network Library (fann)
3 Copyright (C) 2003 Steffen Nissen (lukesky@diku.dk)
4
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.
9
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.
14
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
18 */
19
20 #ifndef __fann_internal_h__
21 #define __fann_internal_h__
22 /* internal include file, not to be included directly
23  */
24
25 #include <math.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "fann_data.h"
29
30 #define FANN_FIX_VERSION "FANN_FIX_2.0"
31 #define FANN_FLO_VERSION "FANN_FLO_2.0"
32
33 #ifdef FIXEDFANN
34 #define FANN_CONF_VERSION FANN_FIX_VERSION
35 #else
36 #define FANN_CONF_VERSION FANN_FLO_VERSION
37 #endif
38
39 #define FANN_GET(type, name) \
40 FANN_EXTERNAL type FANN_API fann_get_ ## name(struct fann *ann) \
41 { \
42         return ann->name; \
43 }
44
45 #define FANN_SET(type, name) \
46 FANN_EXTERNAL void FANN_API fann_set_ ## name(struct fann *ann, type value) \
47 { \
48         ann->name = value; \
49 }
50
51 #define FANN_GET_SET(type, name) \
52 FANN_GET(type, name) \
53 FANN_SET(type, name)
54
55
56 struct fann_train_data;
57
58 struct fann *fann_allocate_structure(unsigned int num_layers);
59 void fann_allocate_neurons(struct fann *ann);
60
61 void fann_allocate_connections(struct fann *ann);
62
63 int fann_save_internal(struct fann *ann, const char *configuration_file,
64                                            unsigned int save_as_fixed);
65 int fann_save_internal_fd(struct fann *ann, FILE * conf, const char *configuration_file,
66                                                   unsigned int save_as_fixed);
67 int fann_save_train_internal(struct fann_train_data *data, const char *filename,
68                                                           unsigned int save_as_fixed, unsigned int decimal_point);
69 int fann_save_train_internal_fd(struct fann_train_data *data, FILE * file, const char *filename,
70                                                                  unsigned int save_as_fixed, unsigned int decimal_point);
71
72 void fann_update_stepwise(struct fann *ann);
73 void fann_seed_rand();
74
75 void fann_error(struct fann_error *errdat, const enum fann_errno_enum errno_f, ...);
76 void fann_init_error_data(struct fann_error *errdat);
77
78 struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file);
79 struct fann_train_data *fann_read_train_from_fd(FILE * file, const char *filename);
80
81 void fann_compute_MSE(struct fann *ann, fann_type * desired_output);
82 void fann_update_output_weights(struct fann *ann);
83 void fann_backpropagate_MSE(struct fann *ann);
84 void fann_update_weights(struct fann *ann);
85 void fann_update_slopes_batch(struct fann *ann, struct fann_layer *layer_begin,
86                                                           struct fann_layer *layer_end);
87 void fann_update_weights_quickprop(struct fann *ann, unsigned int num_data,
88                                                                    unsigned int first_weight, unsigned int past_end);
89 void fann_update_weights_batch(struct fann *ann, unsigned int num_data, unsigned int first_weight,
90                                                            unsigned int past_end);
91 void fann_update_weights_irpropm(struct fann *ann, unsigned int first_weight,
92                                                                  unsigned int past_end);
93
94 void fann_clear_train_arrays(struct fann *ann);
95
96 fann_type fann_activation(struct fann * ann, unsigned int activation_function, fann_type steepness,
97                                                   fann_type value);
98
99 fann_type fann_activation_derived(unsigned int activation_function,
100                                                                   fann_type steepness, fann_type value, fann_type sum);
101
102 int fann_desired_error_reached(struct fann *ann, float desired_error);
103
104 /* Some functions for cascade */
105 int fann_train_outputs(struct fann *ann, struct fann_train_data *data, float desired_error);
106
107 float fann_train_outputs_epoch(struct fann *ann, struct fann_train_data *data);
108
109 int fann_train_candidates(struct fann *ann, struct fann_train_data *data);
110
111 fann_type fann_train_candidates_epoch(struct fann *ann, struct fann_train_data *data);
112
113 void fann_install_candidate(struct fann *ann);
114
115 int fann_initialize_candidates(struct fann *ann);
116
117 void fann_set_shortcut_connections(struct fann *ann);
118
119 /* called fann_max, in order to not interferre with predefined versions of max */
120 #define fann_max(x, y) (((x) > (y)) ? (x) : (y))
121 #define fann_min(x, y) (((x) < (y)) ? (x) : (y))
122 #define fann_safe_free(x) {if(x) { free(x); x = NULL; }}
123 #define fann_clip(x, lo, hi) (((x) < (lo)) ? (lo) : (((x) > (hi)) ? (hi) : (x)))
124 /*#define fann_clip(x, lo, hi) (x)*/
125
126 #define fann_rand(min_value, max_value) (((float)(min_value))+(((float)(max_value)-((float)(min_value)))*rand()/(RAND_MAX+1.0f)))
127
128 #define fann_abs(value) (((value) > 0) ? (value) : -(value))
129
130 #ifdef FIXEDFANN
131
132 #define fann_mult(x,y) ((x*y) >> decimal_point)
133 #define fann_div(x,y) (((x) << decimal_point)/y)
134 #define fann_random_weight() (fann_type)(fann_rand((0-multiplier)/10,multiplier/10))
135 /* sigmoid calculated with use of floats, only as reference */
136
137 #else
138
139 #define fann_mult(x,y) (x*y)
140 #define fann_div(x,y) (x/y)
141 #define fann_random_weight() (fann_rand(-0.1f,0.1f))
142
143 #endif
144
145 #endif