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