ANN  0.1.1.5
A library containing multiple neural network models written in C
feedforward.c
Go to the documentation of this file.
1 #include <stdlib.h>
5 
7 
8 
9 double PCFNN_NEURON_feedforward_inputs(struct PCFNN_NEURON *n, double *inputs, double(*f_act)(double), double(*f_act_de)(double))
10 {
11  if (f_act != NULL) n->f_act = f_act;
12  if (f_act_de != NULL) n->f_act_de = f_act_de;
13  if (n == NULL || inputs == NULL || n->f_act == NULL || n->f_act_de == NULL) return 0;
14  n->activation = n->bias;
15  for (size_t i = 0; i < n->size; ++i)
16  n->activation += n->weights[i] * inputs[i];
17  n->output = n->f_act(n->activation);
18  return n->output;
19 }
20 
21 
22 double PCFNN_NEURON_feedforward(struct PCFNN_NEURON *n, double(*f_act)(double), double(*f_act_de)(double))
23 {
24  if (f_act != NULL) n->f_act = f_act;
25  if (f_act_de != NULL) n->f_act_de = f_act_de;
26  if (n == NULL || n->f_act == NULL || n->f_act_de == NULL) return 0;
27  n->activation = n->bias;
28  for (size_t i = 0; i < n->size; ++i)
29  n->activation += n->weights[i] * n->inputs[i]->output;
30  n->output = n->f_act(n->activation);
31  return n->output;
32 }
33 
34 
36 {
37  if (l == NULL || l->type != PCFNN_LAYER_INPUT) return;
38  for (size_t i = 0; i < l->size; ++i)
39  {
40  l->neurons[i]->activation = inputs[i];
41  l->neurons[i]->output = l->neurons[i]->f_act(l->neurons[i]->activation);
42  }
43 }
44 
45 
47 {
48  if (l == NULL || l->type == PCFNN_LAYER_INPUT) return;
49  for(size_t i = 0; i < l->size; ++i)
50  PCFNN_NEURON_feedforward(l->neurons[i], NULL, NULL);
51 }
52 
53 
55 {
56  if (net == NULL) return;
58  for(size_t i = 0; i < net->size; ++i)
59  if (net->layers[i]->type != PCFNN_LAYER_INPUT)
61 }
62 
63 
65 {
66  if (net == NULL) return NULL;
67  double *output = malloc(sizeof(double) * net->outputl->size);
68  if (output == NULL) return NULL;
69  for(size_t i = 0; i < net->outputl->size; ++i)
70  output[i] = net->outputl->neurons[i]->output;
71  return output;
72 }
Neuron unit.
Definition: neuron.h:35
Layer unit.
Definition: layer.h:53
PCFNN_LAYER.
double activation
Definition: neuron.h:40
struct PCFNN_LAYER * inputl
Definition: network.h:30
void PCFNN_LAYER_feedforward(struct PCFNN_LAYER *l)
Feedforward the hidden layer l.
Definition: feedforward.c:46
struct PCFNN_LAYER ** layers
Definition: network.h:29
size_t size
Definition: layer.h:55
struct PCFNN_LAYER * outputl
Definition: network.h:30
struct PCFNN_NEURON ** inputs
Definition: neuron.h:42
size_t size
Definition: network.h:28
PCFNN_NEURON.
double output
Definition: neuron.h:38
double(* f_act_de)(double)
Definition: neuron.h:45
double * PCFNN_NETWORK_get_output(struct PCFNN_NETWORK *net)
Return a double array which is the output of the output layer of net.
Definition: feedforward.c:64
PCFNN_FEEDFORWARD.
void PCFNN_NETWORK_feedforward(struct PCFNN_NETWORK *net, double *inputs)
Feedforward the PCFNN_NETWORK net.
Definition: feedforward.c:54
void PCFNN_LAYER_feedforward_input(struct PCFNN_LAYER *l, double *inputs)
Feedforward the input layer l.
Definition: feedforward.c:35
PCFNN_NETWORK.
struct PCFNN_NEURON ** neurons
Definition: layer.h:56
double PCFNN_NEURON_feedforward_inputs(struct PCFNN_NEURON *n, double *inputs, double(*f_act)(double), double(*f_act_de)(double))
Feedforward the input neuron n.
Definition: feedforward.c:9
double bias
Definition: neuron.h:38
double * weights
Definition: neuron.h:37
double PCFNN_NEURON_feedforward(struct PCFNN_NEURON *n, double(*f_act)(double), double(*f_act_de)(double))
Feedforward the input neuron n.
Definition: feedforward.c:22
double(* f_act)(double)
Definition: neuron.h:44
enum PCFNN_LAYER_TYPE type
Definition: layer.h:62
Network unit.
Definition: network.h:27
size_t size
Definition: neuron.h:36