2
* GENANN - Minimal C Artificial Neural Network
4
* Copyright (c) 2015, 2016 Lewis Van Winkle
8
* This software is provided 'as-is', without any express or implied
9
* warranty. In no event will the authors be held liable for any damages
10
* arising from the use of this software.
12
* Permission is granted to anyone to use this software for any purpose,
13
* including commercial applications, and to alter it and redistribute it
14
* freely, subject to the following restrictions:
16
* 1. The origin of this software must not be misrepresented; you must not
17
* claim that you wrote the original software. If you use this software
18
* in a product, an acknowledgement in the product documentation would be
19
* appreciated but is not required.
20
* 2. Altered source versions must be plainly marked as such, and must not be
21
* misrepresented as being the original software.
22
* 3. This notice may not be removed or altered from any source distribution.
37
/* We use the following for uniform random numbers between 0 and 1.
38
* If you have a better function, redefine this macro. */
39
#define GENANN_RANDOM() (((double)rand())/RAND_MAX)
43
typedef double (*genann_actfun)(double a);
46
typedef struct genann {
47
/* How many inputs, outputs, and hidden neurons. */
48
int inputs, hidden_layers, hidden, outputs;
50
/* Which activation function to use for hidden neurons. Default: gennann_act_sigmoid_cached*/
51
genann_actfun activation_hidden;
53
/* Which activation function to use for output. Default: gennann_act_sigmoid_cached*/
54
genann_actfun activation_output;
56
/* Total number of weights, and size of weights buffer. */
59
/* Total number of neurons + inputs and size of output buffer. */
62
/* All weights (total_weights long). */
65
/* Stores input array and output of each neuron (total_neurons long). */
68
/* Stores delta of each hidden and output neuron (total_neurons - inputs long). */
75
/* Creates and returns a new ann. */
76
genann *genann_init(int inputs, int hidden_layers, int hidden, int outputs);
78
/* Creates ANN from file saved with genann_write. */
79
genann *genann_read(FILE *in);
81
/* Sets weights randomly. Called by init. */
82
void genann_randomize(genann *ann);
84
/* Returns a new copy of ann. */
85
genann *genann_copy(genann const *ann);
87
/* Frees the memory used by an ann. */
88
void genann_free(genann *ann);
90
/* Runs the feedforward algorithm to calculate the ann's output. */
91
double const *genann_run(genann const *ann, double const *inputs);
93
/* Does a single backprop update. */
94
void genann_train(genann const *ann, double const *inputs, double const *desired_outputs, double learning_rate);
97
void genann_write(genann const *ann, FILE *out);
100
double genann_act_sigmoid(double a);
101
double genann_act_sigmoid_cached(double a);
102
double genann_act_threshold(double a);
103
double genann_act_linear(double a);
110
#endif /*__GENANN_H__*/