3
3
# ------------------------------------------------------------------
4
4
5
5
"""
6
- ProjectionPursuit(;tol=1e-6, maxiter=100, deg=5, perc=.9, n=100)
6
+ ProjectionPursuit(; tol=1e-6, maxiter=100, deg=5, perc=0 .9, n=100, rng=Random.GLOBAL_RNG )
7
7
8
8
The projection pursuit multivariate transform converts any multivariate distribution into
9
9
the standard multivariate Gaussian distribution.
@@ -23,23 +23,29 @@ number of iterations reaches a maximum `maxiter`.
23
23
```julia
24
24
ProjectionPursuit()
25
25
ProjectionPursuit(deg=10)
26
- ProjectionPursuit(perc=.85, n=50)
27
- ProjectionPursuit(tol=1e-4, maxiter=250, deg=5, perc=.95, n=100)
26
+ ProjectionPursuit(perc=0.85, n=50)
27
+ ProjectionPursuit(tol=1e-4, maxiter=250, deg=5, perc=0.95, n=100)
28
+
29
+ # with rng
30
+ using Random
31
+ rng = MersenneTwister(2)
32
+ ProjectionPursuit(perc=0.85, n=50, rng=rng)
28
33
```
29
34
30
35
See [https://doi.org/10.2307/2289161](https://doi.org/10.2307/2289161) for
31
36
further details.
32
37
"""
33
- struct ProjectionPursuit{T} <: StatelessFeatureTransform
38
+ struct ProjectionPursuit{T,RNG } <: StatelessFeatureTransform
34
39
tol:: T
35
40
maxiter:: Int
36
41
deg:: Int
37
42
perc:: T
38
43
n:: Int
44
+ rng:: RNG
39
45
end
40
46
41
- ProjectionPursuit (;tol= 1e-6 , maxiter= 100 , deg= 5 , perc= .9 , n= 100 ) =
42
- ProjectionPursuit {typeof(tol)} (tol, maxiter, deg, perc, n)
47
+ ProjectionPursuit (; tol= 1e-6 , maxiter= 100 , deg= 5 , perc= 0 .9 , n= 100 , rng = Random . GLOBAL_RNG ) =
48
+ ProjectionPursuit {typeof(tol),typeof(rng) } (tol, maxiter, deg, perc, n, rng )
43
49
44
50
isrevertible (:: Type{<:ProjectionPursuit} ) = true
45
51
@@ -54,7 +60,7 @@ function pindex(transform, Z, α)
54
60
I = (3 / 2 ) * mean (r)^ 2
55
61
if d > 1
56
62
Pⱼ₋₂, Pⱼ₋₁ = ones (length (r)), r
57
- for j = 2 : d
63
+ for j in 2 : d
58
64
Pⱼ₋₂, Pⱼ₋₁ =
59
65
Pⱼ₋₁, (1 / j) * ((2 j- 1 ) * r .* Pⱼ₋₁ - (j- 1 ) * Pⱼ₋₂)
60
66
I += ((2 j+ 1 )/ 2 ) * (mean (Pⱼ₋₁))^ 2
76
82
function gaussquantiles (transform, N, q)
77
83
n = transform. n
78
84
p = 1.0 - transform. perc
79
- Is = [pbasis (transform, randn (N, q)) for i in 1 : n]
85
+ rng = transform. rng
86
+ Is = [pbasis (transform, randn (rng, N, q)) for i in 1 : n]
80
87
I = reduce (hcat, Is)
81
88
quantile .(eachrow (I), p)
82
89
end
@@ -119,18 +126,20 @@ function alphamax(transform, Z)
119
126
neldermead (transform, Z, α)
120
127
end
121
128
122
- function orthobasis (α, tol)
129
+ function orthobasis (transform, α)
130
+ tol = transform. tol
131
+ rng = transform. rng
123
132
q = length (α)
124
- Q, R = qr ([α rand (q, q- 1 )])
133
+ Q, R = qr ([α rand (rng, q, q- 1 )])
125
134
while norm (diag (R)) < tol
126
- Q, R = qr ([α rand (q, q- 1 )])
135
+ Q, R = qr ([α rand (rng, q, q- 1 )])
127
136
end
128
137
Q
129
138
end
130
139
131
140
function rmstructure (transform, Z, α)
132
141
# find orthonormal basis for rotation
133
- Q = orthobasis (α, transform . tol )
142
+ Q = orthobasis (transform, α )
134
143
135
144
# remove structure of first rotated axis
136
145
newtable, qcache = apply (Quantile (1 ), Tables. table (Z * Q))
0 commit comments