-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
essStats.c
82 lines (61 loc) · 1.98 KB
/
essStats.c
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
#include "ess.h"
void updateFrequencyMatrix(eSSType *eSSParams){
for (int k = 0; k < eSSParams->refSet->size; ++k)
{
for (int i = 0; i < eSSParams->n_params; ++i)
{
for (int j = 0; j < eSSParams->n_sub_regions; ++j)
{
if (eSSParams->refSet->members[k].params[i] > eSSParams->min_boundary_matrix[i][j] && eSSParams->refSet->members[k].params[i] < eSSParams->max_boundary_matrix[i][j])
{
eSSParams->stats->freqs_matrix[i][j]++;
break;
}
}
}
}
}
/**
* Compute the statistics of the set like the mean and standard deviation of Individuals cost.
* @param eSSParams
* @param set
*/
void compute_SetStats(eSSType *eSSParams, Set *set ){
// souble n = 0
double Sum = 0;
double Sum_sqr = 0;
for (int i = 0; i < set->size; ++i)
{
// n = n + 1
Sum = Sum + set->members[i].cost ;
Sum_sqr = Sum_sqr + set->members[i].cost*set->members[i].cost ;
}
double variance = (Sum_sqr - (Sum*Sum)/set->size)/(set->size - 1);
set->mean_cost = Sum / set->size;
set->std_cost = sqrt(variance);
}
void compute_Mean(eSSType *eSSParams, Individual *ind){
}
void compute_Std(eSSType *eSSParams, Individual *ind){
}
void update_IndsStats(eSSType *eSSParams, Set *set){
for (int i = 0; i < set->size; ++i){
update_IndStats(eSSParams, &(set->members[i]));
}
}
/**
* Update or reset the statistics of an Individual consisting its mean and variance.
* @param eSSParams
* @param ind
*/
void update_IndStats(eSSType *eSSParams, Individual *ind){
if (ind->n_not_randomized == 0){
ind->mean_cost = 0;
ind->var_cost = 0;
}else{
double prev_mean = ind->mean_cost;
ind->n_not_randomized++;
ind->mean_cost = ind->mean_cost + (ind->cost - ind->mean_cost) / ind->n_not_randomized;
ind->var_cost = ind->var_cost + (ind->cost - ind->mean_cost)*(ind->cost - prev_mean);
}
}