diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3163a..fc0b1a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v0.11.5 (Upcoming Release) - Initial implementation of the robust hat matrix regression estimator +- Introduce `view` in LTS and LMS. # v0.11.4 diff --git a/src/lms.jl b/src/lms.jl index 2e57e80..c8e451f 100644 --- a/src/lms.jl +++ b/src/lms.jl @@ -79,7 +79,7 @@ function lms(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; iters = not try k = rand(kindices) sampledindices = sample(indices, k, replace = false) - betas = X[sampledindices, :] \ y[sampledindices] + betas = view(X, sampledindices, :) \ view(y, sampledindices) res = sort!((y .- X * betas) .^ 2.0) m2 = res[h] if m2 < bestobjective diff --git a/src/lts.jl b/src/lts.jl index c0d2651..b630257 100644 --- a/src/lts.jl +++ b/src/lts.jl @@ -51,11 +51,11 @@ function iterateCSteps( iter::Int = 0 sortedresindices = Array{Int}(undef, n) while iter < maxiter - tempols = ols(X[subsetindices, :], y[subsetindices]) + tempols = ols(view(X, subsetindices, :), view(y, subsetindices)) res = y - X * coef(tempols) sortperm!(sortedresindices, abs.(res)) - subsetindices = sortedresindices[1:h] - objective = sum(sort!(res .^ 2.0)[1:h]) + subsetindices = view(sortedresindices, 1:h) + objective = sum(view(sort!(res .^ 2.0), 1:h)) if isapprox(oldobjective, objective, atol=eps) break end @@ -172,7 +172,7 @@ function lts(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; iters=nothi end end - ltsbetas = X[besthsubset, :] \ y[besthsubset] + ltsbetas = view(X, besthsubset, :) \ view(y, besthsubset) ltsres = y - X * ltsbetas ltsS = sqrt(sum((ltsres .^ 2.0)[1:h]) / (h - p)) ltsresmean = mean(ltsres[besthsubset]) diff --git a/test/runtests.jl b/test/runtests.jl index 33a4f99..03e1772 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,9 +6,9 @@ using LinearAlgebra using LinRegOutliers import Plots: RGBX -include("testdiagnostics.jl") include("testbasis.jl") include("testols.jl") +include("testdiagnostics.jl") include("tesths93.jl") include("testks89.jl") include("testsmr98.jl")