/
CorrelationDimension.pm6
102 lines (67 loc) · 1.8 KB
/
CorrelationDimension.pm6
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
use v6.c;
use Mathx::Chaos::Dimension;
use Mathx::Stat::Correlation;
role ThisCorrelationDimension {
method correlation($x,$y) { Mathx::Stat::Correlation.new.Correlation($x,$y); }
};
class Mathx::Chaos::CorrelationDimension is Mathx::Chaos::Dimension does ThisCorrelationDimension {
has $.r is rw;
has $.rthreshold is rw;
method BUILD() {
$.r = 1.0;
$.rthreshold = 0.0000001;
}
### Public Methods
method correlationdimension($x,$y,$r) {
### |X - Y| < D;
my $c = self.correlation($x,$y);
return log ($c + $r) / log ($r);
}
### The following function can be used to calculate a (high) limit
### which is a correlation dimension
### Note that a Boltzmann function can approximate Monte Carlo samples
### just as the dimension of the chaotic problem (dynamic system)
method dimension($x,$y) {
### |X - Y| < D;
my $c = self.correlation($x,$y);
return log ($c) / log ($.rthreshold);
}
method morerandomdimension($x,$y) {
### |X - Y| < D; D is entropially more expensive and random
my $c = self.correlation($x,$y);
return log ($c) / log (1 / ( 1..(1 /$.rthreshold).rand));
}
method dimension0($x) {
### NOTE : the limit is a sum, not the real limit :
### D = log ($x) / log ($rr)
my $rr = $.r;
my $countedlimit = 0.0;
while True {
my $countedlimit += (log $x) / (log ($rr));
if ($rr < $.rthreshold) {
return $countedlimit;
}
else
{
$rr /= 10;
}
}
}
method morerandomdimension0($x) {
### NOTE : the limit is a sum, not the real limit :
### D = log ($x) / log ($rr)
### The sum is more or less random
my $rr = $.r;
my $countedlimit = 0.0;
while True {
my $countedlimit += (log $x) / (log ($rr));
if ($rr < $.rthreshold) {
return $countedlimit;
}
else
{
$rr /= 1..10.rand;
}
}
}
}