Skip to content

Commit 4a2bcf8

Browse files
committed
introduce view in LTS and LMS
1 parent c76ce2c commit 4a2bcf8

4 files changed

Lines changed: 7 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v0.11.5 (Upcoming Release)
22

33
- Initial implementation of the robust hat matrix regression estimator
4+
- Introduce `view` in LTS and LMS.
45

56
# v0.11.4
67

src/lms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function lms(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; iters = not
7979
try
8080
k = rand(kindices)
8181
sampledindices = sample(indices, k, replace = false)
82-
betas = X[sampledindices, :] \ y[sampledindices]
82+
betas = view(X, sampledindices, :) \ view(y, sampledindices)
8383
res = sort!((y .- X * betas) .^ 2.0)
8484
m2 = res[h]
8585
if m2 < bestobjective

src/lts.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ function iterateCSteps(
5151
iter::Int = 0
5252
sortedresindices = Array{Int}(undef, n)
5353
while iter < maxiter
54-
tempols = ols(X[subsetindices, :], y[subsetindices])
54+
tempols = ols(view(X, subsetindices, :), view(y, subsetindices))
5555
res = y - X * coef(tempols)
5656
sortperm!(sortedresindices, abs.(res))
57-
subsetindices = sortedresindices[1:h]
58-
objective = sum(sort!(res .^ 2.0)[1:h])
57+
subsetindices = view(sortedresindices, 1:h)
58+
objective = sum(view(sort!(res .^ 2.0), 1:h))
5959
if isapprox(oldobjective, objective, atol=eps)
6060
break
6161
end
@@ -172,7 +172,7 @@ function lts(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; iters=nothi
172172
end
173173
end
174174

175-
ltsbetas = X[besthsubset, :] \ y[besthsubset]
175+
ltsbetas = view(X, besthsubset, :) \ view(y, besthsubset)
176176
ltsres = y - X * ltsbetas
177177
ltsS = sqrt(sum((ltsres .^ 2.0)[1:h]) / (h - p))
178178
ltsresmean = mean(ltsres[besthsubset])

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using LinearAlgebra
66
using LinRegOutliers
77
import Plots: RGBX
88

9-
include("testdiagnostics.jl")
109
include("testbasis.jl")
1110
include("testols.jl")
11+
include("testdiagnostics.jl")
1212
include("tesths93.jl")
1313
include("testks89.jl")
1414
include("testsmr98.jl")

0 commit comments

Comments
 (0)