Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tw/interface #5

Merged
merged 5 commits into from
Nov 28, 2023
Merged

Tw/interface #5

merged 5 commits into from
Nov 28, 2023

Conversation

tweisser
Copy link
Contributor

@tweisser tweisser commented Jun 8, 2020

I unified the interface for Monomial and Polynomial Bases (now the field is called elements).
The idea is, that <:AbstractPolynomialBasis is a wrapper for a familiy of polynomials that we label as a basis in some sense (similar to MP.MonomialVector).
I added iterate, getindex, and a coefficients(poly, basis_type) function which returns a vector of coefficients which should yield

p == polynomial(coefficients(p, basis), basis_covering_monomials(basis, monomials(p))

I'm working on changes to depended packages.

src/fixed.jl Outdated Show resolved Hide resolved
src/fixed.jl Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2020

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (417aec8) 96.87% compared to head (2aeb23f) 96.08%.

❗ Current head 2aeb23f differs from pull request most recent head c9059ad. Consider uploading reports for the commit c9059ad to get more accurate results

Files Patch % Lines
src/orthogonal.jl 68.42% 6 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #5      +/-   ##
==========================================
- Coverage   96.87%   96.08%   -0.79%     
==========================================
  Files          10       10              
  Lines         224      281      +57     
==========================================
+ Hits          217      270      +53     
- Misses          7       11       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/fixed.jl Outdated Show resolved Hide resolved
src/fixed.jl Outdated
```
=#
function MP.coefficients(p, Basis::Type{<:AbstractPolynomialBasis})
basis = maxdegree_basis(Basis, variables(p), maxdegree(p))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define

function MP.coefficients(p, Basis::Type{<:AbstractPolynomialBasis})
    return MP.coefficients(p, maxdegree_basis(Basis, variables(p), maxdegree(p)))
end
function MP.coefficients(p, basis::AbstractPolynomialBasis)
    # ...
end

It is needed for https://github.com/JuliaAlgebra/MultivariateMoments.jl/pull/16/files#r438604571

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying an instantiated basis would kind of imply that we return a vector of coefficients of length length(basis). So far I am deleting zero coefficients to be consistent with coefficients(p).

@tweisser
Copy link
Contributor Author

I introduced inner products for the orthogonal bases and defined MP.coefficients(p, basis::AbstractMultipleOrthogonalBasis).
The inner products are numerically quite instable (dividing huge numbers). As a result coefficient function is numerically unstable, too. I had to introduce isapprox in place of == at some points to make the tests pass. I imagine, going to higher degrees, the tolerances will not be sufficient.

src/chebyshev.jl Outdated
elseif mod(i, 2) == 1
return 0
else
n = Int(i/2)
Copy link
Member

@blegat blegat Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n = div(i, 2)

src/chebyshev.jl Outdated
function sp(i::Int)
if i == 0
return π
elseif mod(i, 2) == 1
Copy link
Member

@blegat blegat Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elseif isodd(i)

src/chebyshev.jl Outdated
return 0
else
n = Int(i/2)
return π*factorial(i)/(2^i * factorial(n)^2)
Copy link
Member

@blegat blegat Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will very quickly exceed the capacity of Int64. We can simplify factorial(i) with factorial(n), do pi / 2^i so that it transforms to Float64 before multiplying with factorial(n)

src/chebyshev.jl Outdated
function sp(i::Int)
if i == 0
return π/2
elseif mod(i, 2) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments than for the other one

src/fixed.jl Outdated Show resolved Hide resolved
src/legendre.jl Outdated
@@ -28,3 +28,15 @@ reccurence_third_coef(::Type{<:LegendreBasis}, degree) = -(degree - 1)
reccurence_deno_coef(::Type{<:LegendreBasis}, degree) = degree

degree_one_univariate_polynomial(::Type{<:LegendreBasis}, variable::MP.AbstractVariable) = MA.@rewrite(variable + 0)

function scalar_product_function(::Type{<:LegendreBasis})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function scalar_product_function(::Type{<:LegendreBasis}, i::Int)

@blegat
Copy link
Member

blegat commented Jul 13, 2020

struct PolynomialInBasis{C, B}
    coefficients::Vector{C}
    basis::B
end

and instead of MP.coefficient, we could have in_basis(p, basis)::PolynomialInBasis

@blegat
Copy link
Member

blegat commented Jul 13, 2020

in_basis(x^2 + 2, MonomialBasis([x^2, x, 1])) -> PolynomialInBasis([1, 0, 2], MonomialBasis([x^2, x, 1])
in_basis(x^2 + 2, MonomialBasis) -> PolynomialInBasis([1, 2], MonomialBasis([x^2, 1])

@blegat blegat merged commit 5892f39 into JuliaAlgebra:master Nov 28, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants