C
x
94
1
2
3
4
5
int K, cols;
6
long double * binomialProbability;//pow(2,K)
7
long double p;
8
int * temp, * zeta;//K * pow(2,K)
9
10
void allocatePatternsWProbability(void);
11
void generateAllBinaryStrings(int col, int row);
12
void putInZeta(int i);
13
14
FILE* myFile;
15
void allocatePatternWProbability(void) {
16
myFile = stderr;
17
K = 3;
18
cols = 3;
19
allocatePatternsWProbability();
20
}
21
22
int main( int argc , char * argv[] ){
23
//other stuff
24
allocatePatternWProbability();
25
//other stuff
26
return 0;
27
}
28
29
30
void allocatePatternsWProbability(void){
31
int i, j, sum, offset, n;
32
33
temp = (int *)malloc(K * sizeof(int));
34
if(temp == NULL){
35
printf("temp malloc failed ABORT\n");
36
fprintf(myFile, "temp malloc failed ABORT\n");
37
exit(-9);
38
}
39
zeta = (int *)malloc(K * cols * sizeof(int));
40
if(zeta == NULL){
41
printf("zeta malloc failed ABORT\n");
42
fprintf(myFile, "zeta malloc failed ABORT\n");
43
exit(-9);
44
}
45
46
binomialProbability = (long double *)malloc(cols * sizeof(long double));
47
if(binomialProbability == NULL){
48
printf("binomialProbability malloc failed ABORT\n");
49
fprintf(myFile, "binomialProbability malloc failed ABORT\n");
50
exit(-9);
51
}
52
53
generateAllBinaryStrings(0, 0);
54
for(i=0; i<cols; i++){
55
sum = 0;
56
for(j=0; j<K; j++){
57
offset = i + cols * j;
58
printf("zeta %d = %d\n", offset, zeta[offset]);
59
sum += zeta[offset];
60
}
61
n = (K + sum) * 0.5;
62
binomialProbability[i] = pow(p,n) * pow((1 - p), (K - n));
63
printf("n %d binomialProbability %Lg\n", n, binomialProbability[i]);
64
}
65
}
66
67
/***************************************************************************************************/
68
69
void generateAllBinaryStrings(int i, int j){
70
if(j == K){
71
putInZeta(i);
72
i++;
73
return;
74
}
75
temp[j] = -1;
76
generateAllBinaryStrings(i, j + 1);
77
78
temp[j] = 1;
79
generateAllBinaryStrings(i, j + 1);
80
}
$ gcc prog.c -Wall -Wextra -O2 -march=native -std=c99 -pedantic "-lm"
Start
prog.c: In function 'main': prog.c:22:15: warning: unused parameter 'argc' [-Wunused-parameter] 22 | int main( int argc , char * argv[] ){ | ~~~~^~~~ prog.c:22:29: warning: unused parameter 'argv' [-Wunused-parameter] 22 | int main( int argc , char * argv[] ){ | ~~~~~~~^~~~~~
temp 0 = -1 and zeta 0 = -1 temp 1 = -1 and zeta 3 = -1 temp 2 = -1 and zeta 6 = -1 temp 0 = -1 and zeta 0 = -1 temp 1 = -1 and zeta 3 = -1 temp 2 = 1 and zeta 6 = 1 temp 0 = -1 and zeta 0 = -1 temp 1 = 1 and zeta 3 = 1 temp 2 = -1 and zeta 6 = -1 temp 0 = -1 and zeta 0 = -1 temp 1 = 1 and zeta 3 = 1 temp 2 = 1 and zeta 6 = 1 temp 0 = 1 and zeta 0 = 1 temp 1 = -1 and zeta 3 = -1 temp 2 = -1 and zeta 6 = -1 temp 0 = 1 and zeta 0 = 1 temp 1 = -1 and zeta 3 = -1 temp 2 = 1 and zeta 6 = 1 temp 0 = 1 and zeta 0 = 1 temp 1 = 1 and zeta 3 = 1 temp 2 = -1 and zeta 6 = -1 temp 0 = 1 and zeta 0 = 1 temp 1 = 1 and zeta 3 = 1 temp 2 = 1 and zeta 6 = 1 zeta 0 = 1 zeta 3 = 1 zeta 6 = 1 n 3 binomialProbability 0 zeta 1 = 0 zeta 4 = 0 zeta 7 = 0 n 1 binomialProbability 0 zeta 2 = 0 zeta 5 = 0 zeta 8 = 0 n 1 binomialProbability 0
0
Finish