Commit 62815992 authored by Alessandro 's avatar Alessandro

improving juobs_linalg with new functions for computing eigenvalues and eigenvectors

parent 3c0f634e
...@@ -8,7 +8,7 @@ include("juobs_tools.jl") ...@@ -8,7 +8,7 @@ include("juobs_tools.jl")
include("juobs_obs.jl") include("juobs_obs.jl")
export read_mesons, read_ms1, read_ms, read_md export read_mesons, read_ms1, read_ms, read_md
export get_matrix, uwgevp_tot, energies, uwdot, uweigvals, uweigvecs, uweigen, invert export get_matrix, uwgevp_tot, energies, uwdot, uweigvals, uweigvecs, uweigen, invert, getall_eigvals, getall_eigvecs
export corr_obs, plat_av, lin_fit, x_lin_fit, y_lin_fit, fit_routine export corr_obs, plat_av, lin_fit, x_lin_fit, y_lin_fit, fit_routine
export meff, dec_const_pcvc, comp_t0 export meff, dec_const_pcvc, comp_t0
......
################################################################## #=using ForwardDiff, LinearAlgebra
# Alessandro Conigli wrote this script.
# It implements multiple linear algebra utilites optimised to work
# with uwreal data types.
# The major features so fare implemented are:
# - matrix matrix and vector vector multiplication
# - norm of uwreal vectors
# - copysign function for uwreal variables
# - creation of identity matrix of uwreal
# - element wise multiplication between uwreal variables and matrix of uwreal
#
#
##################################################################
using ForwardDiff, LinearAlgebra
for op in (:eigvals, :eigvecs) for op in (:eigvals, :eigvecs)
@eval function LinearAlgebra.$op(a::Matrix{uwreal}) @eval function LinearAlgebra.$op(a::Matrix{uwreal})
...@@ -22,7 +9,7 @@ for op in (:eigvals, :eigvecs) ...@@ -22,7 +9,7 @@ for op in (:eigvals, :eigvecs)
#return uwreal(LinearAlgebra.$op(a.mean), a.prop, ForwardDiff.derivative($op, a.mean)*a.der) #return uwreal(LinearAlgebra.$op(a.mean), a.prop, ForwardDiff.derivative($op, a.mean)*a.der)
end end
end end
=#
@doc raw""" @doc raw"""
get_matrix(corr_diag::Vector{Array}, corr_upper::Vector{Array} ) get_matrix(corr_diag::Vector{Array}, corr_upper::Vector{Array} )
...@@ -64,6 +51,7 @@ Julia> 4*4 Array{uwreal,2} ...@@ -64,6 +51,7 @@ Julia> 4*4 Array{uwreal,2}
``` ```
""" """
function get_matrix(corr_diag::Vector{Vector{uwreal}}, corr_upper::Vector{Vector{uwreal}}) function get_matrix(corr_diag::Vector{Vector{uwreal}}, corr_upper::Vector{Vector{uwreal}})
println("a")
time = length(corr_diag[1]) # total time slices time = length(corr_diag[1]) # total time slices
n = length(corr_diag) # matrix dimension n = length(corr_diag) # matrix dimension
d = length(corr_upper) # upper elements d = length(corr_upper) # upper elements
...@@ -184,6 +172,12 @@ Return the eigenvalues of the uwreal matrix a. ...@@ -184,6 +172,12 @@ Return the eigenvalues of the uwreal matrix a.
If evec = true also the eigenvectors are returned as columns of the orthogonal matrix u. If evec = true also the eigenvectors are returned as columns of the orthogonal matrix u.
The keyword iter, set by default to 30, selects the number of iterations of the qr algorithm before stopping. The keyword iter, set by default to 30, selects the number of iterations of the qr algorithm before stopping.
""" """
function getall_eigvals(a::Vector{Matrix}, t0; iter=30 )
n = length(a)
res = Vector{Vector{uwreal}}(undef, n)
[res[i] = uweigvals(a[i], a[t0]) for i=1:n]
return res
end
function uweigvals(a::Matrix{uwreal}; iter = 30) function uweigvals(a::Matrix{uwreal}; iter = 30)
n = size(a,1) n = size(a,1)
for k in 1:iter for k in 1:iter
...@@ -193,8 +187,7 @@ function uweigvals(a::Matrix{uwreal}; iter = 30) ...@@ -193,8 +187,7 @@ function uweigvals(a::Matrix{uwreal}; iter = 30)
return get_diag(a) return get_diag(a)
end end
function uweigvals(a::Matrix{uwreal}, b::Matrix{uwreal}; iter = 30) function uweigvals(a::Matrix{uwreal}, b::Matrix{uwreal}; iter = 30)
c = uwdot(invert(b), a) c = uwdot(invert(b),a)
n = size(c,1)
for k in 1:iter for k in 1:iter
q_k, r_k = qr(c) q_k, r_k = qr(c)
c = uwdot(r_k, q_k) c = uwdot(r_k, q_k)
...@@ -202,6 +195,13 @@ function uweigvals(a::Matrix{uwreal}, b::Matrix{uwreal}; iter = 30) ...@@ -202,6 +195,13 @@ function uweigvals(a::Matrix{uwreal}, b::Matrix{uwreal}; iter = 30)
return get_diag(c) return get_diag(c)
end end
function getall_eigvecs(a::Vector{Matrix}, delta_t; iter=30)
n = length(a)-delta_t
res = Vector{Matrix{uwreal}}(undef, n)
[res[i] = uweigvecs(a[i+delta_t], a[i]) for i=1:n]
return res
end
function uweigvecs(a::Matrix{uwreal}; iter = 30) function uweigvecs(a::Matrix{uwreal}; iter = 30)
n = size(a,1) n = size(a,1)
u = idty(n) u = idty(n)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment