Commit c8b1159d by Alejandro Saez

### Merge branch 'javier' into alejandro

parents 7f6a1be6 5eb61b12
 Home · juobs Documentation
Home · juobs Documentation
 ... @@ -78,4 +78,4 @@ evals = getall_eigvals(matrices, 5) #where t_0=5 ... @@ -78,4 +78,4 @@ evals = getall_eigvals(matrices, 5) #where t_0=5 Julia>source
juobs.getall_eigvecsFunction
getall_eigvecs(a::Vector{Matrix}, delta_t; iter=30 )

This function solves a GEVP problem, returning the eigenvectors, for a list of matrices.

$C(t_i)v_i = λ_i C(t_i-\delta_t) v_i$, with i=1:lenght(a)

Here delta_t is the time shift within the two matrices of the problem, and is kept fixed. It takes as input:

• a::Vector{Matrix} : a vector of matrices

• delta_t::Int64 : the fixed time shift t-t_0

• iter=30 : the number of iterations of the qr algorithm used to extract the eigenvalues

It returns:

• res = Vector{Matrix{uwreal}}

where each res[i] is a matrix with the eigenvectors as columns Examples:

mat_array = get_matrix(diag, upper_diag)                          Julia>
source
juobs.getall_eigvecsFunction
getall_eigvecs(a::Vector{Matrix}, delta_t; iter=30 )

This function solves a GEVP problem, returning the eigenvectors, for a list of matrices.

$C(t_i)v_i = λ_i C(t_i-\delta_t) v_i$, with i=1:lenght(a)

Here delta_t is the time shift within the two matrices of the problem, and is kept fixed. It takes as input:

• a::Vector{Matrix} : a vector of matrices

• delta_t::Int64 : the fixed time shift t-t_0

• iter=30 : the number of iterations of the qr algorithm used to extract the eigenvalues

It returns:

• res = Vector{Matrix{uwreal}}

where each res[i] is a matrix with the eigenvectors as columns Examples:

mat_array = get_matrix(diag, upper_diag)
evecs = getall_eigvecs(mat_array, 5)
source
evecs = getall_eigvecs(mat_array, 5)source
This diff is collapsed.
 ... @@ -24,4 +24,4 @@ truncate_data!(Y, nc) ... @@ -24,4 +24,4 @@ truncate_data!(Y, nc) dat = read_mesons([path1, path2], "G5", "G5") dat = read_mesons([path1, path2], "G5", "G5") Y = read_ms.([path1_ms, path2_ms]) Y = read_ms.([path1_ms, path2_ms]) truncate_data!(dat, [nc1, nc2]) truncate_data!(dat, [nc1, nc2]) truncate_data!(Y, [nc1, nc2])source truncate_data!(Y, [nc1, nc2])source
 Search · juobs Documentation

Search · juobs Documentation

This diff is collapsed.
 ... @@ -50,4 +50,4 @@ m2_phys = fitp[1] + fitp[2] * phi2_phys

Given a model function with a number param of parameters and an array of uwreal, this function fit ydata with the given model and print fit information The method return an array upar with the best fit parameters with their errors. The flag wpm is an optional array of Float64 of lenght 4. The first three paramenters specify the criteria to determine the summation windows:

• vp[1]: The autocorrelation function is summed up to $t = round(vp[1])$.

• vp[2]: The sumation window is determined using U. Wolff poposal with $S_\tau = wpm[2]$

• vp[3]: The autocorrelation function $\Gamma(t)$ is summed up a point where its error $\delta\Gamma(t)$ is a factor vp[3] times larger than the signal.

An additional fourth parameter vp[4], tells ADerrors to add a tail to the error with $\tau_{exp} = wpm[4]$. Negative values of wpm[1:4] are ignored and only one component of wpm[1:3] needs to be positive. If the flag covaris set to true, fit_routine takes into account covariances between x and y for each data point.

@. model(x,p) = p[1] + p[2] * exp(-(p[3]-p[1])*x)       fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal}, param::Int64=3; wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing, covar::Bool=false)

Given a model function with a number param of parameters and an array of uwreal, this function fit ydata with the given model and print fit information The method return an array upar with the best fit parameters with their errors. The flag wpm is an optional array of Float64 of lenght 4. The first three paramenters specify the criteria to determine the summation windows:

