| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Math::Random::Brownian; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
40816
|
use 5.008005; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
43
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
235
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
|
9
|
1
|
|
|
1
|
|
1039
|
use AutoLoader; |
|
|
1
|
|
|
|
|
1757
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use Math::Random::Brownian ':all'; |
|
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
19
|
|
|
|
|
|
|
# will save memory. |
|
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
) ] ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
31
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
32
|
|
|
|
|
|
|
# This AUTOLOAD is used to 'autoload' constants from the constant() |
|
33
|
|
|
|
|
|
|
# XS function. |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
0
|
|
|
my $constname; |
|
36
|
0
|
|
|
|
|
|
our $AUTOLOAD; |
|
37
|
0
|
|
|
|
|
|
($constname = $AUTOLOAD) =~ s/.*:://; |
|
38
|
0
|
0
|
|
|
|
|
croak "&Math::Random::Brownian::constant not defined" if $constname eq 'constant'; |
|
39
|
0
|
|
|
|
|
|
my ($error, $val) = constant($constname); |
|
40
|
0
|
0
|
|
|
|
|
if ($error) { croak $error; } |
|
|
0
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
|
42
|
1
|
|
|
1
|
|
251
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
84
|
|
|
|
0
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Fixed between 5.005_53 and 5.005_61 |
|
44
|
|
|
|
|
|
|
#XXX if ($] >= 5.00561) { |
|
45
|
|
|
|
|
|
|
#XXX *$AUTOLOAD = sub () { $val }; |
|
46
|
|
|
|
|
|
|
#XXX } |
|
47
|
|
|
|
|
|
|
#XXX else { |
|
48
|
0
|
|
|
0
|
|
|
*$AUTOLOAD = sub { $val }; |
|
|
0
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#XXX } |
|
50
|
|
|
|
|
|
|
} |
|
51
|
0
|
|
|
|
|
|
goto &$AUTOLOAD; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
require XSLoader; |
|
55
|
|
|
|
|
|
|
XSLoader::load('Math::Random::Brownian', $VERSION); |
|
56
|
1
|
|
|
1
|
|
1035
|
use Params::Validate qw( validate SCALAR ); |
|
|
1
|
|
|
|
|
12976
|
|
|
|
1
|
|
|
|
|
1424
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $Validate = |
|
59
|
|
|
|
|
|
|
{ |
|
60
|
|
|
|
|
|
|
LENGTH => {type => SCALAR, |
|
61
|
|
|
|
|
|
|
callbacks => |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
|
|
|
|
|
|
'is positive' => |
|
64
|
|
|
|
|
|
|
sub{ $_[0] > 0}, |
|
65
|
|
|
|
|
|
|
'is an integer' => |
|
66
|
|
|
|
|
|
|
sub{ $_[0] == int $_[0]}, |
|
67
|
|
|
|
|
|
|
}, |
|
68
|
|
|
|
|
|
|
}, |
|
69
|
|
|
|
|
|
|
HURST => {type => SCALAR, |
|
70
|
|
|
|
|
|
|
callbacks => |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
|
|
|
|
|
|
'is between 0 and 1' => |
|
73
|
|
|
|
|
|
|
sub{ $_[0] > 0 && $_[0] < 1}, |
|
74
|
|
|
|
|
|
|
}, |
|
75
|
|
|
|
|
|
|
}, |
|
76
|
|
|
|
|
|
|
VARIANCE => {type => SCALAR, |
|
77
|
|
|
|
|
|
|
callbacks => |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
'is positive' => |
|
80
|
|
|
|
|
|
|
sub{ $_[0] > 0 }, |
|
81
|
|
|
|
|
|
|
}, |
|
82
|
|
|
|
|
|
|
}, |
|
83
|
|
|
|
|
|
|
NOISE => {type => SCALAR, |
|
84
|
|
|
|
|
|
|
callbacks => |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
|
|
|
|
|
|
'must be Gaussian or Brownian' => |
|
87
|
|
|
|
|
|
|
sub{ $_[0] =~ 'Gaussian' || $_[0] =~ 'Brownian' }, |
|
88
|
|
|
|
|
|
|
}, |
|
89
|
|
|
|
|
|
|
}, |
|
90
|
|
|
|
|
|
|
}; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $Wavelet_Validate = |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
|
|
|
|
|
|
%$Validate, |
|
95
|
|
|
|
|
|
|
APPROX_PARAM => {type => SCALAR, |
|
96
|
|
|
|
|
|
|
callbacks => |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
|
|
|
|
|
|
'is an integer' => |
|
99
|
|
|
|
|
|
|
sub{ $_[0] == int $_[0] }, |
|
100
|
|
|
|
|
|
|
}, |
|
101
|
|
|
|
|
|
|
}, |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
106
|
|
|
|
|
|
|
sub new |
|
107
|
|
|
|
|
|
|
{ |
|
108
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $self = {}; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->{SEED1} = time ^ ($$ + ($$ << 15)); |
|
113
|
0
|
|
|
|
|
|
$self->{SEED2} = time ^ $$ ^ unpack "%L*", `ps axww | gzip`; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
bless $self, $class; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return $self; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub Hosking |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
123
|
0
|
|
|
|
|
|
my %p = (); |
|
124
|
0
|
|
|
|
|
|
%p = validate(@_,$Validate); |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $n = int (log($p{LENGTH})/log(2.0)) + 1; |
|
127
|
0
|
|
|
|
|
|
my $H = $p{HURST}; |
|
128
|
0
|
|
|
|
|
|
my $L = $p{VARIANCE}; |
|
129
|
0
|
|
|
|
|
|
my $cum; |
|
130
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Gaussian' ) { $cum = 0; } |
|
|
0
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Brownian' ) { $cum = 1; } |
|
|
0
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $seed1 = $self->{SEED1}; |
|
133
|
0
|
|
|
|
|
|
my $seed2 = $self->{SEED2}; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $output = __hosking($n,$H,$L,$cum,$seed1,$seed2); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Save new seeds |
|
138
|
0
|
|
|
|
|
|
$self->{SEED1} = $$output[-2]; |
|
139
|
0
|
|
|
|
|
|
$self->{SEED2} = $$output[-1]; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Truncate the array |
|
142
|
0
|
|
|
|
|
|
my @new_output = (); |
|
143
|
0
|
|
|
|
|
|
for(my $i=0;$i<$p{LENGTH};$i++) |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
0
|
|
|
|
|
|
$new_output[$i] = $$output[$i]; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return @new_output; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub Circulant |
|
152
|
|
|
|
|
|
|
{ |
|
153
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
154
|
0
|
|
|
|
|
|
my %p = (); |
|
155
|
0
|
|
|
|
|
|
%p = validate(@_,$Validate); |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
my $n = int (log($p{LENGTH})/log(2.0)) + 1; |
|
158
|
0
|
|
|
|
|
|
my $H = $p{HURST}; |
|
159
|
0
|
|
|
|
|
|
my $L = $p{VARIANCE}; |
|
160
|
0
|
|
|
|
|
|
my $cum; |
|
161
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Gaussian' ) { $cum = 0; } |
|
|
0
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Brownian' ) { $cum = 1; } |
|
|
0
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $seed1 = $self->{SEED1}; |
|
164
|
0
|
|
|
|
|
|
my $seed2 = $self->{SEED2}; |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $output = __circulant($n,$H,$L,$cum,$seed1,$seed2); |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Save new seeds |
|
169
|
0
|
|
|
|
|
|
$self->{SEED1} = $$output[-2]; |
|
170
|
0
|
|
|
|
|
|
$self->{SEED2} = $$output[-1]; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# Truncate the array |
|
173
|
0
|
|
|
|
|
|
my @new_output = (); |
|
174
|
0
|
|
|
|
|
|
for(my $i=0;$i<$p{LENGTH};$i++) |
|
175
|
|
|
|
|
|
|
{ |
|
176
|
0
|
|
|
|
|
|
$new_output[$i] = $$output[$i]; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
return @new_output; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub ApprCirc |
|
183
|
|
|
|
|
|
|
{ |
|
184
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
185
|
0
|
|
|
|
|
|
my %p = (); |
|
186
|
0
|
|
|
|
|
|
%p = validate(@_,$Validate); |
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my $n = int (log($p{LENGTH})/log(2.0)) + 1; |
|
189
|
0
|
|
|
|
|
|
my $H = $p{HURST}; |
|
190
|
0
|
|
|
|
|
|
my $L = $p{VARIANCE}; |
|
191
|
0
|
|
|
|
|
|
my $cum; |
|
192
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Gaussian' ) { $cum = 0; } |
|
|
0
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Brownian' ) { $cum = 1; } |
|
|
0
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
my $seed1 = $self->{SEED1}; |
|
195
|
0
|
|
|
|
|
|
my $seed2 = $self->{SEED2}; |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $output = __apprcirc($n,$H,$L,$cum,$seed1,$seed2); |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Save new seeds |
|
200
|
0
|
|
|
|
|
|
$self->{SEED1} = $$output[-2]; |
|
201
|
0
|
|
|
|
|
|
$self->{SEED2} = $$output[-1]; |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Truncate the array |
|
204
|
0
|
|
|
|
|
|
my @new_output = (); |
|
205
|
0
|
|
|
|
|
|
for(my $i=0;$i<$p{LENGTH};$i++) |
|
206
|
|
|
|
|
|
|
{ |
|
207
|
0
|
|
|
|
|
|
$new_output[$i] = $$output[$i]; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
return @new_output; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub Paxson |
|
214
|
|
|
|
|
|
|
{ |
|
215
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
216
|
0
|
|
|
|
|
|
my %p = (); |
|
217
|
0
|
|
|
|
|
|
%p = validate(@_,$Validate); |
|
218
|
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $n = int (log($p{LENGTH})/log(2.0)) + 1; |
|
220
|
0
|
|
|
|
|
|
my $H = $p{HURST}; |
|
221
|
0
|
|
|
|
|
|
my $L = $p{VARIANCE}; |
|
222
|
0
|
|
|
|
|
|
my $cum; |
|
223
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Gaussian' ) { $cum = 0; } |
|
|
0
|
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
|
if( $p{NOISE} =~ 'Brownian' ) { $cum = 1; } |
|
|
0
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
my $seed1 = $self->{SEED1}; |
|
226
|
0
|
|
|
|
|
|
my $seed2 = $self->{SEED2}; |
|
227
|
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
my $output = __paxson($n,$H,$L,$cum,$seed1,$seed2); |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Save new seeds |
|
231
|
0
|
|
|
|
|
|
$self->{SEED1} = $$output[-2]; |
|
232
|
0
|
|
|
|
|
|
$self->{SEED2} = $$output[-1]; |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# Truncate the array |
|
235
|
0
|
|
|
|
|
|
my @new_output = (); |
|
236
|
0
|
|
|
|
|
|
for(my $i=0;$i<$p{LENGTH};$i++) |
|
237
|
|
|
|
|
|
|
{ |
|
238
|
0
|
|
|
|
|
|
$new_output[$i] = $$output[$i]; |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
return @new_output; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub DESTROY |
|
245
|
|
|
|
|
|
|
{ |
|
246
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
1; |
|
251
|
|
|
|
|
|
|
__END__ |