libfgen
0.1.15
Library for optimization using a genetic algorithm or particle swarm optimization
|
Data Structures | |
struct | Ffit |
Defines | |
#define | FFIT_MAPPING_LINEAR 0 |
#define | FFIT_MAPPING_SQUARE 1 |
#define | FFIT_MAPPING_CUBE 2 |
#define | FFIT_MAPPING_LOG 3 |
#define | FFIT_MAPPING_BINOMIAL_1_TO_5 4 |
#define | FFIT_MAPPING_BINOMIAL_1_TO_7 5 |
#define | FFIT_OPTIMIZATION_FGEN_ELEMENT 1 |
#define | FFIT_OPTIMIZATION_ARCHIPELAGO_ELEMENT 2 |
#define | FFIT_OPTIMIZATION_HILL_CLIMB_ELEMENT 4 |
#define | FFIT_OPTIMIZATION_FPSO_ELEMENT 8 |
#define | FFIT_OPTIMIZATION_FGEN_REAL_VALUED_ELEMENT 16 |
#define | FFIT_OPTIMIZATION_FGEN FFIT_OPTIMIZATION_FGEN_ELEMENT |
#define | FFIT_OPTIMIZATION_FGEN_ARCHIPELAGO (FFIT_OPTIMIZATION_FGEN_ELEMENT | FFIT_OPTIMIZATION_ARCHIPELAGO_ELEMENT) |
#define | FFIT_OPTIMIZATION_FGEN_WITH_HILL_CLIMB (FFIT_OPTIMIZATION_FGEN_ELEMENT | FFIT_OPTIMIZATION_HILL_CLIMB_ELEMENT) |
#define | FFIT_OPTIMIZATION_FGEN_ARCHIPELAGO_WITH_HILL_CLIMB |
#define | FFIT_OPTIMIZATION_FPSO FFIT_OPTIMIZATION_FPSO_ELEMENT |
#define | FFIT_OPTIMIZATION_FGEN_REAL_VALUED |
#define | FFIT_OPTIMIZATION_FGEN_REAL_VALUED_ARCHIPELAGO |
#define | FFIT_THREADING_DISABLED 0 |
#define | FFIT_THREADING_ENABLED 1 |
Typedefs | |
typedef double(* | FfitCalculateErrorFunc )(const Ffit *fit, const double *param) |
typedef void(* | FfitGenerationCallbackFunc )(Ffit *fit, int generation, const double *best_param, double best_error) |
Functions | |
FGEN_API Ffit * | ffit_create (int nu_params, FfitGenerationCallbackFunc ffit_generation_callback_func, FfitCalculateErrorFunc ffit_calculate_error_func) |
FGEN_API void | ffit_set_parameter_range_and_mapping (Ffit *fit, int index, double range_min, double range_max, int mapping) |
FGEN_API void | ffit_run_fgen_with_defaults (Ffit *fit) |
FGEN_API void | ffit_run_fgen (Ffit *fit, int population_size, int nu_bits_per_param, int selection_type, FgenCrossoverFunc crossover, float crossover_probability_float, float mutation_per_bit_probability_float, float macro_mutation_probability_float) |
FGEN_API void | ffit_run_fgen_archipelago (Ffit *fit, int nu_islands, int population_size, int nu_bits_per_param, int selection_type, FgenCrossoverFunc crossover, float crossover_probability_float, float mutation_probability_float, float macro_mutation_probability_float, float migration_probability_float, int migration_interval) |
FGEN_API void | ffit_run_fgen_real_valued (Ffit *fit, int population_size, int selection_type, float crossover_probability_float, float mutation_per_bit_probability_float, float macro_mutation_probability_float) |
FGEN_API void | ffit_run_fgen_real_valued_archipelago (Ffit *fit, int nu_islands, int population_size, int selection_type, float crossover_probability_float, float mutation_probability_float, float macro_mutation_probability_float, float migration_probability_float, int migration_interval) |
FGEN_API void | ffit_run_fpso (Ffit *fit, int population_size, int topology, int bounding_strategy, double omega, double phi1, double phi2) |
FGEN_API void | ffit_signal_stop (Ffit *fit) |
FGEN_API void | ffit_signal_model_change (Ffit *fit) |
FGEN_API void | ffit_destroy (Ffit *fit) |
FGEN_API int | ffit_get_population_size (const Ffit *fit) |
FGEN_API void | ffit_get_individual_params (const Ffit *fit, int index, double *params) |
FGEN_API void * | ffit_get_population (const Ffit *fit) |
FGEN_API void | ffit_set_threading (Ffit *fit, int threading_level) |
FGEN_API void | ffit_set_generation_callback_interval (Ffit *fit, int interval) |
#define FFIT_OPTIMIZATION_FGEN_ARCHIPELAGO_WITH_HILL_CLIMB |
#define FFIT_OPTIMIZATION_FGEN_REAL_VALUED |
#define FFIT_OPTIMIZATION_FGEN_REAL_VALUED_ARCHIPELAGO |
typedef double(* FfitCalculateErrorFunc)(const Ffit *fit, const double *param) |
The error calculation function evaluation function. The fit and the parameters to be evaluated are passed as arguments. See ffit_create().
typedef void(* FfitGenerationCallbackFunc)(Ffit *fit, int generation, const double *best_param, double best_error) |
The generation callback function that is called every n generations as defined by the generation callback interval. The parameters that generated the best (lowest) result in the calculate error function are passed as arguments, as is the associated error value.
FGEN_API Ffit* ffit_create | ( | int | nu_params, |
FfitGenerationCallbackFunc | generation_callback_func, | ||
FfitCalculateErrorFunc | calculate_error_func | ||
) |
Create a new fit datastructure.
nu_params | The number of parameters in the solution. |
generation_callback_func | The generation callback function that is called after every n generations in the optimization algorithm, where n is the generation callback interval (see ffit_set_generation_callback_interval()). |
calculate_error_func | The error evaluation function that returns the error value of the provided parameter solution. |
FGEN_API void ffit_set_parameter_range_and_mapping | ( | Ffit * | fit, |
int | index, | ||
double | range_min, | ||
double | range_max, | ||
int | mapping | ||
) |
Set the range and mapping of a parameter. In general this function must be called, after ffit_create(), for each parameter. Counting starts with zero, so for example, if nu_params in ffit_create was 3, this function should be called three times with index equal to 0, 1 and 2 respectively.
fit | The fit to which the settings apply. |
index | The index (starting with 0) of the parameter. |
range_min | The lower bound of the range of the parameter. |
range_max | The upper bound (exclusive) of the range of the parameter. |
mapping | The mathematical mapping of the parameter range based on the behaviour of standard functions in the range [0, 1[. For example, use FFIT_MAPPING_LINEAR for a standard linear mapping. This affects the efficiency of the search algorithm only, and does not affect the range of parameters or the way parameters are presented to the callback functions. |
FGEN_API void ffit_run_fgen_with_defaults | ( | Ffit * | fit | ) |
Run a fit using a genetic algorithm with default settings. Note that this function reseeds the random number generator using the system timer so that every run is different. Default settings are:
fit | The fit to run. Must have been created previously using ffit_create(). |
FGEN_API void ffit_run_fgen | ( | Ffit * | fit, |
int | population_size, | ||
int | nu_bits_per_param, | ||
int | selection_type, | ||
FgenCrossoverFunc | crossover, | ||
float | crossover_probability_float, | ||
float | mutation_per_bit_probability_float, | ||
float | macro_mutation_probability_float | ||
) |
Run a fit using a genetic algorithm with specified settings. Note that this function reseeds the random number generator using the system timer so that every run is different. If ffit_set_threading() was called with FFIT_THREADING_ENABLED as argument prior to calling this function, the fit will be run with threaded error (fitness) calculations in each generation.
fit | The fit to run. Must have been created previously using ffit_create(). |
population_size | The size of GA population. |
nu_bits_per_param | The number of bits used for the parameter representation. Must be 16, 32 or 64. |
selection_type | The fgen selection type (for example, FGEN_ELITIST_SUS). |
crossover | The crossover operator function (for example, fgen_crossover_uniform_per_element). |
crossover_probability_float | The crossover rate. |
mutation_per_bit_probability_float | The mutation rate per bit. |
macro_mutation_probability_float | The macro-mutation probability per data element. |
FGEN_API void ffit_run_fgen_archipelago | ( | Ffit * | fit, |
int | nu_islands, | ||
int | population_size, | ||
int | nu_bits_per_param, | ||
int | selection_type, | ||
FgenCrossoverFunc | crossover, | ||
float | crossover_probability_float, | ||
float | mutation_probability_float, | ||
float | macro_mutation_probability_float, | ||
float | migration_probability_float, | ||
int | migration_interval | ||
) |
Run a fit using an archipelago of genetic algorithms with migration. Note that this function reseeds the random number generator using the system timer so that every run is different. The populations are automatically created and the fitting process is started. If ffit_set_threading() was called with FFIT_THREADING_ENABLED as argument prior to calling this function, the fit will be run threaded.
fit | The fit to run. |
nu_islands | The number of islands in the archipelago. |
population_size | The size of each GA population. |
nu_bits_per_param | The number of bits used for the parameter representation. Must be 16, 32 or 64. |
selection_type | The fgen selection type. |
crossover | The crossover operator function. |
crossover_probability_float | The crossover rate. |
mutation_probability_float | The mutation rate per bit. |
macro_mutation_probability_float | The macro-mutation probability per data element. |
migration_probability_float | The migration probability per individual. |
migration_interval | The migration interval. Must be greater than 0. A value of 1 means migrations happens every generation, a value of 50 means migrations only happens every 50th generation. |
FGEN_API void ffit_run_fgen_real_valued | ( | Ffit * | fit, |
int | population_size, | ||
int | selection_type, | ||
float | crossover_probability_float, | ||
float | mutation_per_element_probability_float, | ||
float | macro_mutation_probability_float | ||
) |
Run a fit using a genetic algorithm with real-valued chromosomes with specified settings. Note that ffit_run_fgen works very well with real valued parameters, despite using bitstring representation internally. This function uses real-valued parameters (double) internally in the genetic algorithm. Note that this function reseeds the random number generator using the system timer so that every run is different.
fit | The fit to run. |
population_size | The size of GA population. |
selection_type | The fgen selection type. |
crossover_probability_float | The crossover rate. |
mutation_per_bit_probability_float | The mutation probability per data element. |
macro_mutation_probability_float | The macro-mutation probability per data element. |
FGEN_API void ffit_run_fgen_real_valued_archipelago | ( | Ffit * | fit, |
int | nu_islands, | ||
int | population_size, | ||
int | selection_type, | ||
float | crossover_probability_float, | ||
float | mutation_probability_float, | ||
float | macro_mutation_probability_float, | ||
float | migration_probability_float, | ||
int | migration_interval | ||
) |
Run a fit using an archipelago of genetic algorithms with real-valued chromosomes internally, with migration. Note that this function reseeds the random number generator using the system timer so that every run is different.
fit | The fit to run. |
nu_islands | The number of islands in the archipelago. |
population_size | The size of each GA population. |
selection_type | The fgen selection type. |
crossover_probability_float | The crossover probability. |
mutation_probability_float | The mutation probability per data element. |
macro_mutation_probability_float | The macro-mutation probability per data element. |
migration_probability_float | The migration probability per individual. |
migration_interval | The migration interval. Must be greater than 0. A value of 1 means migrations happens every generation, a value of 50 means migrations only happens every 50th generation. |
FGEN_API void ffit_run_fpso | ( | Ffit * | fit, |
int | population_size, | ||
int | topology, | ||
int | bounding_strategy, | ||
double | omega, | ||
double | phi1, | ||
double | phi2 | ||
) |
Run a fit using particle swarm optimization. Note that this function reseeds the random number generator using the system timer so that every run is different.
fit | The fit to run. |
population_size | The size of the swarm population. |
topology | The fpso topology type, one of FPSO_TOPOLOGY_LBEST and FPSO_TOPOLOGY_GBEST. |
bounding_strategy | The fpso bounding strategy. One of the following:
|
omega | The omega value used in the PSO. A default value is defined as FPSO_DEFAULT_OMEGA. |
phi1 | The phi1 value used in the PSO. A default value is defined as FPSO_DEFAULT_PHI1. |
phi2 | the phi2 value used in the PSO. A default value is defined as FPSO_DEFAULT_PHI2. |
FGEN_API void ffit_signal_stop | ( | Ffit * | fit | ) |
FGEN_API void ffit_signal_model_change | ( | Ffit * | fit | ) |
FGEN_API void ffit_destroy | ( | Ffit * | fit | ) |
FGEN_API int ffit_get_population_size | ( | const Ffit * | fit | ) |
FGEN_API void ffit_get_individual_params | ( | const Ffit * | fit, |
int | index, | ||
double * | params | ||
) |
Get the parameters of an individual from the optimization algorithm population. This can be used to enumerate the solutions present in the population.
fit | The fit. |
index | The index (starting at 0) of the individual in the population. The allowed range for this argument is defined by ffit_get_population_size(). |
params | The location where the fetched parameter array of the individual is stored. |
FGEN_API void* ffit_get_population | ( | const Ffit * | fit | ) |
Return a pointer to the optimization algorithm population used in a fit.
fit | The fit. |
FGEN_API void ffit_set_threading | ( | Ffit * | fit, |
int | level | ||
) |
FGEN_API void ffit_set_generation_callback_interval | ( | Ffit * | fit, |
int | interval | ||
) |
Set the interval at which the generation callback function is called. A value of 1 means it is called every generation, a value of 50 means it is called only every 50th generation. The default is 1. Higher values are beneficial for threaded execution when using a genetic algorithm archipelago.