1 /*
2 Fast Artificial Neural Network Library (fann)
3 Copyright (C) 2003-2012 Steffen Nissen (sn@leenissen.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_error_h__
21 #define __fann_error_h__
22 
23 #include <stdio.h>
24 
25 #define FANN_ERRSTR_MAX 128
26 struct fann_error;
27 
28 /* Section: FANN Error Handling
29 
30    Errors from the fann library are usually reported on stderr.
31    It is however possible to redirect these error messages to a file,
32    or completely ignore them by the <fann_set_error_log> function.
33 
34    It is also possible to inspect the last error message by using the
35    <fann_get_errno> and <fann_get_errstr> functions.
36  */
37 
38 /* Enum: fann_errno_enum
39 	Used to define error events on <struct fann> and <struct fann_train_data>.
40 
41 	See also:
42 		<fann_get_errno>, <fann_reset_errno>, <fann_get_errstr>
43 
44 	FANN_E_NO_ERROR - No error
45 	FANN_E_CANT_OPEN_CONFIG_R - Unable to open configuration file for reading
46 	FANN_E_CANT_OPEN_CONFIG_W - Unable to open configuration file for writing
47 	FANN_E_WRONG_CONFIG_VERSION - Wrong version of configuration file
48 	FANN_E_CANT_READ_CONFIG - Error reading info from configuration file
49 	FANN_E_CANT_READ_NEURON - Error reading neuron info from configuration file
50 	FANN_E_CANT_READ_CONNECTIONS - Error reading connections from configuration file
51 	FANN_E_WRONG_NUM_CONNECTIONS - Number of connections not equal to the number expected
52 	FANN_E_CANT_OPEN_TD_W - Unable to open train data file for writing
53 	FANN_E_CANT_OPEN_TD_R - Unable to open train data file for reading
54 	FANN_E_CANT_READ_TD - Error reading training data from file
55 	FANN_E_CANT_ALLOCATE_MEM - Unable to allocate memory
56 	FANN_E_CANT_TRAIN_ACTIVATION - Unable to train with the selected activation function
57 	FANN_E_CANT_USE_ACTIVATION - Unable to use the selected activation function
58 	FANN_E_TRAIN_DATA_MISMATCH - Irreconcilable differences between two <struct fann_train_data> structures
59 	FANN_E_CANT_USE_TRAIN_ALG - Unable to use the selected training algorithm
60 	FANN_E_TRAIN_DATA_SUBSET - Trying to take subset which is not within the training set
61 	FANN_E_INDEX_OUT_OF_BOUND - Index is out of bound
62 	FANN_E_SCALE_NOT_PRESENT - Scaling parameters not present
63     FANN_E_INPUT_NO_MATCH - The number of input neurons in the ann and data don't match
64     FANN_E_OUTPUT_NO_MATCH - The number of output neurons in the ann and data don't match
65 */
66 enum fann_errno_enum
67 {
68 	FANN_E_NO_ERROR = 0,
69 	FANN_E_CANT_OPEN_CONFIG_R,
70 	FANN_E_CANT_OPEN_CONFIG_W,
71 	FANN_E_WRONG_CONFIG_VERSION,
72 	FANN_E_CANT_READ_CONFIG,
73 	FANN_E_CANT_READ_NEURON,
74 	FANN_E_CANT_READ_CONNECTIONS,
75 	FANN_E_WRONG_NUM_CONNECTIONS,
76 	FANN_E_CANT_OPEN_TD_W,
77 	FANN_E_CANT_OPEN_TD_R,
78 	FANN_E_CANT_READ_TD,
79 	FANN_E_CANT_ALLOCATE_MEM,
80 	FANN_E_CANT_TRAIN_ACTIVATION,
81 	FANN_E_CANT_USE_ACTIVATION,
82 	FANN_E_TRAIN_DATA_MISMATCH,
83 	FANN_E_CANT_USE_TRAIN_ALG,
84 	FANN_E_TRAIN_DATA_SUBSET,
85 	FANN_E_INDEX_OUT_OF_BOUND,
86 	FANN_E_SCALE_NOT_PRESENT,
87 	FANN_E_INPUT_NO_MATCH,
88 	FANN_E_OUTPUT_NO_MATCH
89 };
90 
91 /* Group: Error Handling */
92 
93 /* Function: fann_set_error_log
94 
95    Change where errors are logged to. Both <struct fann> and <struct fann_data> can be
96    casted to <struct fann_error>, so this function can be used to set either of these.
97 
98    If log_file is NULL, no errors will be printed.
99 
100    If errdata is NULL, the default log will be set. The default log is the log used when creating
101    <struct fann> and <struct fann_data>. This default log will also be the default for all new structs
102    that are created.
103 
104    The default behavior is to log them to stderr.
105 
106    See also:
107     <struct fann_error>
108 
109    This function appears in FANN >= 1.1.0.
110  */
111 FANN_EXTERNAL void FANN_API fann_set_error_log(struct fann_error *errdat, FILE * log_file);
112 
113 
114 /* Function: fann_get_errno
115 
116    Returns the last error number.
117 
118    See also:
119     <fann_errno_enum>, <fann_reset_errno>
120 
121    This function appears in FANN >= 1.1.0.
122  */
123 FANN_EXTERNAL enum fann_errno_enum FANN_API fann_get_errno(struct fann_error *errdat);
124 
125 
126 /* Function: fann_reset_errno
127 
128    Resets the last error number.
129 
130    This function appears in FANN >= 1.1.0.
131  */
132 FANN_EXTERNAL void FANN_API fann_reset_errno(struct fann_error *errdat);
133 
134 
135 /* Function: fann_reset_errstr
136 
137    Resets the last error string.
138 
139    This function appears in FANN >= 1.1.0.
140  */
141 FANN_EXTERNAL void FANN_API fann_reset_errstr(struct fann_error *errdat);
142 
143 
144 /* Function: fann_get_errstr
145 
146    Returns the last errstr.
147 
148    This function calls <fann_reset_errno> and <fann_reset_errstr>
149 
150    This function appears in FANN >= 1.1.0.
151  */
152 FANN_EXTERNAL char *FANN_API fann_get_errstr(struct fann_error *errdat);
153 
154 
155 /* Function: fann_print_error
156 
157    Prints the last error to stderr.
158 
159    This function appears in FANN >= 1.1.0.
160  */
161 FANN_EXTERNAL void FANN_API fann_print_error(struct fann_error *errdat);
162 
163 extern FILE * fann_default_error_log;
164 
165 #endif
166