Skip to content

Commit 3a20737

Browse files
authored
Marchenko–Pastur example, fix plotting of Q[:,1:n] (#109)
* Marchenko–Pastur example, fix plotting of Q[:,1:4] * restore plotgrid * Update normalized.jl
1 parent 93141e2 commit 3a20737

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.6.6"
4+
version = "0.6.7"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

examples/marchenkopasturops.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using ClassicalOrthogonalPolynomials, Plots
2+
3+
# MP law
4+
r = 0.5
5+
lmin, lmax = (1-sqrt(r))^2, (1+sqrt(r))^2
6+
U = chebyshevu(lmin..lmax)
7+
x = axes(U,1)
8+
w = @. 1/(2π) * sqrt((lmax-x)*(x-lmin))/(x*r)
9+
10+
# Q is a quasimatrix such that Q[x,k+1] is equivalent to
11+
# qₖ(x), the k-th orthogonal polynomial wrt to w
12+
Q = LanczosPolynomial(w, U)
13+
14+
# The Jacobi matrix associated with Q, as an ∞×∞ SymTridiagonal
15+
J = jacobimatrix(Q)
16+
17+
# plot q₀,…,q₆
18+
plot(Q[:,1:7])
19+
20+
# Wachter law
21+
a,b = 5,10
22+
c,d = sqrt(a/(a+b) * (1-1/(a+b))), sqrt(1/(a+b) * (1-a/(a+b)))
23+
lmin,lmax = (c-d)^2,(c+d)^2
24+
U = chebyshevu(lmin..lmax)
25+
x = axes(U,1)
26+
w = @. (a+b) * sqrt((x-lmin)*(lmax-x)/(2π*x*(1-x)))
27+
Q = LanczosPolynomial(w, U)
28+
plot(Q[:,1:7])

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,19 @@ _tritrunc(X, n) = _tritrunc(MemoryLayout(X), X, n)
245245
jacobimatrix(V::SubQuasiArray{<:Any,2,<:Any,<:Tuple{Inclusion,OneTo}}) =
246246
_tritrunc(jacobimatrix(parent(V)), maximum(parentindices(V)[2]))
247247

248-
grid(P::SubQuasiArray{<:Any,2,<:OrthogonalPolynomial,<:Tuple{Inclusion,Any}}) =
248+
grid(P::SubQuasiArray{<:Any,2,<:OrthogonalPolynomial,<:Tuple{Inclusion,OneTo}}) =
249249
eigvals(symtridiagonalize(jacobimatrix(P)))
250250

251+
function grid(Pn::SubQuasiArray{<:Any,2,<:OrthogonalPolynomial,<:Tuple{Inclusion,Any}})
252+
kr,jr = parentindices(Pn)
253+
grid(parent(Pn)[:,oneto(maximum(jr))])
254+
end
255+
256+
function plotgrid(Pn::SubQuasiArray{T,2,<:OrthogonalPolynomial,<:Tuple{Inclusion,Any}}) where T
257+
kr,jr = parentindices(Pn)
258+
grid(parent(Pn)[:,oneto(40maximum(jr))])
259+
end
260+
251261
function golubwelsch(X)
252262
D, V = eigen(symtridiagonalize(X)) # Eigenvalue decomposition
253263
D, V[1,:].^2

src/classical/jacobi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ summary(io::IO, P::Jacobi) = print(io, "Jacobi($(P.a), $(P.b))")
153153
# transforms
154154
###
155155

156-
function grid(Pn::SubQuasiArray{T,2,<:AbstractJacobi,<:Tuple{Inclusion,Any}}) where T
156+
function grid(Pn::SubQuasiArray{T,2,<:AbstractJacobi,<:Tuple{Inclusion,OneTo}}) where T
157157
kr,jr = parentindices(Pn)
158158
ChebyshevGrid{1,T}(maximum(jr))
159159
end

src/normalized.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ QuasiArrays.ApplyQuasiArray(Q::Normalized) = ApplyQuasiArray(*, arguments(ApplyL
8383

8484
ArrayLayouts.mul(Q::Normalized, C::AbstractArray) = ApplyQuasiArray(*, Q, C)
8585

86-
grid(Q::SubQuasiArray{<:Any,2,<:Normalized,<:Tuple{Inclusion,Any}}) = grid(view(parent(Q).P, parentindices(Q)...))
86+
grid(Q::SubQuasiArray{<:Any,2,<:Normalized,<:Tuple{Inclusion,OneTo}}) = grid(view(parent(Q).P, parentindices(Q)...))
8787
plotgrid(Q::SubQuasiArray{<:Any,2,<:Normalized,<:Tuple{Inclusion,Any}}) = plotgrid(view(parent(Q).P, parentindices(Q)...))
8888

8989
# transform_ldiv(Q::Normalized, C::AbstractQuasiArray) = Q.scaling .\ (Q.P \ C)

test/test_lanczos.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,36 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedLayout, ort
263263
R = U \ Q;
264264
@test R[1:5,1:5] isa Matrix{Float64}
265265
end
266+
267+
@testset "Marchenko–Pastur" begin
268+
# MP law
269+
r = 0.5
270+
lmin, lmax = (1-sqrt(r))^2, (1+sqrt(r))^2
271+
U = chebyshevu(lmin..lmax)
272+
x = axes(U,1)
273+
w = @. 1/(2π) * sqrt((lmax-x)*(x-lmin))/(x*r)
274+
275+
# Q is a quasimatrix such that Q[x,k+1] is equivalent to
276+
# qₖ(x), the k-th orthogonal polynomial wrt to w
277+
Q = LanczosPolynomial(w, U)
278+
279+
# The Jacobi matrix associated with Q, as an ∞×∞ SymTridiagonal
280+
J = jacobimatrix(Q)
281+
282+
@test J[1:3,1:3] SymTridiagonal([1,1.5,1.5], fill(1/sqrt(2),2))
283+
284+
# plot q₀,…,q₆
285+
@test plotgrid(Q[:,1:7]) eigvals(Symmetric(J[1:280,1:280]))
286+
end
287+
288+
@testset "Wachter law" begin
289+
a,b = 5,10
290+
c,d = sqrt(a/(a+b) * (1-1/(a+b))), sqrt(1/(a+b) * (1-a/(a+b)))
291+
lmin,lmax = (c-d)^2,(c+d)^2
292+
U = chebyshevu(lmin..lmax)
293+
x = axes(U,1)
294+
w = @. (a+b) * sqrt((x-lmin)*(lmax-x)/(2π*x*(1-x)))
295+
Q = LanczosPolynomial(w, U)
296+
@test Q[0.5,1:3] [0.9384176649676137,1.2140849874743076,0.5387898199391473]
297+
end
266298
end

0 commit comments

Comments
 (0)