Skip to content

Commit 31bae7e

Browse files
authored
cumsum for Legendre (#248)
* cumsum for Legendre * Update test_roots.jl * Create detpointprocess.jl
1 parent 54bbe03 commit 31bae7e

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
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 <solver@mac.com>"]
4-
version = "0.15.5"
4+
version = "0.15.6"
55

66

77
[deps]

examples/detpointprocess.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using ClassicalOrthogonalPolynomials, Plots
2+
using ClassicalOrthogonalPolynomials: sample
3+
4+
x = Inclusion(ChebyshevInterval())
5+
6+
function christoffel(A)
7+
Q,R = qr(A)
8+
n = size(A,2)
9+
sum(expand(Q[:,k] .^2) for k=1:n)/n
10+
end
11+
12+
function dpp(A)
13+
m = size(A,2)
14+
Q,R = qr(A)
15+
r = Float64[]
16+
for n = m:-1:1
17+
Kₙ = sum(expand(Q[:,k] .^2) for k=1:n)/n
18+
r₁ = sample(Kₙ)
19+
push!(r, r₁)
20+
Q = Q*nullspace(Q[r₁, :]')
21+
end
22+
r
23+
end
24+
25+
m = 10
26+
A = cos.((0:m)' .* x)
27+
r = union([dpp(A) for _=1:1000]...)
28+
histogram(r; nbins=50, normalized=true)
29+
plot!(christoffel(A); ylims=(0,1))
30+
31+
## DPPs are much better condtioned
32+
Q,R = qr(A)
33+
@test cond(Q[dpp(A),:]) 100
34+
@test cond(Q[sample(christoffel(A),11),:]) 1000
35+
@test cond(Q[range(-1,1,11),:]) > 1E13

src/classical/ultraspherical.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ function diff(WS::WeightedUltraspherical{T}; dims=1) where T
185185
end
186186
end
187187

188+
function _cumsum(P::Legendre{V}, dims) where V
189+
@assert dims == 1
190+
Σ = Bidiagonal(Vcat(1, Zeros{V}(∞)), Fill(-one(V), ∞), :L)
191+
ApplyQuasiArray(*, Ultraspherical(-one(V)/2), Σ)
192+
end
193+
188194

189195
##########
190196
# Conversion

test/test_legendre.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,12 @@ import QuasiArrays: MulQuasiArray
229229
@testset "ChebyshevInterval constructor" begin
230230
@test legendre(ChebyshevInterval()) Legendre()
231231
end
232+
233+
@testset "cumsum" begin
234+
P = Legendre()
235+
x = axes(P,1)
236+
@test (P \ cumsum(P)) * (P \ exp.(x)) P \ (exp.(x) .- exp(-1))
237+
f = P * (P \ exp.(x))
238+
@test P \ cumsum(f) P \ (exp.(x) .- exp(-1))
239+
end
232240
end

test/test_roots.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
Q,R = qr(A)
3131
@test Q[0.1,:]'R A[0.1,:]'
3232

33-
# sum(expand(Q[:,k] .^2) for k=axes(Q,2))
33+
@test abs(sum(sample(sum(expand(Q[:,k] .^2) for k=axes(Q,2)), 1000))) 100 # mean is (numerically) zero
3434
end
3535

3636
@testset "minimum/maximum/extrema (#242)" begin

0 commit comments

Comments
 (0)