• vp[1]: The autocorrelation function is summed up to $t = round(vp[1])$.

• vp[2]: The sumation window is determined using U. Wolff poposal with $S_\tau = wpm[2]$

• vp[3]: The autocorrelation function $\Gamma(t)$ is summed up a point where its error $\delta\Gamma(t)$ is a factor vp[3] times larger than the signal.

An additional fourth parameter vp[4], tells ADerrors to add a tail to the error with $\tau_{exp} = wpm[4]$. Negative values of wpm[1:4] are ignored and only one component of wpm[1:3] needs to be positive. If the flag covaris set to true, fit_routine takes into account covariances between x and y for each data point.

@. model(x,p) = p[1] + p[2] * exp(-(p[3]-p[1])*x)
@. model2(x,p) = p[1] + p[2] * x[:, 1] + (p[3] + p[4] * x[:, 1]) * x[:, 2]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 @. model2(x,p) = p[1] + p[2] * x[:, 1] + (p[3] + p[4] * x[:, 1]) * x[:, 2]
fit_routine(model, xdata, ydata, param=3)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  fit_routine(model, xdata, ydata, param=3)
fit_routine(model, xdata, ydata, param=3, covar=true)
source fit_routine(model, xdata, ydata, param=3, covar=true)source
 ... @@ -126,7 +126,7 @@ function energies(evals::Union{Vector{Vector{uwreal}},Array{Array{uwreal}} }; wp ... @@ -126,7 +126,7 @@ function energies(evals::Union{Vector{Vector{uwreal}},Array{Array{uwreal}} }; wp ratio = evals[t][i] / evals[t+1][i] ratio = evals[t][i] / evals[t+1][i] aux_en[t] = 0.5*log(ratio * ratio) aux_en[t] = 0.5*log(ratio * ratio) end end isnothing(wpm) ? uwerr.(aux_en) : uwerr.(aux_en, wpm) isnothing(wpm) ? uwerr.(aux_en) : [uwerr(a, wpm) for a in aux_en] eff_en[i] = copy(aux_en) eff_en[i] = copy(aux_en) end end return eff_en return eff_en ... ...
This diff is collapsed.
 ... @@ -4,8 +4,8 @@ function apply_rw(data::Array{Float64}, W::Matrix{Float64}) ... @@ -4,8 +4,8 @@ function apply_rw(data::Array{Float64}, W::Matrix{Float64}) W1 = W[1, 1:nc] W1 = W[1, 1:nc] W2 = W[2, 1:nc] W2 = W[2, 1:nc] data_r = data .* W1 .* W2 / mean(W1 .* W2) data_r = data .* W1 .* W2 return data_r return (data_r, W1 .* W2) end end function apply_rw(data::Vector{<:Array{Float64}}, W::Vector{Matrix{Float64}}) function apply_rw(data::Vector{<:Array{Float64}}, W::Vector{Matrix{Float64}}) ... @@ -16,17 +16,9 @@ function apply_rw(data::Vector{<:Array{Float64}}, W::Vector{Matrix{Float64}}) ... @@ -16,17 +16,9 @@ function apply_rw(data::Vector{<:Array{Float64}}, W::Vector{Matrix{Float64}}) rw1 = [W[k][1, 1:nc[k]] for k=1:length(W)] rw1 = [W[k][1, 1:nc[k]] for k=1:length(W)] rw2 = [W[k][2, 1:nc[k]] for k=1:length(W)] rw2 = [W[k][2, 1:nc[k]] for k=1:length(W)] rw1_cat = rw1[1] rw = [rw1[k] .* rw2[k] for k=1:length(W)] rw2_cat = rw2[1] data_r = [data[k] .* rw[k] for k=1:length(data)] return (data_r, rw) for k = 2:length(W) rw1_cat = cat(rw1_cat, rw1[k], dims=1) rw2_cat = cat(rw2_cat, rw2[k], dims=1) end rw_mean = mean(rw1_cat .* rw2_cat) data_r = [data[k] .* rw1[k].* rw2[k] / rw_mean for k=1:length(data)] return data_r end end function check_corr_der(obs::Corr, derm::Vector{Corr}) function check_corr_der(obs::Corr, derm::Vector{Corr}) ... @@ -89,20 +81,30 @@ corr_pp = corr_obs.(data) ... @@ -89,20 +81,30 @@ corr_pp = corr_obs.(data) corr_pp_r = corr_obs.(data, rw=[rw1, rw2]) corr_pp_r = corr_obs.(data, rw=[rw1, rw2])   """ """ function corr_obs(cdata::CData; real::Bool=true, rw::Union{Array{Float64, 2}, Nothing}=nothing, L::Int64=1) function corr_obs(cdata::CData; real::Bool=true, rw::Union{Array{Float64, 2}, Nothing}=nothing, L::Int64=1, rw_info::Bool=false) real ? data = cdata.re_data ./ L^3 : data = cdata.im_data ./ L^3 real ? data = cdata.re_data ./ L^3 : data = cdata.im_data ./ L^3 data_r = isnothing(rw) ? data : apply_rw(data, rw) nt = size(data)[2] nt = size(data)[2] obs = Vector{uwreal}(undef, nt) [obs[x0] = uwreal(data_r[:, x0], cdata.id) for x0 = 1:nt] if isnothing(rw) obs = [uwreal(data[:, x0], cdata.id) for x0 = 1:nt] else data_r, W = apply_rw(data, rw) ow = [uwreal(data_r[:, x0], cdata.id) for x0 = 1:nt] W_obs = uwreal(W, cdata.id) obs = [ow[x0] / W_obs for x0 = 1:nt] end if rw_info && !isnothing(rw) return (Corr(obs, cdata), ow, W_obs) else return Corr(obs, cdata) return Corr(obs, cdata) end end end #function corr_obs for R != 1 #function corr_obs for R != 1 #TODO: vcfg with gaps #TODO: vcfg with gaps function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array{Float64, 2}, 1}, Nothing}=nothing, L::Int64=1) function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array{Float64, 2}, 1}, Nothing}=nothing, L::Int64=1, rw_info::Bool=false) nr = length(cdata) nr = length(cdata) id = getfield.(cdata, :id) id = getfield.(cdata, :id) vcfg = getfield.(cdata, :vcfg) vcfg = getfield.(cdata, :vcfg) ... @@ -113,17 +115,29 @@ function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array ... @@ -113,17 +115,29 @@ function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array end end real ? data = getfield.(cdata, :re_data) ./ L^3 : data = getfield.(cdata, :im_data) ./ L^3 real ? data = getfield.(cdata, :re_data) ./ L^3 : data = getfield.(cdata, :im_data) ./ L^3 data_r = isnothing(rw) ? data : apply_rw(data, rw) tmp = data_r[1] [tmp = cat(tmp, data_r[k], dims=1) for k = 2:nr] nt = size(data[1])[2] nt = size(data[1])[2] obs = Vector{uwreal}(undef, nt) [obs[x0] = uwreal(tmp[:, x0], id[1], replica) for x0 = 1:nt] if isnothing(rw) tmp = data[1] [tmp = cat(tmp, data[k], dims=1) for k = 2:nr] obs = [uwreal(tmp[:, x0], id[1], replica) for x0 = 1:nt] else data_r, W = apply_rw(data, rw) tmp = data_r[1] tmp_W = W[1] [tmp = cat(tmp, data_r[k], dims=1) for k = 2:nr] [tmp_W = cat(tmp_W, W[k], dims=1) for k = 2:nr] ow = [uwreal(tmp[:, x0], id[1], replica) for x0 = 1:nt] W_obs = uwreal(tmp_W, id[1], replica) obs = [ow[x0] / W_obs for x0 = 1:nt] end if rw_info && !isnothing(rw) return (Corr(obs, cdata), ow, W_obs) else return Corr(obs, cdata) return Corr(obs, cdata) end end end @doc raw""" @doc raw""" corr_sym(corrL::Corr, corrR::Corr, parity::Int64=1) corr_sym(corrL::Corr, corrR::Corr, parity::Int64=1) ... @@ -196,7 +210,7 @@ m_mdl, m_mds = md_sea(m, [md1, md2], ADerrors.wsg) ... @@ -196,7 +210,7 @@ m_mdl, m_mds = md_sea(m, [md1, md2], ADerrors.wsg) m_shifted = m + 2 * dml * m_mdl + dms * m_mds m_shifted = m + 2 * dml * m_mdl + dms * m_mds   """ """ function md_sea(a::uwreal, md::Vector{Matrix{Float64}}, ws::ADerrors.wspace=ADerrors.wsg) function md_sea(a::uwreal, md::Vector{Matrix{Float64}}, ow::uwreal, w::Union{uwreal, Nothing}=nothing, ws::ADerrors.wspace=ADerrors.wsg) nid = neid(a) nid = neid(a) p = findall(t-> t==1, a.prop) p = findall(t-> t==1, a.prop) ... @@ -227,23 +241,40 @@ function md_sea(a::uwreal, md::Vector{Matrix{Float64}}, ws::ADerrors.wspace=ADer ... @@ -227,23 +241,40 @@ function md_sea(a::uwreal, md::Vector{Matrix{Float64}}, ws::ADerrors.wspace=ADer md_aux = cat(md_aux, md[k][:, 1:ivrep[k]], dims=2) md_aux = cat(md_aux, md[k][:, 1:ivrep[k]], dims=2) end end fluc_obs = getfield.(ws.fluc[p], :delta) nrw = size(md_aux, 1) fluc_md = md_aux .- mean(md_aux, dims=2) uwerr(ow) uwerr(a) ow_data = ow.mean .+ mchist(ow, id) fluc_obs = mchist(a, id) if isnothing(w) der = derivative(a, ow) d1 = der * (ow * uwreal(md_aux[1, :], id, ivrep) - uwreal(ow_data .* md_aux[1, :], id, ivrep)) nrw = size(fluc_md, 1) if nrw == 1 if nrw == 1 der1 = uwreal(-fluc_md[1, :] .* fluc_obs, id, ivrep) return (d1, d1) return (der1, der1) elseif nrw == 2 elseif nrw == 2 der1 = uwreal(-fluc_md[1, :] .* fluc_obs, id, ivrep) d2 = der * (ow * uwreal(md_aux[2, :], id, ivrep) - uwreal(ow_data .* md_aux[2, :], id, ivrep)) der2 = uwreal(-fluc_md[2, :] .* fluc_obs, id, ivrep) return (d1, d2) return (der1, der2) end else else return nothing uwerr(w) der = derivative(a, ow) * w.mean w_data = w.mean .+ mchist(w, id) d1 = der * (ow * uwreal(w_data .* md_aux[1, :], id, ivrep) / w^2 - uwreal(ow_data .* md_aux[1, :], id, ivrep) / w) if nrw == 1 return (d1, d1) elseif nrw == 2 d2 = der * (ow * uwreal(w_data .* md_aux[2, :], id, ivrep) / w^2 - uwreal(ow_data .* md_aux[2, :], id, ivrep) / w) return (d1, d2) end end end return nothing end function md_sea(a::uwreal, md::Vector{Matrix{Float64}}, ow::Array{uwreal}, w::Union{uwreal, Nothing}=nothing, ws::ADerrors.wspace=ADerrors.wsg) d = [md_sea(a, md, ow_, w, ws) for ow_ in ow] return (sum(getindex.(d, 1)), sum(getindex.(d, 2))) end end @doc raw""" @doc raw""" ... @@ -277,7 +308,7 @@ derm = [[corr_pp_d1[k], corr_pp_d2[k]] for k = 1:length(pp_d1)] ... @@ -277,7 +308,7 @@ derm = [[corr_pp_d1[k], corr_pp_d2[k]] for k = 1:length(pp_d1)] m = meff(corr_pp[1], plat) m = meff(corr_pp[1], plat) m_md1, m_md2 = md_val(m, corr_pp[1], derm[1]) m_md1, m_md2 = md_val(m, corr_pp[1], derm[1]) m_shifted = m + 2 * dm1 * m_md1 + dm2 * m_md2 m_shifted = m + dm1 * m_md1 + dm2 * m_md2   """ """ function md_val(a::uwreal, obs::Corr, derm::Vector{Corr}) function md_val(a::uwreal, obs::Corr, derm::Vector{Corr}) ... @@ -293,14 +324,40 @@ function md_val(a::uwreal, obs::Corr, derm::Vector{Corr}) ... @@ -293,14 +324,40 @@ function md_val(a::uwreal, obs::Corr, derm::Vector{Corr}) end end corr = getfield(obs, :obs) corr = getfield(obs, :obs) prop = getfield.(corr, :prop) if all(count.(prop) .== 1) der = [derivative(a, corr[k]) for k = 1:length(corr)] der = [derivative(a, corr[k]) for k = 1:length(corr)] elseif all(count.(prop) .== 2) corr_der = getfield.(corr, :der) n = findall.(t-> t==1, prop) n = vcat(n'...) if all(n[:, 1] .== n[1, 1]) # find ow and w n_w = n[1, 1] n_ow = n[:, 2] else n_w = n[1, 2] n_ow = n[:, 1] end w_mean = 1 / getindex.(corr_der, n_ow)[1] #= Extra information (ow, w) ws = ADerrors.wsg ow_mean = - getindex.(corr_der, n_w) .* w_mean^2 w_data = w_mean .+ ws.fluc[n_w].delta fluc_ow = getfield.(ws.fluc[n_ow], :delta) fluc_ow = vcat(fluc_ow'...) ow_data = ow_mean .+ ws.fluc[n_ow] =# der = a.der[n_ow] * w_mean else return nothing end derm1, derm2 = derm derm1, derm2 = derm return (sum(der .* derm1.obs), sum(der .* derm2.obs)) return (sum(der .* derm1.obs), sum(der .* derm2.obs)) end end function plat_av(obs::Vector{uwreal}, plat::Vector{Int64}, wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing) function plat_av(obs::Vector{uwreal}, plat::Vector{Int64}, wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing) isnothing(wpm) ? uwerr.(obs) : uwerr.(obs, wpm) isnothing(wpm) ? uwerr.(obs) : [uwerr(obs_aux, wpm) for obs_aux in obs] w = 1 ./ err.(obs)[plat[1]:plat[2]].^2 w = 1 ./ err.(obs)[plat[1]:plat[2]].^2 av = sum(w .* obs[plat[1]:plat[2]]) / sum(w) av = sum(w .* obs[plat[1]:plat[2]]) / sum(w) return av return av ... @@ -629,7 +686,7 @@ m2_phys = fitp[1] + fitp[2] * phi2_phys ... @@ -629,7 +686,7 @@ m2_phys = fitp[1] + fitp[2] * phi2_phys   """ """ function lin_fit(x::Vector{<:Real}, y::Vector{uwreal}; wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing) function lin_fit(x::Vector{<:Real}, y::Vector{uwreal}; wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing) isnothing(wpm) ? uwerr.(y) : uwerr.(y, wpm) isnothing(wpm) ? uwerr.(y) : [uwerr(yaux, wpm) for yaux in y] par = lin_fit(x, value.(y), err.(y)) par = lin_fit(x, value.(y), err.(y)) chisq(p, d) = sum((d .- p[1] .- p[2].*x).^2 ./ err.(y) .^2) chisq(p, d) = sum((d .- p[1] .- p[2].*x).^2 ./ err.(y) .^2) (fitp, csqexp) = fit_error(chisq, par, y) (fitp, csqexp) = fit_error(chisq, par, y) ... @@ -683,7 +740,7 @@ fit_routine(model, xdata, ydata, param=3, covar=true) ... @@ -683,7 +740,7 @@ fit_routine(model, xdata, ydata, param=3, covar=true)   """ """ function fit_routine(model::Function, xdata::Array{<:Real}, ydata::Array{uwreal}, param::Int64=3; wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing) function fit_routine(model::Function, xdata::Array{<:Real}, ydata::Array{uwreal}, param::Int64=3; wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing) #isnothing(wpm) ? uwerr.(ydata) : uwerr.(ydata, wpm) isnothing(wpm) ? uwerr.(ydata) : [uwerr(yaux, wpm) for yaux in ydata] yval = value.(ydata) yval = value.(ydata) yer = err.(ydata) yer = err.(ydata) ... @@ -711,8 +768,8 @@ function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal} ... @@ -711,8 +768,8 @@ function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal} uwerr.(ydata) uwerr.(ydata) uwerr.(xdata) uwerr.(xdata) else else uwerr.(ydata, wpm) [uwerr(yaux, wpm) for yaux in ydata] uwerr.(xdata, wpm) [uwerr(xaux, wpm) for xaux in xdata] end end yval = value.(ydata) yval = value.(ydata) ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!