Wednesday, June 03, 2015

Genetics Algorithm Method with Progressive Error Prediction

Genetics Algorithm is one of approximation method that used base prediction technique. It's suggest the algorithm that can be used as portable finding method to approach unknown value whatever mathematics problem that given base on fitness value that can be reach. Neural Network have also capability as same as genetic algorithm. but it's have different approximation method where weight value is a sign that the best prediction can be reach. 

Progressive error prediction is a method to implement Genetic Algorithm for fast finding algorithm. The idea is came from the numerical calculation with ordinary numerical approximation oftentimes given the infinite results value, if the case solver that implemented to the calculation not suitable as expectation, calculation will be stuck and can't be continued. With implement progressive error prediction, the random prediction can be directed to the right point and avoiding stuck point, so the calculation still will be continued although given random input value.

Genetic Algorithm with Progressive error prediction, have capability to calculate many of math problem numerically. And it's depend on how the condition that would be set to the calculation and make the error results would be flow progressively. It's was proofed by Predicted Calc, that's an Android app where implements this method to find the best approximate value of all unknown variables of equation and whatever equation will be type.

Predicted Calc - screenshot thumbnail

Here our pseudo code to implement Progressive Error Prediction for Genetics Algorithm, that used on Predicted Calc:

 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
89
90
range = 10;
for (generation = 0; generation < MaxGen; generation++) {
        /******set population******/
    for (i = 0; i < NumPopulation; i++) {
        if (generation == 0) {
            for (j = 0; j < Population[i].length; j++) {
                if (constan[j]) {
                    Population[i][j] = a[j];
                } else {
                    Population[i][j] = a[j] - 0.5 * range + range * randomDouble();
                }
            }
        } else {
            index =  (1.0 * i * (NumBestPopulation+1) / Population[i].length);
            if(index>=NumBestPopulation)index=NumBestPopulation-1;
            for (j = 0; j < Population[i].length; j++) {
                if (constan[j]) {
                    Population[i][j] = a[j];
                } else {
                    if(i==0){
                        Population[i][j] = BestPopulation[index][j];
                    }else{
                        Population[i][j] = BestPopulation[index][j];
                        if(i<NumBestPopulation-1){
                            Population[i][j] -= 0.5 * range + range * randomDouble();
                        }
                    }
                }
            }
        }
        /******set fitnes power per population******/
        fitnes[i] = 0.0;
        for (io = 0; io < x.length; io++) {
            fitnes[i] +=eFunc(Population[i], x[io], y[io]);                 
        }
        fitnes[i] = sqrt(fitnes[i] / x.length);
        /******end of set fitnes power******/
    }
    /******end of set population******/

    /*****sorted fitnes by min to max error (progressive error)******/
    for (i = 0; i < NumPopulation; i++) {
        for (j = i; j < NumPopulation; j++) {
            if (fitnes[i] > fitnes[j]) {
                tmp = fitnes[i];
                fitnes[i] = fitnes[j];
                fitnes[j] = tmp;
                for (io = 0; io < a.length; io++) {
                    tmp = Population[i][io];
                    Population[i][io] = Population[j][io];
                    Population[j][io] = tmp;
                }
            }
        }
    }
    /*****end fo sorted fitnes******/

    /*****set population with small error as best population****/
    for (i = 0; i < NumBestPopulation; i++) {
        for (io = 0; io < Population[i].length; io++) {
            if(i<NumBestPopulation-1){
                BestPopulation[i][io] = Population[i][io];
            }else{
                BestPopulation[i][io] = tryround(Population[0][io],3,10);
            }
        }
    }
    /*****end of set population****/

    /****checking global error what have value as same as error target******/
    if (generation == 0) {
        error = fitnes[0];
        for (io = 0; io < a.length; io++) {
            a[io] = Population[0][io];
        }
    } else {
        if (error > fitnes[0]) {
            if (fitnes[0] < 0.5 * error) {
            range *= 0.75;
        }
        for (io = 0; io < a.length; io++) {
            a[io] = Population[0][io];
        }
        error = fitnes[0];
    }
    if (error <= eTarget || Stopped) {
        done;
    }
    /****end of checking global error******/
}
logo

Popular Posts