File: GAfit.h

package info (click to toggle)
fityk 0.4.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,472 kB
  • ctags: 2,617
  • sloc: cpp: 19,705; sh: 5,965; xml: 2,325; yacc: 356; makefile: 183; lex: 178
file content (88 lines) | stat: -rw-r--r-- 2,991 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// This file is part of fityk program. Copyright (C) Marcin Wojdyr
// $Id: GAfit.h,v 1.1.1.1 2003/06/17 20:07:53 wojdyr Exp $

#ifndef GAfit__h__
#define GAfit__h__
#include <vector>
#include "common.h"
#include "v_fit.h"

/*     this class contains genetic algorithm for fitting
 */

struct Individual 
{ 
    std::vector<fp> g; 
    fp raw_score, phase_2_score, reversed_score, norm_score; 
    int generation;
    Individual (int n) : g(n), raw_score(0) {}
    Individual () : g(), raw_score(0) {}
};

class GAfit : public v_fit
{
public:
    GAfit ();
    ~GAfit ();
    fp init(); // called before autoiter()
    int autoiter ();
private:
    int popsize;
    int elitism; // = 0, 1, ... popsize
    char mutation_type;
    fp p_mutation;
    bool mutate_all_genes;
    fp mutation_strength;
    char crossover_type;
    fp p_crossover;
    char selection_type;
    bool rank_scoring;
    int tournament_size;
    int window_size;
    fp linear_scaling_a, linear_scaling_c, linear_scaling_b;
    fp std_dev_stop;
    int iter_with_no_progresss_stop;
    fp wssr_stop;
    int autoplot_indiv_nr;
    std::vector<Individual> pop1, pop2, *pop, *opop;
    int iteration;
    Individual best_indiv;
    std::string log_file;
    fp tmp_max;
    std::map<char, std::string> Crossover_enum;
    std::map<char, std::string> Selection_enum;

    void mutation();
    void crossover();
    void uniform_crossover (std::vector<Individual>::iterator c1, 
                            std::vector<Individual>::iterator c2);
    void one_point_crossover (std::vector<Individual>::iterator c1, 
                              std::vector<Individual>::iterator c2);
    void two_points_crossover (std::vector<Individual>::iterator c1, 
                               std::vector<Individual>::iterator c2);
    void arithmetic_crossover1 (std::vector<Individual>::iterator c1, 
                                std::vector<Individual>::iterator c2);
    void arithmetic_crossover2 (std::vector<Individual>::iterator c1, 
                                std::vector<Individual>::iterator c2);
    void guaranteed_avarage_crossover (std::vector<Individual>::iterator c1, 
                                       std::vector<Individual>::iterator c2);
    void scale_score ();
    void pre_selection();
    void post_selection();
    fp max_in_window ();
    fp std_dev_based_q();
    void do_rank_scoring(std::vector<Individual> *popp);
    void roulette_wheel_selection (std::vector<int>& next);
    void tournament_selection (std::vector<int>& next);
    void stochastic_remainder_sampling(std::vector<int>& next);
    void deterministic_sampling_selection(std::vector<int>& next);
    std::vector<int>::iterator SRS_and_DS_common (std::vector<int>& next);
    bool termination_criteria_and_print_info (int iter);
    void print_post_fit_info (fp wssr_before);
    void autoplot_in_autoiter();
    void compute_wssr_for_ind (std::vector<Individual>::iterator ind);
    void log_ga_options(); 
}; 

#endif