-
Notifications
You must be signed in to change notification settings - Fork 0
/
DISCO.cpp
104 lines (85 loc) · 2.23 KB
/
DISCO.cpp
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
#include "allmyfile.h"
double FuncC(long c, double a)//1+a=b
{
double x = (pow( (1+a), (double)c)-1)/a;
return x;
}
//double ReFuncC(double n, double a)
//{
// double x = (log(n*a+1) ) / (log(a + 1) );
// return x;
//}
long DISCOUpdate(long c, long l, double a)
{
double v = (double)(rand()/(double)RAND_MAX);
double delta = log(a*l/(double)pow((1 + a), c)+1)/log(1+a);
double pd = delta - (long)delta;
if(v <= pd)
return (long)(delta+1);
else
return (long)(delta);
}
long DISCO_renor(double a1, double a2, long c1)// previous a1,c1;next a2,c2;
{
double v = (double)(rand()/(double)RAND_MAX);//generate a random number 0<x<1
long c2;
double c2_temp;
c2_temp = log(a2/a1*(pow(1+a1, (double)c1)-1)+1.0)/log(1+a2);
double pd = c2_temp - (long)c2_temp;
if(v <= pd)
{
c2 = (long)(c2_temp+1);
}
else
{
c2 = (long)c2_temp;
}
return c2;
}
/*************************OEF********************************/
long OEFUpdate(long c, long l, double a)
{
//a equals to 2e2 in the optimal estimation function
double v = (double)(rand()/(double)RAND_MAX);
double f_c = FC_OEF(c, a);//f(c)
double delta = INV_FC_OEF((double)l+f_c, a) - c;
delta = floor(delta);//delta
double f_c_d = FC_OEF(c + (long)delta, a);//f(c+d);
double f_c_d_1 = FC_OEF(c + (long)delta + 1, a);//f(c+d+1);
double temp_1 = (double)l + f_c - f_c_d;
double temp_2 = f_c_d_1 - f_c_d;
double pd = temp_1/temp_2;
if(v <= pd)
return (long)(delta+1);
else
return (long)(delta);
}
double FC_OEF(long c, double a)
{
double x = (pow( (1+a), (double)c)-1)/a*(2+a)/2;
return x;
}
double INV_FC_OEF(double n, double a)
{
double temp_1 = log(2*a*n + 2 + a)-log(2 + a);
double temp_2 = log(1 + a);
double x = temp_1/temp_2;
return x;
}
long OEF_renor(double a1, double a2, long c1)// previous a1,c1;next a2,c2;
{
double v = (double)(rand()/(double)RAND_MAX);//generate a random number 0<x<1
long c2;
double c2_temp;
c2_temp = log(a2*(2+a1)/a1/(2+a2)*(pow(1+a1, (double)c1)-1)+1.0)/log(1+a2);
double pd = c2_temp - (long)c2_temp;
if(v <= pd)
{
c2 = (long)(c2_temp+1);
}
else
{
c2 = (long)c2_temp;
}
return c2;
}