Skip to content

Commit adb400c

Browse files
committed
add stress test for lms and lts
1 parent e289030 commit adb400c

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

src/lms.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ function lms(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; iters = not
6868
iters = minimum([500 * p, 3000])
6969
end
7070
bestobjective = Inf
71-
bestparamaters = zeros(Float64, p)
72-
bestres = zeros(Float64, n)
73-
origres = zeros(Float64, n)
71+
bestparamaters = Array{Float64}(undef, p)
72+
bestres = Array{Float64}(undef, n)
73+
origres = Array{Float64}(undef, n)
7474
indices = collect(1:n)
7575
kindices = collect(p:n)
76-
betas = zeros(Float64, p)
77-
res = zeros(Float64, n)
76+
betas = Array{Float64}(undef, p)
77+
res = Array{Float64}(undef, n)
7878

7979
for _ = 1:iters
8080
try
8181
k = rand(kindices, 1)[1]
8282
sampledindices = sample(indices, k, replace = false)
83-
betas .= X[sampledindices, :] \ y[sampledindices]
84-
origres .= y .- X * betas
85-
res .= sort(origres .^ 2.0)
83+
betas = X[sampledindices, :] \ y[sampledindices]
84+
origres = y .- X * betas
85+
res = sort(origres .^ 2.0)
8686
m2 = res[h]
8787
if m2 < bestobjective
8888
bestparamaters .= betas

src/lts.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ function lts(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; iters=nothi
150150

151151
allindices = collect(1:n)
152152
bestobjective = Inf
153-
besthsubset = zeros(Int, h)
154-
subsetindices = zeros(Int, p)
153+
besthsubset = Array{Int}(undef, h)
154+
subsetindices = Array{Int}(undef, p)
155155

156156
bestobjectiveunchanged = 0
157157

158158
for _ = 1:iters
159-
subsetindices .= sample(allindices, p, replace=false)
159+
subsetindices = sample(allindices, p, replace=false)
160160
objective, hsubsetindices = iterateCSteps(X, y, subsetindices, h)
161161
if objective < bestobjective
162162
bestobjective = objective
163-
besthsubset .= hsubsetindices
163+
besthsubset = hsubsetindices
164164
bestobjectiveunchanged = 0
165165
else
166166
bestobjectiveunchanged += 1

test/testlms.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "LMS" begin
1+
@testset "LMS" verbose = true begin
22

33
@testset "LMS - Algorithm - Random data" begin
44
# Create simple data
@@ -33,4 +33,14 @@
3333
@test 21 in outset
3434
end
3535

36+
37+
@testset "LMS - Stress test (n=1000, p=10)" begin
38+
n = 1000
39+
p = 10
40+
x = rand(Float64, n, p)
41+
y = rand(Float64, n)
42+
result = lms(x, y)
43+
@test true
44+
end
45+
3646
end

test/testlts.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "LTS" begin
1+
@testset "LTS" verbose = true begin
22

33
@testset "LTS - Algorithm - Random data" begin
44
# Create simple data
@@ -32,4 +32,21 @@
3232
@test 21 in outset
3333
end
3434

35+
@testset "LTS - Stress test (n = 1000, p = 10)" begin
36+
n = 1000
37+
p = 10
38+
x = rand(Float64, n, p)
39+
y = rand(Float64, n)
40+
result = lts(x, y)
41+
@test true
42+
end
43+
44+
@testset "LTS - Stress test (n = 10000, p = 10)" begin
45+
n = 10000
46+
p = 10
47+
x = rand(Float64, n, p)
48+
y = rand(Float64, n)
49+
result = lts(x, y)
50+
@test true
51+
end
3552
end

0 commit comments

Comments
 (0)