XCSF 1.4.8
XCSF learning classifier system
Loading...
Searching...
No Matches
neural.h
Go to the documentation of this file.
1/*
2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation, either version 3 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
24#pragma once
25
26#include "utils.h"
27#include <stdbool.h>
28#include <stdint.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32
33struct ArgsLayer;
34struct Layer;
35
39struct Llist {
40 struct Layer *layer;
41 struct Llist *prev;
42 struct Llist *next;
43};
44
48struct Net {
52 double *output;
53 struct Llist *head;
54 struct Llist *tail;
55 bool train;
56};
57
58bool
59neural_mutate(const struct Net *net);
60
61char *
62neural_json_export(const struct Net *net, const bool return_weights);
63
64void
65neural_json_import(struct Net *net, const struct ArgsLayer *arg,
66 const cJSON *json);
67
68double
69neural_output(const struct Net *net, const int IDX);
70
71double *
72neural_outputs(const struct Net *net);
73
74double
75neural_size(const struct Net *net);
76
77size_t
78neural_load(struct Net *net, FILE *fp);
79
80size_t
81neural_save(const struct Net *net, FILE *fp);
82
83void
84neural_copy(struct Net *dest, const struct Net *src);
85
86void
87neural_free(struct Net *net);
88
89void
90neural_init(struct Net *net);
91
92void
93neural_create(struct Net *net, struct ArgsLayer *arg);
94
95void
96neural_insert(struct Net *net, struct Layer *l, const int pos);
97
98void
99neural_remove(struct Net *net, const int pos);
100
101void
102neural_push(struct Net *net, struct Layer *l);
103
104void
105neural_pop(struct Net *net);
106
107void
108neural_learn(const struct Net *net, const double *output, const double *input);
109
110void
111neural_print(const struct Net *net, const bool print_weights);
112
113void
114neural_propagate(struct Net *net, const double *input, const bool train);
115
116void
117neural_rand(const struct Net *net);
118
119void
120neural_resize(const struct Net *net);
double * neural_outputs(const struct Net *net)
Returns the outputs from the output layer of a neural network.
Definition neural.c:384
void neural_push(struct Net *net, struct Layer *l)
Inserts a layer at the head of a neural network.
Definition neural.c:187
void neural_learn(const struct Net *net, const double *output, const double *input)
Performs a gradient descent update on a neural network.
Definition neural.c:328
bool neural_mutate(const struct Net *net)
Mutates a neural network.
Definition neural.c:257
double neural_size(const struct Net *net)
Returns the total number of non-zero weights in a neural network.
Definition neural.c:450
void neural_create(struct Net *net, struct ArgsLayer *arg)
Initialises and creates a new neural network from a parameter list.
Definition neural.c:54
double neural_output(const struct Net *net, const int IDX)
Returns the output of a specified neuron in the output layer of a neural network.
Definition neural.c:369
void neural_resize(const struct Net *net)
Resizes neural network layers as necessary.
Definition neural.c:290
char * neural_json_export(const struct Net *net, const bool return_weights)
Returns a json formatted string representation of a neural network.
Definition neural.c:407
size_t neural_load(struct Net *net, FILE *fp)
Reads a neural network from a file.
Definition neural.c:499
void neural_json_import(struct Net *net, const struct ArgsLayer *arg, const cJSON *json)
Creates a neural network from a cJSON object.
Definition neural.c:434
void neural_free(struct Net *net)
Frees a neural network.
Definition neural.c:224
void neural_remove(struct Net *net, const int pos)
Removes a layer from a neural network.
Definition neural.c:140
void neural_print(const struct Net *net, const bool print_weights)
Prints a neural network.
Definition neural.c:395
void neural_rand(const struct Net *net)
Randomises the layers within a neural network.
Definition neural.c:242
void neural_copy(struct Net *dest, const struct Net *src)
Copies a neural network.
Definition neural.c:208
void neural_init(struct Net *net)
Initialises an empty neural network.
Definition neural.c:37
void neural_propagate(struct Net *net, const double *input, const bool train)
Forward propagates a neural network.
Definition neural.c:310
void neural_pop(struct Net *net)
Removes the layer at the head of a neural network.
Definition neural.c:197
size_t neural_save(const struct Net *net, FILE *fp)
Writes a neural network to a file.
Definition neural.c:478
void neural_insert(struct Net *net, struct Layer *l, const int pos)
Inserts a layer into a neural network.
Definition neural.c:95
Parameters for initialising a neural network layer.
Neural network layer data structure.
Forward declaration of layer structure.
Definition neural.h:39
struct Llist * prev
Pointer to the previous layer (forward)
Definition neural.h:41
struct Layer * layer
Pointer to the layer data structure.
Definition neural.h:40
struct Llist * next
Pointer to the next layer (backward)
Definition neural.h:42
Neural network data structure.
Definition neural.h:48
int n_layers
Number of layers (hidden + output)
Definition neural.h:49
double * output
Pointer to the network output.
Definition neural.h:52
struct Llist * tail
Pointer to the tail layer (first layer)
Definition neural.h:54
struct Llist * head
Pointer to the head layer (output layer)
Definition neural.h:53
bool train
Whether the network is in training mode.
Definition neural.h:55
int n_outputs
Number of network outputs.
Definition neural.h:51
int n_inputs
Number of network inputs.
Definition neural.h:50
Utility functions for random number handling, etc.