Skip to content

Commit 7068143

Browse files
committed
gram schmidt orthogonalization
1 parent 2a8661e commit 7068143

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

src/BasisFunctions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ include("sampling/quadweights.jl")
322322

323323
include("bases/dictionary/indexing.jl")
324324
include("bases/dictionary/dictionary.jl")
325+
include("bases/dictionary/dict_evaluation.jl")
326+
include("bases/dictionary/dict_moments.jl")
325327
include("bases/dictionary/promotion.jl")
326328
include("bases/dictionary/span.jl")
327329
include("bases/dictionary/orthog.jl")

src/bases/dictionary/dictionary.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,3 @@ function iterate(d::Dictionary, state)
327327
(d[next_item], (iter,next_tuple))
328328
end
329329
end
330-
331-
332-
333-
include("dict_evaluation.jl")
334-
include("dict_moments.jl")

src/bases/dictionary/expansions.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,6 @@ expansion_of_one(dict::Dictionary) = Expansion(dict, coefficients_of_one(dict))
217217
expansion_of_x(dict::Dictionary) = Expansion(dict, coefficients_of_x(dict))
218218

219219
apply(op::DictionaryOperator, e::Expansion) = Expansion(dest(op), op * coefficients(e))
220+
221+
norm(f::Expansion) = norm(f, measure(f))
222+
norm(f::Expansion, μ) = sqrt(innerproduct(f, f, μ))

src/bases/dictionary/orthog.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,28 @@ function mixedgrammatrix!(G, Φ1::Dictionary, Φ2::Dictionary, μ; options...)
278278
end
279279
G
280280
end
281+
282+
283+
#################################
284+
# Gram-Schmidt orthogonalization
285+
#################################
286+
287+
288+
function gram_schmidt(U::Dictionary, μ = measure(U))
289+
N = length(U)
290+
V = [Expansion(U, zeros(U)) for k in 1:N]
291+
V[1].coefficients[1] = 1 / norm(U[1], μ)
292+
for k in 2:N
293+
V[k].coefficients[k] = 1
294+
for j in 1:k-1
295+
V[k] = V[k] - innerproduct(V[k], V[j], μ) * V[j]
296+
end
297+
V[k] = V[k] / norm(V[k], μ)
298+
end
299+
300+
A = UpperTriangular(zeros(coefficienttype(U), N, N))
301+
for k in 1:N
302+
A[1:k,k] = V[k].coefficients[1:k]
303+
end
304+
A*U
305+
end

src/bases/poly/polynomials.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ degree(p::Polynomial) = p.degree
5757

5858
support(p::Polynomial) = support(dictionary(p))
5959
measure(p::Polynomial) = measure(dictionary(p))
60+
61+
########################
62+
# Polynomial expansions
63+
########################
64+
65+
"""
66+
polynomialdegree(f::Expansion)
67+
68+
If `f` is an expansion in a polynomial basis, return the degree of the polynomial function (not taking
69+
into account possible leading zero coefficients).
70+
"""
71+
polynomialdegree(f::Expansion) = maxpolynomialdegree(dictionary(f))
72+
73+
"The maximal polynomial degree of any expansion in the given basis."
74+
maxpolynomialdegree(b::PolynomialBasis) = PolynomialDegree(length(b)-1)
75+
76+
maxpolynomialdegree(b::OperatedDict) = maxpolynomialdegree(superdict(b))

src/computations/approximation.jl

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Generic approximation
44
########################
55

6+
const ANYFUNCTION = Union{Function,Expansion,TypedFunction}
7+
68
"""
79
The `approximation` function returns an operator that can be used to approximate
810
a function in the function set. This operator maps a grid to a set of coefficients.
@@ -23,27 +25,14 @@ end
2325
continuous_approximation::Dictionary; options...) = inv(gram(Φ; options...))
2426

2527
# Automatically sample a function if an operator is applied to it
26-
(*)(op::DictionaryOperator, f::Function) = op * project(src(op), f)
27-
Base.:\(op::DictionaryOperator, f::Function) = op \ project(dest(op), f)
28+
(*)(op::DictionaryOperator, f::ANYFUNCTION) = op * project(src(op), f)
29+
Base.:\(op::DictionaryOperator, f::ANYFUNCTION) = op \ project(dest(op), f)
2830

29-
project::GridBasis, f::Function; options...) = sample(Φ, f)
31+
project::GridBasis, f::ANYFUNCTION; options...) = sample(Φ, f)
3032

3133
approximate::Dictionary, f::Function; options...) =
3234
Expansion(Φ, approximation(Φ; options...) * f)
3335

34-
"""
35-
The 2-argument approximation exists to allow you to transform any
36-
Dictionary coefficients to any other Dictionary coefficients, including
37-
Discrete Grid Spaces.
38-
If a transform exists, the transform is used.
39-
"""
40-
function approximation(A::Dictionary, B::Dictionary, options...)
41-
if hastransform(A, B)
42-
return transform(A, B; options...)
43-
else
44-
error("Don't know a transform from ", A, " to ", B)
45-
end
46-
end
4736

4837

4938
#################
@@ -78,7 +67,7 @@ default_interpolation(Φ::Dictionary, gb::GridBasis; options...) =
7867
default_interpolation(::Type{T}, Φ::Dictionary, gb::GridBasis; options...) where {T} =
7968
QR_solver(evaluation(T, Φ, grid(gb)))
8069

81-
interpolate::Dictionary, pts, f, T=coefficienttype(s)) = Expansion(interpolation(T, Φ, pts) * f)
70+
interpolate::Dictionary, pts, f, T=coefficienttype(Φ)) = Expansion(Φ,interpolation(T, Φ, pts) * f)
8271

8372
"""
8473
Compute the weights of an interpolatory quadrature rule.

0 commit comments

Comments
 (0)