XCSF  1.4.7
XCSF learning classifier system
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 
31 struct ArgsDGP {
33  int max_k;
34  int max_t;
35  int n;
36  int n_inputs;
37 };
38 
42 struct Graph {
44  double *initial_state;
45  double *state;
46  double *tmp_input;
47  double *tmp_state;
48  int *connectivity;
49  int *function;
50  int klen;
51  int max_k;
52  int max_t;
53  int n;
54  int n_inputs;
55  int t;
56  double *mu;
57 };
58 
59 bool
60 graph_mutate(struct Graph *dgp);
61 
62 char *
63 graph_json_export(const struct Graph *dgp);
64 
65 void
66 graph_json_import(struct Graph *dgp, const struct ArgsDGP *args,
67  const cJSON *json);
68 
69 double
70 graph_output(const struct Graph *dgp, const int IDX);
71 
72 size_t
73 graph_load(struct Graph *dgp, FILE *fp);
74 
75 size_t
76 graph_save(const struct Graph *dgp, FILE *fp);
77 
78 void
79 graph_copy(struct Graph *dest, const struct Graph *src);
80 
81 void
82 graph_free(const struct Graph *dgp);
83 
84 void
85 graph_init(struct Graph *dgp, const struct ArgsDGP *args);
86 
87 void
88 graph_print(const struct Graph *dgp);
89 
90 void
91 graph_rand(struct Graph *dgp);
92 
93 void
94 graph_reset(const struct Graph *dgp);
95 
96 void
97 graph_update(const struct Graph *dgp, const double *inputs, const bool reset);
98 
99 void
100 graph_args_init(struct ArgsDGP *args);
101 
102 char *
103 graph_args_json_import(struct ArgsDGP *args, cJSON *json);
104 
105 char *
106 graph_args_json_export(const struct ArgsDGP *args);
107 
108 size_t
109 graph_args_save(const struct ArgsDGP *args, FILE *fp);
110 
111 size_t
112 graph_args_load(struct ArgsDGP *args, FILE *fp);
113 
114 /* parameter setters */
115 
116 void
117 graph_param_set_max_k(struct ArgsDGP *args, const int a);
118 
119 void
120 graph_param_set_max_t(struct ArgsDGP *args, const int a);
121 
122 void
123 graph_param_set_n(struct ArgsDGP *args, const int a);
124 
125 void
126 graph_param_set_n_inputs(struct ArgsDGP *args, const int a);
127 
128 void
129 graph_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
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_t(struct ArgsDGP *args, const int a)
Definition: dgp.c:730
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
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_json_export(const struct Graph *dgp)
Returns a json formatted string representation of a DGP graph.
Definition: dgp.c:346
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
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_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
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.