-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkov.sh
executable file
·163 lines (153 loc) · 2.88 KB
/
markov.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
cat expAlldata.txt | sed 's/.*\([0-9]\{2\}\),\([0-9]\{2\}\),\([0-9]\{2\}\),\([0-9]\{2\}\),\([0-9]\{2\}\),\([0-9]\{2\}\)|\([0-9]\{2\}\).*/\1,\2,\3,\4,\5,\6,\7/g'>tmpdata
cat tmpdata|
awk '
BEGIN{
FS=",";
getline;
getline;
getline;
for(j=1;j<34;j++)
{
proArray[j]=0;
}
}
{
for(i=1;i<7;i++)
{
for(j=1;j<34;j++)
{
if(strtonum($i)==j)
{
proArray[j]++;
}
}
}
}
END{
sum=0
for(j=1;j<34;j++)
{
printf("%d ", proArray[j]);
#sum+=proArray[j];
}
#printf("total: %d\n", NR-3);
#printf("sum: %d\n", sum);
}
'>./curPro.data
tac tmpdata|
awk 'BEGIN{
FS=",";
getline;
for(i=1;i<34;i++)
{
for(j=1;j<34;j++)
{
markovTrans[i][j]=0;
}
}
getline;
for(j=1;j<7;j++)
{
getdataArrayOne[j]=$j;
#printf("%d ", $j);
#printf("%d ", getdataArrayOne[j]);
}
}
{
for(j=1;j<7;j++)
{
getdataArrayTwo[j]=$j;
#printf("%d ", $j);
#printf("%d ", getdataArrayTwo[j]);
}
#printf("\n");
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
markovTrans[strtonum(getdataArrayOne[i])][strtonum(getdataArrayTwo[j])]++;
}
}
for(j=1;j<7;j++)
{
getdataArrayOne[j]=$j;
}
}
END{
#for(j=0;j<34;j++)
#{
#printf("%2d ",j);
#}
for(i=1;i<34;i++)
{
#printf("\n%2d ", i);
for(j=1;j<34;j++)
{
printf("%2d ",markovTrans[i][j]);
}
printf("\n");
}
#printf("total: %d\n", NR);
}'>transPro.data
#get recent balls
cat tmpdata | sed '1,3'd>3
oldIFS=$IFS
IFS=","
printf "balls \n"
read balls[{0..6}]<3
for i in {0..5}
do
echo ${balls[i]}
done
#select current balls' probability
IFS=" "
read orgProArray[{1..33}]<curPro.data
for i in {0..5}
do
echo ${orgProArray[balls[i]]}
done
#Copy transfer probability
IFS=" "
sampleSpan=33
for i in {0..32}
do
read marKovTransPro[$[i*sampleSpan+{1..33}]]
done<transPro.data
#Test marKovTransPro
for i in {0..32}
do
for j in {1..33}
do
printf "%2d " "${marKovTransPro[$[i*sampleSpan+j]]}"
done
printf "\n"
done
#Copy selected marKovTransPro
printf "selected\n"
for i in {0..5}
do
for j in {1..33}
do
selectMKTP[$[i*sampleSpan+j]]=${marKovTransPro[$[$[balls[i]-1]*sampleSpan+j]]}
printf "%d " "${selectMKTP[$[i*sampleSpan+j]]}"
done
printf "\n"
done
#Calculate the probability with markovChain
for i in {1..33}
do
sum=0
for j in {0..5}
do
sum=$[$sum+${orgProArray[balls[j]]}*${selectMKTP[j*sampleSpan+i]}]
#echo ${orgProArray[balls[j]]}
done
choiseProArray[i]=$sum
done
printf "final choice\n"
for i in {1..33}
do
printf "%d:%d\n" ${choiseProArray[i]} $i
done>4
sort -t":" -nrk 1 <4 >decision2.txt