Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slight performance improvements for flts #25

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/flts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ end
# Helper function that applies a certain number of C-steps to a subset H and checks for convergence
function optimize_H(A, y, h::Int, initial, maxiter::Int, ΔQmin)
Q_old = initial[3]
# Create object in outer scope
opt = nothing
local opt
# Apply C-steps until convergence / maxiter
for i in 1:maxiter
opt = C_step(A, y, initial[2], h)
Expand Down Expand Up @@ -127,7 +126,8 @@ end
# The C-step, workinghorse that guarentees converging parameters
function C_step(A, y, θ_old, h)
# Use the old parameters to get the residuals
residuals = y .- A * θ_old
residuals = copy(y)
mul!(residuals, A, θ_old, 1, -1)
# Sort the residuals and return a new subset with the smallest residuals
# H_new = sortperm(abs.(residuals))[1:h] # should be more efficient, but apperantly is not
H_new = sortperm(abs.(residuals))[1:h]
Expand All @@ -139,6 +139,9 @@ end

# get the objective function Q
function get_Q(A, y, H, θ)
residuals = y .- A * θ
return sum(abs2, residuals[H])
# residuals = y .- A * θ
residuals = copy(y)
mul!(residuals, A, θ, 1, -1)

return @views sum(abs2, residuals[H])
end