-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPairCopulaRand.cpp
159 lines (124 loc) · 3.84 KB
/
PairCopulaRand.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
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
#include "VineCopulaCPP_header.hpp"
void PairCopulaRand(int family, int rotation, const double *theta, double *U, double *V, unsigned int n)
{
// If the function is called without any seed, a random seed (using the current system time) is generated
unsigned int i;
boost::mt19937 gen;
gen.seed(time(0));
std::stringstream RNG_State;
RNG_State << gen;
std::vector<unsigned int> SeedState(624);
double state;
for (i=0;i<624;i++)
{
RNG_State >> state;
SeedState[i] = (unsigned int) state;
}
PairCopulaRand(SeedState, family, rotation, theta, U, V, n);
return;
}
void PairCopulaRand(int family, const double *theta, double *U, double *V, unsigned int n)
{
// If the function is called without any seed, a random seed (using the current system time) is generated
unsigned int i;
boost::mt19937 gen;
gen.seed(time(0));
std::stringstream RNG_State;
RNG_State << gen;
std::vector<unsigned int> SeedState(624);
double state;
for (i=0;i<624;i++)
{
RNG_State >> state;
SeedState[i] = (unsigned int) state;
}
PairCopulaRand(SeedState, family, theta, U, V, n);
return;
}
void PairCopulaRand(std::vector<unsigned int>& SeedState, int family, int rotation, const double *theta, double *U, double *V, unsigned int n)
{
unsigned int i;
boost::mt19937 gen;
// Load the state
std::stringstream RNG_State_In;
std::copy(SeedState.begin(), SeedState.end(), std::ostream_iterator<unsigned int>(RNG_State_In, " "));
RNG_State_In>>gen;
boost::uniform_01 <> URAND;
boost::variate_generator <boost::mt19937&, boost::uniform_01 <> > RAND(gen,URAND);
for (i=0;i<n;i++)
{
U[i] = RAND();
V[i] = RAND();
}
// Save the state
double state;
std::stringstream RNG_State_Out;
RNG_State_Out << gen;
for (i=0;i<624;i++)
{
RNG_State_Out >> state;
SeedState[i] = (unsigned int) state;
}
switch(family){
case 0:
{
// Indep
break;
}
default:
{
// AMH, AsymFGM, BB6, BB7, Gaussian, Gumbel, IteratedFGM, Joe, Plackett, Tawn1, Tawn2, Tawn, t
if(rotation>0)
{
std::vector<double> U1(n),V1(n);
Rotate_Obs(U,V,&U1[0],&V1[0],rotation,n);
PairCopulaInvHfun_Rotated_Obs(family, rotation, theta, &U1[0], &V1[0], U, n);
}
else
{
PairCopulaInvHfun(family, rotation, theta, U, V, U, n);
}
break;
}
}
return;
}
void PairCopulaRand(std::vector<unsigned int>& SeedState, int family, const double *theta, double *U, double *V, unsigned int n)
{
unsigned int i;
boost::mt19937 gen;
// Load the state
std::stringstream RNG_State_In;
std::copy(SeedState.begin(), SeedState.end(), std::ostream_iterator<unsigned int>(RNG_State_In, " "));
RNG_State_In>>gen;
boost::uniform_01 <> URAND;
boost::variate_generator <boost::mt19937&, boost::uniform_01 <> > RAND(gen,URAND);
for (i=0;i<n;i++)
{
U[i] = RAND();
V[i] = RAND();
}
// Save the state
double state;
std::stringstream RNG_State_Out;
RNG_State_Out << gen;
for (i=0;i<624;i++)
{
RNG_State_Out >> state;
SeedState[i] = (unsigned int) state;
}
switch(family){
case 0:
{
// Indep
break;
}
default:
{
// AMH, AsymFGM, BB6, BB7, Gaussian, Gumbel, IteratedFGM, Joe, Plackett, Tawn1, Tawn2, Tawn, t
PairCopulaInvHfun(family, theta, U, V, U, n);
break;
}
}
return;
}