XCSF 1.4.8
XCSF learning classifier system
Loading...
Searching...
No Matches
gp.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 ArgsGPTree {
32 double max;
33 double min;
37 int max_len;
38 double *constants;
39};
40
44struct GPTree {
45 int *tree;
46 int len;
47 int pos;
48 double *mu;
49};
50
51void
52tree_free(const struct GPTree *gp);
53
54void
55tree_rand(struct GPTree *gp, const struct ArgsGPTree *args);
56
57void
58tree_copy(struct GPTree *dest, const struct GPTree *src);
59
60void
61tree_print(const struct GPTree *gp, const struct ArgsGPTree *args);
62
63char *
64tree_json_export(const struct GPTree *gp, const struct ArgsGPTree *args);
65
66void
67tree_json_import(struct GPTree *gp, const struct ArgsGPTree *args,
68 const cJSON *json);
69
70double
71tree_eval(struct GPTree *gp, const struct ArgsGPTree *args, const double *x);
72
73void
74tree_crossover(struct GPTree *p1, struct GPTree *p2);
75
76bool
77tree_mutate(struct GPTree *gp, const struct ArgsGPTree *args);
78
79size_t
80tree_save(const struct GPTree *gp, FILE *fp);
81
82size_t
83tree_load(struct GPTree *gp, FILE *fp);
84
85void
86tree_args_init(struct ArgsGPTree *args);
87
88void
89tree_args_free(struct ArgsGPTree *args);
90
91char *
92tree_args_json_import(struct ArgsGPTree *args, cJSON *json);
93
94char *
95tree_args_json_export(const struct ArgsGPTree *args);
96
97size_t
98tree_args_save(const struct ArgsGPTree *args, FILE *fp);
99
100size_t
101tree_args_load(struct ArgsGPTree *args, FILE *fp);
102
103void
105
106/* parameter setters */
107
108void
109tree_param_set_max(struct ArgsGPTree *args, const double a);
110
111void
112tree_param_set_min(struct ArgsGPTree *args, const double a);
113
114void
115tree_param_set_n_inputs(struct ArgsGPTree *args, const int a);
116
117void
118tree_param_set_n_constants(struct ArgsGPTree *args, const int a);
119
120void
121tree_param_set_init_depth(struct ArgsGPTree *args, const int a);
122
123void
124tree_param_set_max_len(struct ArgsGPTree *args, const int a);
void tree_json_import(struct GPTree *gp, const struct ArgsGPTree *args, const cJSON *json)
Creates a GP tree from a cJSON object.
Definition gp.c:273
char * tree_args_json_export(const struct ArgsGPTree *args)
Returns a json formatted string of the GP tree parameters.
Definition gp.c:449
char * tree_args_json_import(struct ArgsGPTree *args, cJSON *json)
Sets the GP tree parameters from a cJSON object.
Definition gp.c:469
char * tree_json_export(const struct GPTree *gp, const struct ArgsGPTree *args)
Returns a json formatted string representation of a GP tree.
Definition gp.c:253
void tree_args_free(struct ArgsGPTree *args)
Frees memory used by GP tree parameters.
Definition gp.c:438
size_t tree_load(struct GPTree *gp, FILE *fp)
Reads a GP tree from a file.
Definition gp.c:400
void tree_param_set_max_len(struct ArgsGPTree *args, const int a)
Definition gp.c:598
void tree_crossover(struct GPTree *p1, struct GPTree *p2)
Performs sub-tree crossover.
Definition gp.c:318
size_t tree_save(const struct GPTree *gp, FILE *fp)
Writes the GP tree to a file.
Definition gp.c:383
void tree_print(const struct GPTree *gp, const struct ArgsGPTree *args)
Prints a GP tree.
Definition gp.c:289
void tree_param_set_max(struct ArgsGPTree *args, const double a)
Definition gp.c:553
void tree_param_set_n_inputs(struct ArgsGPTree *args, const int a)
Definition gp.c:565
double tree_eval(struct GPTree *gp, const struct ArgsGPTree *args, const double *x)
Evaluates a GP tree.
Definition gp.c:133
void tree_param_set_n_constants(struct ArgsGPTree *args, const int a)
Definition gp.c:576
void tree_args_init_constants(struct ArgsGPTree *args)
Builds global constants used by GP trees.
Definition gp.c:539
void tree_param_set_init_depth(struct ArgsGPTree *args, const int a)
Definition gp.c:587
bool tree_mutate(struct GPTree *gp, const struct ArgsGPTree *args)
Performs point mutation on a GP tree.
Definition gp.c:355
void tree_args_init(struct ArgsGPTree *args)
Sets tree GP parameters to default values.
Definition gp.c:422
size_t tree_args_load(struct ArgsGPTree *args, FILE *fp)
Loads Tree GP parameters.
Definition gp.c:521
void tree_param_set_min(struct ArgsGPTree *args, const double a)
Definition gp.c:559
void tree_copy(struct GPTree *dest, const struct GPTree *src)
Copies a GP tree.
Definition gp.c:302
void tree_free(const struct GPTree *gp)
Frees a GP tree.
Definition gp.c:119
size_t tree_args_save(const struct ArgsGPTree *args, FILE *fp)
Saves Tree GP parameters.
Definition gp.c:501
void tree_rand(struct GPTree *gp, const struct ArgsGPTree *args)
Creates a random GP tree.
Definition gp.c:102
Parameters for initialising GP trees.
Definition gp.h:31
double * constants
Constants available for GP trees.
Definition gp.h:38
int n_constants
Number of constants available.
Definition gp.h:35
int init_depth
Initial depth.
Definition gp.h:36
int max_len
Maximum initial length.
Definition gp.h:37
double min
Minimum value of a constant.
Definition gp.h:33
int n_inputs
Number of inputs.
Definition gp.h:34
double max
Maximum value of a constant.
Definition gp.h:32
GP tree data structure.
Definition gp.h:44
int * tree
Flattened tree representation of functions and terminals.
Definition gp.h:45
int pos
Current position in the tree.
Definition gp.h:47
double * mu
Mutation rates.
Definition gp.h:48
int len
Size of the tree.
Definition gp.h:46
XCSF data structures.