XCSF 1.4.8
XCSF learning classifier system
Loading...
Searching...
No Matches
dgp.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 "xcsf.h"
27
31struct ArgsDGP {
33 int max_k;
34 int max_t;
35 int n;
37};
38
42struct Graph {
44 double *initial_state;
45 double *state;
46 double *tmp_input;
47 double *tmp_state;
49 int *function;
50 int klen;
51 int max_k;
52 int max_t;
53 int n;
55 int t;
56 double *mu;
57};
58
59bool
60graph_mutate(struct Graph *dgp);
61
62char *
63graph_json_export(const struct Graph *dgp);
64
65void
66graph_json_import(struct Graph *dgp, const struct ArgsDGP *args,
67 const cJSON *json);
68
69double
70graph_output(const struct Graph *dgp, const int IDX);
71
72size_t
73graph_load(struct Graph *dgp, FILE *fp);
74
75size_t
76graph_save(const struct Graph *dgp, FILE *fp);
77
78void
79graph_copy(struct Graph *dest, const struct Graph *src);
80
81void
82graph_free(const struct Graph *dgp);
83
84void
85graph_init(struct Graph *dgp, const struct ArgsDGP *args);
86
87void
88graph_print(const struct Graph *dgp);
89
90void
91graph_rand(struct Graph *dgp);
92
93void
94graph_reset(const struct Graph *dgp);
95
96void
97graph_update(const struct Graph *dgp, const double *inputs, const bool reset);
98
99void
100graph_args_init(struct ArgsDGP *args);
101
102char *
103graph_args_json_import(struct ArgsDGP *args, cJSON *json);
104
105char *
106graph_args_json_export(const struct ArgsDGP *args);
107
108size_t
109graph_args_save(const struct ArgsDGP *args, FILE *fp);
110
111size_t
112graph_args_load(struct ArgsDGP *args, FILE *fp);
113
114/* parameter setters */
115
116void
117graph_param_set_max_k(struct ArgsDGP *args, const int a);
118
119void
120graph_param_set_max_t(struct ArgsDGP *args, const int a);
121
122void
123graph_param_set_n(struct ArgsDGP *args, const int a);
124
125void
126graph_param_set_n_inputs(struct ArgsDGP *args, const int a);
127
128void
129graph_param_set_evolve_cycles(struct ArgsDGP *args, const bool a);
size_t graph_args_save(const struct ArgsDGP *args, FILE *fp)
Saves DGP parameters.
Definition dgp.c:687
void graph_print(const struct Graph *dgp)
Prints a DGP graph.
Definition dgp.c:333
void graph_param_set_max_t(struct ArgsDGP *args, const int a)
Definition dgp.c:730
char * graph_args_json_import(struct ArgsDGP *args, cJSON *json)
Sets the DGP graph parameters from a cJSON object.
Definition dgp.c:658
void graph_copy(struct Graph *dest, const struct Graph *src)
Copies a DGP graph.
Definition dgp.c:251
void graph_free(const struct Graph *dgp)
Frees a DGP graph.
Definition dgp.c:523
size_t graph_args_load(struct ArgsDGP *args, FILE *fp)
Loads DGP parameters.
Definition dgp.c:705
void graph_rand(struct Graph *dgp)
Randomises a specified DGP graph.
Definition dgp.c:296
void graph_param_set_n(struct ArgsDGP *args, const int a)
Definition dgp.c:741
size_t graph_save(const struct Graph *dgp, FILE *fp)
Writes DGP graph to a file.
Definition dgp.c:563
void graph_args_init(struct ArgsDGP *args)
Sets DGP parameters to default values.
Definition dgp.c:624
char * graph_json_export(const struct Graph *dgp)
Returns a json formatted string representation of a DGP graph.
Definition dgp.c:346
void graph_json_import(struct Graph *dgp, const struct ArgsDGP *args, const cJSON *json)
Creates a DGP graph from a cJSON object.
Definition dgp.c:477
void graph_update(const struct Graph *dgp, const double *inputs, const bool reset)
Updates a DGP graph T cycles.
Definition dgp.c:318
void graph_init(struct Graph *dgp, const struct ArgsDGP *args)
Initialises a new DGP graph.
Definition dgp.c:226
double graph_output(const struct Graph *dgp, const int IDX)
Returns the current state of a specified node in the graph.
Definition dgp.c:274
void graph_param_set_n_inputs(struct ArgsDGP *args, const int a)
Definition dgp.c:752
char * graph_args_json_export(const struct ArgsDGP *args)
Returns a json formatted string of the DGP parameters.
Definition dgp.c:639
void graph_param_set_max_k(struct ArgsDGP *args, const int a)
Definition dgp.c:719
size_t graph_load(struct Graph *dgp, FILE *fp)
Reads DGP graph from a file.
Definition dgp.c:588
void graph_param_set_evolve_cycles(struct ArgsDGP *args, const bool a)
Definition dgp.c:763
void graph_reset(const struct Graph *dgp)
Resets the states to their initial state.
Definition dgp.c:284
bool graph_mutate(struct Graph *dgp)
Mutates a specified DGP graph.
Definition dgp.c:540
Parameters for initialising DGP graphs.
Definition dgp.h:31
int max_t
Maximum number of update cycles.
Definition dgp.h:34
int max_k
Maximum number of connections a node may have.
Definition dgp.h:33
int n_inputs
Number of inputs to the graph.
Definition dgp.h:36
int n
Number of nodes in the graph.
Definition dgp.h:35
bool evolve_cycles
Whether to evolve the number of update cycles.
Definition dgp.h:32
Dynamical GP graph data structure.
Definition dgp.h:42
int n_inputs
Number of inputs to the graph.
Definition dgp.h:54
double * mu
Mutation rates.
Definition dgp.h:56
int * connectivity
Connectivity map.
Definition dgp.h:48
double * state
Current state of each node.
Definition dgp.h:45
double * initial_state
Initial node states.
Definition dgp.h:44
int t
Number of cycles to run.
Definition dgp.h:55
int n
Number of nodes.
Definition dgp.h:53
bool evolve_cycles
Whether to evolve the number of update cycles.
Definition dgp.h:43
int max_t
Maximum number of update cycles.
Definition dgp.h:52
int max_k
Maximum number of connections a node may have.
Definition dgp.h:51
double * tmp_state
Temporary storage for synchronous update.
Definition dgp.h:47
int * function
Node activation functions.
Definition dgp.h:49
double * tmp_input
Temporary storage for updating the graph.
Definition dgp.h:46
int klen
Length of connectivity map.
Definition dgp.h:50
XCSF data structures.