From 620a25c25044584dff0b21b4bf4e8eb8fb7c192a Mon Sep 17 00:00:00 2001 From: mischmi96 Date: Mon, 18 Jan 2021 14:38:53 +0100 Subject: [PATCH] adds minor changes to verbose functionality for lsqr --- Project.toml | 2 +- src/nperiodic_approx_scat_lsqr.jl | 16 +++++++++------- src/periodic_approx_scat_lsqr.jl | 14 ++++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Project.toml b/Project.toml index af32755..d74da55 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ANOVAapprox" uuid = "5e027bd6-ab01-4733-8320-e0223e929ebb" authors = ["Michael Schmischke and Felix Bartel "] -version = "1.0.6" +version = "1.0.7" [deps] Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" diff --git a/src/nperiodic_approx_scat_lsqr.jl b/src/nperiodic_approx_scat_lsqr.jl index 353a638..5407b61 100644 --- a/src/nperiodic_approx_scat_lsqr.jl +++ b/src/nperiodic_approx_scat_lsqr.jl @@ -1,4 +1,4 @@ -mutable struct nperiodic_approx_scat_lsqr{d,ds} <: nperiodic_approx +mutable struct nperiodic_approx_scat_lsqr{d,ds} <: nperiodic_approx basis::String X::Matrix{Float64} y::Vector{ComplexF64} @@ -9,11 +9,11 @@ mutable struct nperiodic_approx_scat_lsqr{d,ds} <: nperiodic_approx function nperiodic_approx_scat_lsqr{d,ds}( basis::String, X::Matrix{Float64}, y::Vector{ComplexF64}, U::Vector{Vector{Int64}}, trafo::GroupedTransform, N::Vector{Int64} ) where {d,ds} return new( basis, X, y, U, trafo, N, Dict{Float64,GroupedCoeff}() ) - end + end end function const_one( x )::Float64 - return 1.0 + return 1.0 end function approximate( approx::nperiodic_approx_scat_lsqr{d,ds}; max_iter::Int64=30, lambda::Vector{Float64}=[0.0,], smoothness::Float64=1.5, density::Function=const_one, verbose::Bool=false )::Nothing where {d,ds} @@ -23,8 +23,10 @@ function approximate( approx::nperiodic_approx_scat_lsqr{d,ds}; max_iter::Int64= nf = get_NumFreq( approx ) dsqrt = [ sqrt(density(approx.X[:,i])) for i in 1:M ] - for i = 1:length(lambda) - println( i, ". Lambda: ", lambda[i] ) + for i = 1:length(lambda) + if verbose + println( i, ". Lambda: ", lambda[i] ) + end wsqrt = sqrt(lambda[i]).*(sqrt.(vec(what))) F_vec = LinearMap{ComplexF64}( @@ -33,9 +35,9 @@ function approximate( approx::nperiodic_approx_scat_lsqr{d,ds}; max_iter::Int64= size(approx.X, 2)+nf, nf ) tmp = zeros( ComplexF64, nf ) - lsqr!( tmp, F_vec, vcat(dsqrt .* approx.y,zeros(ComplexF64,nf)), maxiter = max_iter, verbose=verbose ) + lsqr!( tmp, F_vec, vcat(dsqrt .* approx.y,zeros(ComplexF64,nf)), maxiter = max_iter, verbose=verbose ) approx.fc[lambda[i]] = GroupedCoeff(approx.trafo.setting, tmp) end - return + return end diff --git a/src/periodic_approx_scat_lsqr.jl b/src/periodic_approx_scat_lsqr.jl index 077cc74..a0ac982 100644 --- a/src/periodic_approx_scat_lsqr.jl +++ b/src/periodic_approx_scat_lsqr.jl @@ -1,4 +1,4 @@ -mutable struct periodic_approx_scat_lsqr{d,ds} <: periodic_approx +mutable struct periodic_approx_scat_lsqr{d,ds} <: periodic_approx X::Matrix{Float64} y::Vector{ComplexF64} U::Vector{Vector{Int64}} @@ -8,7 +8,7 @@ mutable struct periodic_approx_scat_lsqr{d,ds} <: periodic_approx function periodic_approx_scat_lsqr{d,ds}( X::Matrix{Float64}, y::Vector{ComplexF64}, U::Vector{Vector{Int64}}, trafo::GroupedTransform, N::Vector{Int64} ) where {d,ds} return new( X, y, U, trafo, N, Dict{Float64,GroupedCoeff}() ) - end + end end function approximate( approx::periodic_approx_scat_lsqr{d,ds}; max_iter::Int64=30, lambda::Vector{Float64}=[0.0,], smoothness::Float64=1.5, verbose::Bool=false )::Nothing where {d,ds} @@ -16,8 +16,10 @@ function approximate( approx::periodic_approx_scat_lsqr{d,ds}; max_iter::Int64=3 M = size(approx.X,2) nf = get_NumFreq( approx ) - for i = 1:length(lambda) - println( i, ". Lambda: ", lambda[i] ) + for i = 1:length(lambda) + if verbose + println( i, ". Lambda: ", lambda[i] ) + end wsqrt = sqrt(lambda[i]).*(sqrt.(vec(what))) F_vec = LinearMap{ComplexF64}( @@ -26,9 +28,9 @@ function approximate( approx::periodic_approx_scat_lsqr{d,ds}; max_iter::Int64=3 size(approx.X, 2)+nf, nf ) tmp = zeros( ComplexF64, nf ) - lsqr!( tmp, F_vec, vcat(approx.y,zeros(ComplexF64,nf)), maxiter = max_iter, verbose=verbose ) + lsqr!( tmp, F_vec, vcat(approx.y,zeros(ComplexF64,nf)), maxiter = max_iter, verbose=verbose ) approx.fc[lambda[i]] = GroupedCoeff(approx.trafo.setting, tmp) #@save string( "fc_", i, "_10noise.jld2" ) tmp end - return + return end