1
- using StatsBase
2
- using LinearAlgebra
3
1
# Following the algorithm by William and Seeger, 2001
4
2
# Cs is equivalent to X_mm and C to X_mn
5
3
6
- function sampleindex (X:: AbstractMatrix , r:: AbstractFloat ; obsdim:: Integer = defaultobs)
4
+ function sampleindex (X:: AbstractMatrix , r:: Real ; obsdim:: Integer = defaultobs)
7
5
0 < r <= 1 || throw (ArgumentError (" Sample rate `r` must be in range (0,1]" ))
8
6
n = size (X, obsdim)
9
7
m = ceil (Int, n* r)
@@ -51,11 +49,16 @@ Type for storing a Nystrom factorization. The factorization contains two fields:
51
49
\m athbf{K} \a pprox \m athbf{C}^{\i ntercal}\m athbf{W}\m athbf{C}
52
50
```
53
51
"""
54
- struct NystromFact{T<: AbstractFloat }
52
+ struct NystromFact{T<: Real }
55
53
W:: Matrix{T}
56
54
C:: Matrix{T}
57
55
end
58
56
57
+ function NystromFact (W:: Matrix{<:Real} , C:: Matrix{<:Real} )
58
+ T = Base. promote_eltypeof (W, C)
59
+ return NystromFact (convert (Matrix{T}, W), convert (Matrix{T}, C))
60
+ end
61
+
59
62
@doc raw """
60
63
nystrom(k::Kernel, X::Matrix, S::Vector; obsdim::Int=defaultobs)
61
64
@@ -69,8 +72,7 @@ Nystrom factorization satisfying:
69
72
function nystrom (k:: Kernel , X:: AbstractMatrix , S:: Vector{<:Integer} ; obsdim:: Int = defaultobs)
70
73
C, Cs = nystrom_sample (k, X, S; obsdim= obsdim)
71
74
W = nystrom_pinv! (Cs)
72
- T = typeof (first (W))
73
- return NystromFact {T} (W, C)
75
+ return NystromFact (W, C)
74
76
end
75
77
76
78
@doc raw """
@@ -87,8 +89,7 @@ function nystrom(k::Kernel, X::AbstractMatrix, r::AbstractFloat; obsdim::Int=def
87
89
S = sampleindex (X, r; obsdim= obsdim)
88
90
C, Cs = nystrom_sample (k, X, S; obsdim= obsdim)
89
91
W = nystrom_pinv! (Cs)
90
- T = typeof (first (W))
91
- return NystromFact {T} (W, C)
92
+ return NystromFact (W, C)
92
93
end
93
94
94
95
"""
0 commit comments