SciML / DataInterpolations.jl

A library of data interpolation and smoothing functions
MIT License
214 stars 45 forks source link

Performance and accuracy issues with Loess regression #29

Closed piever closed 6 months ago

piever commented 5 years ago

I'm comparing Loess with the Loess.jl package and results differ a bit. Steps to reproduce:

import DataInterpolations, Loess

t = sort(10 .* rand(100));
u = sin.(t) .+ 0.5 * randn(100);
l1 = DataInterpolations.Loess(u, t, 2, 0.75);
l2 = Loess.loess(t, u, degree=2, span=0.75);

using Plots
scatter(t, u, label="")
plot!(t, l1.(t), label="DataInterpolations.Loess")
plot!(t, Loess.predict(l2, t), label="Loess.loess")

Screenshot from 2019-04-18 18-22-18

Concerning performance, it's a bit puzzling as fitting here is much faster than Loess.jl and prediction is much slower:

julia> using BenchmarkTools

julia> @btime DataInterpolations.Loess($u, $t, 2, 0.75);
  1.706 μs (4 allocations: 4.31 KiB)

julia> @btime Loess.loess($t, $u, degree=2, span=0.75);
  4.058 ms (77694 allocations: 3.82 MiB)

But performance on the prediction degrades when the data is a bit bigger:

julia> t = sort(10 .* rand(1000));

julia> u = sin.(t) .+ 0.5 * randn(1000);

julia> l1 = DataInterpolations.Loess(u, t, 2, 0.75);

julia> l2 = Loess.loess(t, u, degree=2, span=0.75);

julia> @btime $l1.($t);
  43.769 ms (17003 allocations: 94.37 MiB)

julia> @btime Loess.predict($l2, $t);
  4.545 ms (48492 allocations: 1.48 MiB)
sipah00 commented 5 years ago

@piever Thanks for reporting this, Right now, I'm having my final exams, will look into it after some days.

ChrisRackauckas commented 6 months ago

LOESS was removed.