Skip to content

Commit ad7006c

Browse files
committed
remove modifications to fit function`
1 parent 5c74be9 commit ad7006c

File tree

4 files changed

+15
-36
lines changed

4 files changed

+15
-36
lines changed

docs/src/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ end
1616

1717
```@docs
1818
coeffs
19-
order
2019
degree
2120
length
2221
size
2322
domain
2423
mapdomain
2524
chop
2625
chop!
26+
round
2727
truncate
2828
truncate!
2929
```

src/common.jl

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,22 @@ fromroots(A::AbstractMatrix{T}; var::SymbolLike = :x) where {T <: Number} =
6060
fromroots(Polynomial, eigvals(A), var = var)
6161

6262
"""
63-
fit(x, y, deg=length(x) - 1; [weights], var=:x)
64-
fit(::Type{<:AbstractPolynomial}, x, y, deg=length(x)-1; [weights], var=:x)
65-
66-
Fit the given data as a polynomial type with the given degree. Uses linear least squares. When weights are given, as either a `Number`, `Vector` or `Matrix`, will use weighted linear least squares. The default polynomial type is [`Polynomial`](@ref). This will automatically scale your data to the [`domain`](@ref) of the polynomial type using [`mapdomain`](@ref). To specify a different range to scale to, specify `domain=(a,b)` where `a <= minimum(xs) && maximum(xs) <= b`.
63+
fit(x, y; [weights], deg=length(x) - 1, var=:x)
64+
fit(::Type{<:AbstractPolynomial}, x, y; [weights], deg=length(x)-1, var=:x)
65+
Fit the given data as a polynomial type with the given degree. Uses linear least squares. When weights are given, as either a `Number`, `Vector` or `Matrix`, will use weighted linear least squares. The default polynomial type is [`Polynomial`](@ref). This will automatically scale your data to the [`domain`](@ref) of the polynomial type using [`mapdomain`](@ref)
6766
"""
6867
function fit(P::Type{<:AbstractPolynomial},
6968
x::AbstractVector{T},
7069
y::AbstractVector{T},
71-
deg::Integer=length(x) - 1;
72-
domain=(minimum(x), maximum(x)),
73-
weights = nothing,
74-
var = :x,) where {T}
75-
x = mapdomain(P, first(domain),last(domain)).(x)
70+
deg::Integer = length(x) - 1;
71+
weights = nothing,
72+
var = :x,) where {T}
73+
x = mapdomain(P, x)
7674
vand = vander(P, x, deg)
7775
if weights !== nothing
7876
coeffs = _wlstsq(vand, y, weights)
7977
else
80-
coeffs = vand \ y #pinv(vand) * y
78+
coeffs = pinv(vand) * y
8179
end
8280
return P(T.(coeffs), var)
8381
end
@@ -196,7 +194,8 @@ In-place version of [`chop`](@ref)
196194
"""
197195
function chop!(p::AbstractPolynomial{T};
198196
rtol::Real = Base.rtoldefault(real(T)),
199-
atol::Real = 0,) where {T}
197+
atol::Real = 0,) where {T}
198+
degree(p) == -1 && return p
200199
for i = lastindex(p):-1:0
201200
val = p[i]
202201
if !isapprox(val, zero(T); rtol = rtol, atol = atol)
@@ -353,25 +352,6 @@ function mapdomain(P::Type{<:AbstractPolynomial}, x::AbstractArray)
353352
return x_scaled
354353
end
355354
mapdomain(::P, x::AbstractArray) where {P <: AbstractPolynomial} = mapdomain(P, x)
356-
357-
"""
358-
mapdomain(P::Type{<:AbstractPolynomial}, a , b)
359-
360-
Returns a *linear* function ϕ: [a,b] -> domain(P)
361-
362-
If either endpoint if infinite, returns `identity`.
363-
"""
364-
function mapdomain(P::Type{<:AbstractPolynomial}, a::Number, b::Number)
365-
a, b = a < b ? (a,b) : (b,a)
366-
dom = domain(P)
367-
m, M = first(dom), last(dom)
368-
(isinf(a) || isinf(b) || isinf(m) || isinf(M)) && return x -> x
369-
x -> begin
370-
lambda = (x-a)/(b-a)
371-
m + lambda * (last(dom) - first(dom))
372-
end
373-
end
374-
375355
#=
376356
indexing =#
377357
Base.firstindex(p::AbstractPolynomial) = 0
@@ -527,7 +507,7 @@ function Base.gcd(p1::AbstractPolynomial{T}, p2::AbstractPolynomial{S}) where {T
527507
while r₁ zero(r₁) && iter itermax # just to avoid unnecessary recursion
528508
_, rtemp = divrem(r₀, r₁)
529509
r₀ = r₁
530-
r₁ = truncate(rtemp)
510+
r₁ = truncate(rtemp)
531511
iter += 1
532512
end
533513
return r₀

src/polynomials/Poly.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module PolyCompat
22

33
using ..Polynomials
4-
export poly, polyval, polyint, polyder, polyfit
4+
export poly, polyval, polyint, polyder #, polyfit
55

66
#=
77
This type is only here to provide stability while deprecating. This will eventually be removed in favor
@@ -176,7 +176,7 @@ Polynomials.polyint(p::Poly, C = 0) = integrate(p, C)
176176
Polynomials.polyint(p::Poly, a, b) = integrate(p, a, b)
177177
Polynomials.polyder(p::Poly, ord = 1) = derivative(p, ord)
178178

179-
polyfit(x, y, n = length(x) - 1, sym=:x) = fit(Poly, x, y, n; var = sym)
180-
polyfit(x, y, sym::Symbol) = fit(Poly, x, y, var = sym)
179+
#polyfit(x, y, n = length(x) - 1, sym=:x) = fit(Poly, x, y, n; var = sym)
180+
#polyfit(x, y, sym::Symbol) = fit(Poly, x, y, var = sym)
181181

182182
end

src/polynomials/Polynomial.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ function Base.:*(p1::Polynomial{T}, p2::Polynomial{S}) where {T,S}
206206
p1.var != p2.var && error("Polynomials must have same variable")
207207
n,m = length(p1)-1, length(p2)-1 # not degree, so pNULL works
208208
R = promote_type(T, S)
209-
N = m + n
210209
c = zeros(R, m + n + 1)
211210
for i in 0:n, j in 0:m
212211
@inbounds c[i + j + 1] += p1[i] * p2[j]

0 commit comments

Comments
 (0)