Class: Quasi::Halton
Instance Method Summary
collapse
#L2_discrepancy, #n_inverse, #nextQuasiNormalVector, #product, #productSQ, #projectionOut, #restart
Constructor Details
#initialize(dim) ⇒ Halton
Returns a new instance of Halton.
12
13
14
15
16
|
# File 'lib/halton.rb', line 12
def initialize(dim)
super(dim)
compute_primes()
@x=NArray.float(dim)
end
|
Instance Method Details
#compute_primes ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/halton.rb', line 18
def compute_primes()
@prime= NArray.int(@dim)
@prime[0]=2
if(@dim>1)
@prime[1]=3
end
if(@dim>2)
@prime[2]=5
end
for j in 3..@dim
q=@prime[j-1]+2
while !isPrime(q) do
q+=1
end
@prime[j]=q
end
end
|
#getName ⇒ Object
84
85
86
|
# File 'lib/halton.rb', line 84
def getName
return "Halton Sequence"
end
|
#isPrime(q) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/halton.rb', line 39
def isPrime(q)
is_prime=false
m=Math.sqrt(q).to_int
i=0
p=@prime[i]
while(p<=m) do
if(q%p==0)
return false
end
i+=1
p=@prime[i]
end
return true
end
|
#nextPoint ⇒ Object
78
79
80
81
82
|
# File 'lib/halton.rb', line 78
def nextPoint
n=@index
@index+=1
return pointO(n)
end
|
#point(n, s) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/halton.rb', line 57
def point(n,s)
p=@prime[s]
x,f = 0.0,1.0
while (n>0)
f/=p
x+=(n%p)*f
n=n/p
end
return x
end
|
#pointO(n) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/halton.rb', line 70
def pointO(n)
x=Array.new(@dim)
for s in 0..@dim-1 x[s]=point(n,s)
end
return x
end
|