00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __EVOLUTIONARYALGORITHM_H__
00018 #define __EVOLUTIONARYALGORITHM_H__
00019
00020
00021 #include "TrainingAlgorithm.h"
00022 #include "../ObjectiveFunctional/ObjectiveFunctional.h"
00023
00024 namespace Flood
00025 {
00026
00029
00030 class EvolutionaryAlgorithm : public TrainingAlgorithm
00031 {
00032
00033 public:
00034
00035
00036
00038
00039 enum FitnessAssignmentMethod{LinearRanking};
00040
00042
00043 enum SelectionMethod{RouletteWheel, StochasticUniversalSampling};
00044
00046
00047 enum RecombinationMethod{Line, Intermediate};
00048
00050
00051 enum MutationMethod{Normal, Uniform};
00052
00053
00054 explicit EvolutionaryAlgorithm(ObjectiveFunctional*);
00055
00056
00057
00058
00059 explicit EvolutionaryAlgorithm(void);
00060
00061
00062
00063
00064 virtual ~EvolutionaryAlgorithm(void);
00065
00066
00067
00068
00069
00070
00071
00072
00073 int get_population_size(void);
00074
00075 Matrix<double>& get_population(void);
00076
00077
00078
00079 FitnessAssignmentMethod& get_fitness_assignment_method(void);
00080 std::string get_fitness_assignment_method_name(void);
00081
00082 SelectionMethod& get_selection_method(void);
00083 std::string get_selection_method_name(void);
00084
00085 RecombinationMethod& get_recombination_method(void);
00086 std::string get_recombination_method_name(void);
00087
00088 MutationMethod& get_mutation_method(void);
00089 std::string get_mutation_method_name(void);
00090
00091
00092
00093 Vector<double>& get_evaluation(void);
00094 Vector<double>& get_fitness(void);
00095 Vector<bool>& get_selection(void);
00096
00097 bool get_elitism(void);
00098 double get_selective_pressure(void);
00099
00100 double get_recombination_size(void);
00101 double get_mutation_rate(void);
00102 double get_mutation_range(void); double get_maximum_generations_number(void);
00103 double get_mean_evaluation_goal(void);
00104 double get_standard_deviation_evaluation_goal(void);
00105
00106 bool get_reserve_population_history(void);
00107 bool get_reserve_best_individual_history(void);
00108 bool get_reserve_mean_norm_history(void);
00109 bool get_reserve_standard_deviation_norm_history(void);
00110 bool get_reserve_best_norm_history(void);
00111
00112 bool get_reserve_mean_evaluation_history(void);
00113 bool get_reserve_standard_deviation_evaluation_history(void);
00114 bool get_reserve_best_evaluation_history(void);
00115
00116 Vector< Matrix<double> >& get_population_history(void);
00117
00118 Vector< Vector<double> >& get_best_individual_history(void);
00119
00120 Vector<double>& get_mean_norm_history(void);
00121 Vector<double>& get_standard_deviation_norm_history(void);
00122 Vector<double>& get_best_norm_history(void);
00123
00124 Vector<double>& get_mean_evaluation_history(void);
00125 Vector<double>& get_standard_deviation_evaluation_history(void);
00126 Vector<double>& get_best_evaluation_history(void);
00127
00128
00129
00130 void set(void);
00131 void set(ObjectiveFunctional*);
00132
00133 void set_default(void);
00134
00135 void set_fitness_assignment_method(const FitnessAssignmentMethod&);
00136 void set_fitness_assignment_method(const std::string&);
00137
00138 void set_selection_method(const SelectionMethod&);
00139 void set_selection_method(const std::string&);
00140
00141 void set_recombination_method(const RecombinationMethod&);
00142 void set_recombination_method(const std::string&);
00143
00144 void set_mutation_method(const MutationMethod&);
00145 void set_mutation_method(const std::string&);
00146
00147 void set_population_size(int);
00148
00149 void set_population(const Matrix<double>&);
00150
00151 void set_evaluation(const Vector<double>&);
00152 void set_fitness(const Vector<double>&);
00153 void set_selection(const Vector<bool>&);
00154
00155 void set_elitism(bool);
00156 void set_selective_pressure(double);
00157 void set_recombination_size(double);
00158
00159 void set_mutation_rate(double);
00160 void set_mutation_range(double);
00161
00162 void set_maximum_generations_number(int);
00163 void set_mean_evaluation_goal(double);
00164 void set_standard_deviation_evaluation_goal(double);
00165
00166 void set_reserve_population_history(bool);
00167
00168 void set_reserve_best_individual_history(bool);
00169
00170 void set_reserve_mean_norm_history(bool);
00171 void set_reserve_standard_deviation_norm_history(bool);
00172 void set_reserve_best_norm_history(bool);
00173
00174 void set_reserve_mean_evaluation_history(bool);
00175 void set_reserve_standard_deviation_evaluation_history(bool);
00176 void set_reserve_best_evaluation_history(bool);
00177
00178 void set_reserve_all_training_history(bool);
00179
00180 void set_population_history(const Vector< Matrix<double> >&);
00181
00182 void set_best_individual_history(const Vector< Vector<double> >&);
00183
00184 void set_mean_norm_history(const Vector<double>&);
00185 void set_standard_deviation_norm_history(const Vector<double>&);
00186 void set_best_norm_history(const Vector<double>&);
00187
00188 void set_mean_evaluation_history(const Vector<double>&);
00189 void set_standard_deviation_evaluation_history(const Vector<double>&);
00190 void set_best_evaluation_history(const Vector<double>&);
00191
00192
00193
00194 Vector<double> get_individual(int);
00195 void set_individual(int, const Vector<double>&);
00196
00197 Vector<double> get_best_individual(void);
00198
00199 double calculate_mean_evaluation(void);
00200 double calculate_standard_deviation_evaluation(void);
00201
00202
00203
00204 void initialize_population(double);
00205
00206 void initialize_population_uniform(void);
00207 void initialize_population_uniform(double, double);
00208 void initialize_population_uniform(const Vector<double>&, const Vector<double>&);
00209 void initialize_population_uniform(const Matrix<double>&);
00210
00211 void initialize_population_normal(void);
00212 void initialize_population_normal(double, double);
00213 void initialize_population_normal(const Vector<double>&, const Vector<double>&);
00214 void initialize_population_normal(const Matrix<double>&);
00215
00216
00217
00218 Vector<double> calculate_population_norm(void);
00219
00220
00221
00222 void perform_fitness_assignment(void);
00223 void perform_selection(void);
00224 void perform_recombination(void);
00225 void perform_mutation(void);
00226
00227 void evolve_population(void);
00228
00229 void evaluate_population(void);
00230
00231
00232
00233 void perform_linear_ranking_fitness_assignment(void);
00234
00235
00236
00237 void perform_roulette_wheel_selection(void);
00238 void perform_stochastic_universal_sampling_selection(void);
00239
00240
00241
00242 void perform_intermediate_recombination(void);
00243 void perform_line_recombination(void);
00244
00245
00246
00247 void perform_normal_mutation(void);
00248 void perform_uniform_mutation(void);
00249
00250
00251
00252 void train(void);
00253
00254
00255
00256 void resize_training_history(int);
00257
00258 std::string get_training_history_XML(bool);
00259
00260
00261
00262 std::string to_XML(bool);
00263 void load(const char*);
00264
00265
00266 private:
00267
00268
00269
00271
00272 FitnessAssignmentMethod fitness_assignment_method;
00273
00275
00276 SelectionMethod selection_method;
00277
00279
00280 RecombinationMethod recombination_method;
00281
00283
00284 MutationMethod mutation_method;
00285
00286
00287
00289
00290 Matrix<double> population;
00291
00293
00294 Vector<double> evaluation;
00295
00297
00298 Vector<double> fitness;
00299
00301
00302 Vector<bool> selection;
00303
00304
00305
00306 bool elitism;
00307
00310
00311 double selective_pressure;
00312
00315
00316 double recombination_size;
00317
00320
00321 double mutation_rate;
00322
00325
00326 double mutation_range;
00327
00328 double mean_evaluation_goal;
00329
00330 double standard_deviation_evaluation_goal;
00331
00333
00334 int maximum_generations_number;
00335
00339
00340 bool reserve_population_history;
00341
00344
00345 bool reserve_best_individual_history;
00346
00348
00349 bool reserve_mean_norm_history;
00350
00352
00353 bool reserve_standard_deviation_norm_history;
00354
00356
00357 bool reserve_best_norm_history;
00358
00360
00361 bool reserve_mean_evaluation_history;
00362
00364
00365 bool reserve_standard_deviation_evaluation_history;
00366
00368
00369 bool reserve_best_evaluation_history;
00370
00373
00374 Vector< Matrix<double> > population_history;
00375
00378
00379 Vector< Vector<double> > best_individual_history;
00380
00383
00384 Vector<double> mean_norm_history;
00385
00389
00390 Vector<double> standard_deviation_norm_history;
00391
00393
00394 Vector<double> best_norm_history;
00395
00397
00398 Vector<double> mean_evaluation_history;
00399
00401
00402 Vector<double> standard_deviation_evaluation_history;
00403
00405
00406 Vector<double> best_evaluation_history;
00407
00408
00409
00410
00411
00412 double calculate_random_uniform(double, double);
00413 double calculate_random_normal(double, double);
00414 };
00415
00416 }
00417
00418 #endif
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436