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

AssertionError: length(ret) == n #8

Open
cscherrer opened this issue Sep 19, 2020 · 5 comments
Open

AssertionError: length(ret) == n #8

cscherrer opened this issue Sep 19, 2020 · 5 comments

Comments

@cscherrer
Copy link

Hi @simonbyrne , thanks for this package!

In trying this out, I've gotten really nice results for things like a polynomial approximation to log1pexp. But this AssertionError seems very common. It had seemed to happen mostly when asking for rational function approximations - polynomial approximations seem a little more likely to work - but it also fails in (what would seem to be) simple cases like

using Distributions
julia> ratfn_minimax(x -> logpdf(Beta(2,4),x), (nextfloat(0.0),prevfloat(1.0)),2,0)
ERROR: AssertionError: length(ret) == n
Stacktrace:
 [1] winnow_extrema(::Array{Tuple{BigFloat,BigFloat},1}, ::Int64) at /home/chad/.julia/packages/Remez/HLpT8/src/Remez.jl:347
 [2] ratfn_minimax(::var"#50#51", ::Tuple{Float64,Float64}, ::Int64, ::Int64, ::Remez.var"#8#13") at /home/chad/.julia/packages/Remez/HLpT8/src/Remez.jl:598
 [3] ratfn_minimax(::Function, ::Tuple{Float64,Float64}, ::Int64, ::Int64) at /home/chad/.julia/packages/Remez/HLpT8/src/Remez.jl:557
 [4] top-level scope at REPL[36]:1
 [5] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088

Any idea what's going on here?

@simonbyrne
Copy link
Owner

Sorry, I don't actually know that much about the internals (all I really did is take the ARM code and turn it into a package), though one day I'll read up on it. I have found that modifying one side of the interval can sometimes help, e.g. #6 (comment)

@cscherrer
Copy link
Author

Thanks, that Arnoldi paper looks really interesting too

@oscardssmith
Copy link

I've found that one place this can happen is if there's a division by zero (especially annoying when it's a 0/0 that mathematically should be defined)

@simonbyrne
Copy link
Owner

@oscardssmith do you have an example?

@KlausC
Copy link

KlausC commented Jun 6, 2022

Here are some elementary examples, which fail with that error.

julia> f(x) = x
f (generic function with 1 method)

julia> N,D,E,X = ratfn_minimax(f, (-1.0, 1.0), 3, 3)
ERROR: AssertionError: length(ret) == n
Stacktrace:
 [1] winnow_extrema(extrema::Vector{Tuple{BigFloat, BigFloat}}, n::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:347
 [2] ratfn_minimax(f::typeof(f), interval::Tuple{Float64, Float64}, n::Int64, d::Int64, w::Remez.var"#8#13")
   @ Remez ~/dev/Remez.jl/src/Remez.jl:598
 [3] ratfn_minimax(f::Function, interval::Tuple{Float64, Float64}, n::Int64, d::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:557
 [4] top-level scope
   @ REPL[17]:1

julia> f(x) = (x + x^2 ) * (x - x^3/6)
f (generic function with 1 method)

julia> N,D,E,X = ratfn_minimax(f, (-1.0, 1.0), 2, 2)
ERROR: AssertionError: length(ret) == n
Stacktrace:
 [1] winnow_extrema(extrema::Vector{Tuple{BigFloat, BigFloat}}, n::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:347
 [2] ratfn_minimax(f::typeof(f), interval::Tuple{Float64, Float64}, n::Int64, d::Int64, w::Remez.var"#8#13")
   @ Remez ~/dev/Remez.jl/src/Remez.jl:598
 [3] ratfn_minimax(f::Function, interval::Tuple{Float64, Float64}, n::Int64, d::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:557
 [4] top-level scope
   @ REPL[12]:1

julia> f(x) = (x + x^2 ) * x
f (generic function with 1 method)

julia> N,D,E,X = ratfn_minimax(f, (-1.0, 1.0), 2, 2)
ERROR: AssertionError: length(ret) == n
Stacktrace:
 [1] winnow_extrema(extrema::Vector{Tuple{BigFloat, BigFloat}}, n::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:347
 [2] ratfn_minimax(f::typeof(f), interval::Tuple{Float64, Float64}, n::Int64, d::Int64, w::Remez.var"#8#13")
   @ Remez ~/dev/Remez.jl/src/Remez.jl:598
 [3] ratfn_minimax(f::Function, interval::Tuple{Float64, Float64}, n::Int64, d::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:557
 [4] top-level scope
   @ REPL[14]:1

julia> N,D,E,X = ratfn_minimax(f, (-1.0, 1.0), 3, 3)
ERROR: AssertionError: length(ret) == n
Stacktrace:
 [1] winnow_extrema(extrema::Vector{Tuple{BigFloat, BigFloat}}, n::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:347
 [2] ratfn_minimax(f::typeof(f), interval::Tuple{Float64, Float64}, n::Int64, d::Int64, w::Remez.var"#8#13")
   @ Remez ~/dev/Remez.jl/src/Remez.jl:598
 [3] ratfn_minimax(f::Function, interval::Tuple{Float64, Float64}, n::Int64, d::Int64)
   @ Remez ~/dev/Remez.jl/src/Remez.jl:557
 [4] top-level scope
   @ REPL[15]:1

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

No branches or pull requests

4 participants