Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
juobs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Javier Ugarrio
juobs
Commits
5f3ab2cc
Commit
5f3ab2cc
authored
Dec 29, 2025
by
Antonino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverted Gamma method to accept only Vector
parent
30cb3eb7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
171 additions
and
171 deletions
+171
-171
src/juobs_gammaMethod.jl
src/juobs_gammaMethod.jl
+171
-171
No files found.
src/juobs_gammaMethod.jl
View file @
5f3ab2cc
...
...
@@ -14,9 +14,9 @@ by an newer version of ADerrors should be deprecrated.
- chiexp(chisq::Function,par,d,C,W)
"""
module
GammaMethod
import
ADerrors
,
ForwardDiff
,
LinearAlgebra
import
ADerrors
,
ForwardDiff
,
LinearAlgebra
"""
"""
calc_gamma(a1::ADerrors.uwreal [,a2::Aderrors.uwreal] ,id::Union{Int64,String}[, ws::ADerrors.wspace])
Computes the Gamma function associated to the ensemble `id` without the bias included by ADerrors for t>=0
...
...
@@ -90,16 +90,16 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
gamma
[
ig
]
=
gamma
[
ig
]
/
(
nd_eff
-
nrcnt
*
(
ig
-
1
))
end
return
gamma
end
calc_gamma
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
)
=
calc_gamma
(
a1
,
a2
,
ws
.
str2id
[
id
],
ws
)
calc_gamma
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
)
=
calc_gamma
(
a1
,
a2
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
)
calc_gamma
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
Int64
)
=
calc_gamma
(
a1
,
a2
,
id
,
ADerrors
.
wsg
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
,
ws
::
ADerrors
.
wspace
)
=
calc_gamma
(
a
,
a
,
id
,
ws
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
)
=
calc_gamma
(
a
,
a
,
ws
.
str2id
[
id
],
ws
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
String
)
=
calc_gamma
(
a
,
a
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
)
=
calc_gamma
(
a
,
a
,
id
,
ADerrors
.
wsg
)
function
drho
(
rho
::
Vector
{
Float64
},
nd
::
Int64
,
iw
::
Int64
=
0
)
end
calc_gamma
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
)
=
calc_gamma
(
a1
,
a2
,
ws
.
str2id
[
id
],
ws
)
calc_gamma
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
)
=
calc_gamma
(
a1
,
a2
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
)
calc_gamma
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
Int64
)
=
calc_gamma
(
a1
,
a2
,
id
,
ADerrors
.
wsg
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
,
ws
::
ADerrors
.
wspace
)
=
calc_gamma
(
a
,
a
,
id
,
ws
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
)
=
calc_gamma
(
a
,
a
,
ws
.
str2id
[
id
],
ws
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
String
)
=
calc_gamma
(
a
,
a
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
)
calc_gamma
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
)
=
calc_gamma
(
a
,
a
,
id
,
ADerrors
.
wsg
)
function
drho
(
rho
::
Vector
{
Float64
},
nd
::
Int64
,
iw
::
Int64
=
0
)
iw
=
iw
==
0
?
ADerrors
.
wopt_ulli
(
nd
,
ADerrors
.
DEFAULT_STAU
,
rho
)
:
iw
nt
=
length
(
rho
);
dr
=
zeros
(
nt
);
...
...
@@ -122,9 +122,9 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
dr
[
t
]
=
sqrt
(
dr
[
t
]
/
nd
)
end
return
dr
end
end
"""
"""
bias(a1::ADerrors.uwreal [,a2::ADerrors.uwreal], id::Union{Int64,String} [, ws::Aderrors.wspace]; iw::Int64=0)
it return the bias associated to `id` that ADErrors includes in the estimate of the autocorrelation function
...
...
@@ -138,7 +138,7 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
if `iw = 0` the integration window is determined by the automatic windowing procedure with S_τ = 4.0
"""
function
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
Int64
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
function
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
Int64
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
idx
=
ws
.
map_ids
[
id
]
nd
=
ws
.
fluc
[
idx
]
.
nd
if
nd
==
1
...
...
@@ -146,13 +146,13 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
end
gamma
=
calc_gamma
(
a1
,
a2
,
id
,
ws
)
return
gamma
[
1
]
+
2.0
*
sum
(
gamma
[
2
:
iw
])
end
end
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
=
bias
(
a1
,
a2
,
ws
.
str2id
[
id
],
ws
,
iw
=
iw
)
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
Int64
;
iw
::
Int64
=
0
)
=
bias
(
a1
,
a2
,
id
,
wsg
,
iw
=
iw
)
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
;
iw
::
Int64
=
0
)
=
bias
(
a1
,
a2
,
ADerrors
.
wsg
.
str2id
[
id
],
wsg
,
iw
=
iw
)
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
=
bias
(
a1
,
a2
,
ws
.
str2id
[
id
],
ws
,
iw
=
iw
)
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
Int64
;
iw
::
Int64
=
0
)
=
bias
(
a1
,
a2
,
id
,
wsg
,
iw
=
iw
)
bias
(
a1
::
ADerrors
.
uwreal
,
a2
::
ADerrors
.
uwreal
,
id
::
String
;
iw
::
Int64
=
0
)
=
bias
(
a1
,
a2
,
ADerrors
.
wsg
.
str2id
[
id
],
wsg
,
iw
=
iw
)
function
bias
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
function
bias
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
idx
=
ws
.
map_ids
[
id
]
nd
=
ws
.
fluc
[
idx
]
.
nd
if
nd
==
1
...
...
@@ -161,13 +161,13 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
gamma
=
calc_gamma
(
a
,
id
,
ws
)
iw
=
iw
==
0
?
ADerrors
.
wopt_ulli
(
nd
,
ADerrors
.
DEFAULT_STAU
,
gamma
)
:
iw
return
gamma
[
1
]
+
2.0
*
sum
(
gamma
[
2
:
iw
])
end
end
bias
(
a
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
=
bias
(
a
,
ws
.
str2id
[
id
],
ws
,
iw
=
iw
)
bias
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
;
iw
::
Int64
=
0
)
=
bias
(
a
,
id
,
ADerrors
.
wsg
,
iw
=
iw
)
bias
(
a
::
ADerrors
.
uwreal
,
id
::
String
;
iw
::
Int64
=
0
)
=
bias
(
a
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
,
iw
=
iw
)
bias
(
a
::
ADerrors
.
uwreal
,
id
::
String
,
ws
::
ADerrors
.
wspace
;
iw
::
Int64
=
0
)
=
bias
(
a
,
ws
.
str2id
[
id
],
ws
,
iw
=
iw
)
bias
(
a
::
ADerrors
.
uwreal
,
id
::
Int64
;
iw
::
Int64
=
0
)
=
bias
(
a
,
id
,
ADerrors
.
wsg
,
iw
=
iw
)
bias
(
a
::
ADerrors
.
uwreal
,
id
::
String
;
iw
::
Int64
=
0
)
=
bias
(
a
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
,
iw
=
iw
)
function
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
Int64
,
ws
::
ADerrors
.
wspace
;)
function
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
Int64
,
ws
::
ADerrors
.
wspace
;)
b
=
zeros
(
length
(
vobs
),
length
(
vobs
))
iw
=
maximum
([
ADerrors
.
window
(
obs
,
id
)
for
obs
in
vobs
])
for
i
in
1
:
length
(
vobs
)
-
1
,
j
in
i
+
1
:
length
(
vobs
)
...
...
@@ -178,14 +178,14 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
b
[
i
,
i
]
=
bias
(
vobs
[
i
],
id
,
ws
,
iw
=
0
)
end
return
b
end
end
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
String
,
ws
::
ADerrors
.
wspace
)
=
bias
(
vobs
,
ws
.
str2id
[
id
],
ws
)
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
Int64
)
=
bias
(
vobs
,
id
,
ADerrors
.
wsg
)
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
String
)
=
bias
(
vobs
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
)
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
String
,
ws
::
ADerrors
.
wspace
)
=
bias
(
vobs
,
ws
.
str2id
[
id
],
ws
)
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
Int64
)
=
bias
(
vobs
,
id
,
ADerrors
.
wsg
)
bias
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
id
::
String
)
=
bias
(
vobs
,
ADerrors
.
wsg
.
str2id
[
id
],
ADerrors
.
wsg
)
@doc
raw
"""
@doc
raw
"""
cov_pe(vobs::Vectir{ADerrors.uwreal}[,ws:ADerrors.wspace])
Computes the unbiased covariance matrix of `vobs` à la `pyerrors`.
...
...
@@ -201,7 +201,7 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
See also [`cov_min`](@ref) [`cov_ad`](@ref)
"""
function
cov_pe
(
vobs
::
Abstract
Vector
{
ADerrors
.
uwreal
},
ws
::
ADerrors
.
wspace
)
function
cov_pe
(
vobs
::
Vector
{
ADerrors
.
uwreal
},
ws
::
ADerrors
.
wspace
)
ids
=
ADerrors
.
unique_ids_multi
(
vobs
,
ws
)
nid
=
length
(
ids
)
nobs
=
length
(
vobs
)
...
...
@@ -222,12 +222,12 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
corr
=
[
cov
[
i
,
j
]
/
sqrt
(
cov
[
i
,
i
]
*
cov
[
j
,
j
])
for
i
in
1
:
nobs
,
j
in
1
:
nobs
]
cov
=
[
corr
[
i
,
j
]
*
vobs
[
i
]
.
err
*
vobs
[
j
]
.
err
for
i
in
1
:
nobs
,
j
in
1
:
nobs
]
return
cov
end
end
cov_pe
(
vobs
::
AbstractVector
{
ADerrors
.
uwreal
})
=
cov_pe
(
vobs
,
ADerrors
.
wsg
)
cov_pe
(
vobs
::
Vector
{
ADerrors
.
uwreal
})
=
cov_pe
(
vobs
,
ADerrors
.
wsg
)
@doc
raw
"""
@doc
raw
"""
cov_min(vobs::Vector{ADerrors.uwreal} [ws::ADerrors.wspace])
It computes the unbiased covariance matrix of `vobs` using a mixed method.
...
...
@@ -242,7 +242,7 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
See
also
[
`cov_pe`
](
@ref
)
[
`cov_ad`
](
@ref
)
"""
function cov_min(vobs::Abstract
Vector{ADerrors.uwreal},ws::ADerrors.wspace)
function cov_min(vobs::
Vector{ADerrors.uwreal},ws::ADerrors.wspace)
ids = ADerrors.unique_ids_multi(vobs, ws)
nid = length(ids)
iw = fill(typemax(Int64),nid)
...
...
@@ -281,11 +281,11 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
corr = [cov[i,j]/sqrt(cov[i,i]*cov[j,j]) for i in 1:nobs, j in 1:nobs]
cov = [corr[i,j]*vobs[i].err*vobs[j].err for i in 1:nobs, j in 1:nobs]
return cov
end
end
cov_min(vobs::AbstractVector{ADerrors.uwreal}) = cov_min(vobs,ADerrors.wsg)
cov_min(vobs::Vector{ADerrors.uwreal}) = cov_min(vobs,ADerrors.wsg)
@doc raw"""
@doc raw"""
cov_AD
(
vobs
::
Vector
{
ADerrors
.
uwrela
}
[
ws
::
ADerrors
.
wspace
];
biased
::
Bool
=
true
,
info
::
Bool
=
false
)
It
computes
the
unbiased
covariance
matrix
of
`vobs`
"à la ADerrors"
.
...
...
@@ -302,7 +302,7 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
-
`info::Bool`
:
if
`true`
return
the
integration
window
used
to
compute
the
covariance
matrix
as
a
Dict
{
Int64
,
Int64
}(
id
=>
iw
)
See
also
[
`cov_min`
](
@ref
)
[
`cov_pe`
](
@ref
)
"""
function cov_AD(vobs::Abstract
Vector{ADerrors.uwreal},ws::ADerrors.wspace; biased::Bool=true, info::Bool=false)
function cov_AD(vobs::
Vector{ADerrors.uwreal},ws::ADerrors.wspace; biased::Bool=true, info::Bool=false)
ids = ADerrors.unique_ids_multi(vobs, ws)
nid = length(ids)
iw = zeros(Int64,nid)
...
...
@@ -346,17 +346,17 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
cov[n2,n1] = cov[n1,n2]
end
return info ? (cov, Dict(ids.=>iw)) : cov
end
end
cov_AD(vobs::AbstractVector{ADerrors.uwreal};biased::Bool=false) = cov_AD(vobs,ADerrors.wsg,biased=biased)
cov_AD(vobs::Vector{ADerrors.uwreal};biased::Bool=false) = cov_AD(vobs,ADerrors.wsg,biased=biased)
"""
"""
chiexp
(
hess
,
C
,
W
)
It
computes
the
expected
chisquare
given
the
hessian
of
the
chisquare
function
computed
at
its
minimum
,
the
covariance
matrix
of
data
and
the
weigth
function
.
"""
function chiexp(hess,C,W)
function chiexp(hess,C,W)
N, = size(hess)
ndata, = size(C)
npar = N-ndata;
...
...
@@ -373,15 +373,15 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
sum(aux[alpha,alpha] for alpha in 1:ndata )
end
return chiexp
end
"""
end
"""
chiexp
(
chisq
::
Function
,
par
,
d
,
C
,
W
)
It
computes
the
expected
chisquare
given
the
chisquare
function
,
the
fit
parameters
and
the
data
.
This
is
preferred
to
ADerrors
.
chiexp
for
correlated
fits
since
it
accepts
the
covariance
matrix
as
an
input
,
that
usually
has
been
already
computed
before
hand
.
"""
function chiexp(chisq::Function,par::AbstractVector{Float64},d::Abstract
Vector{Float64},C::AbstractMatrix{Float64},W::AbstractMatrix{Float64})
function chiexp(chisq::Function,par::Vector{Float64},d::
Vector{Float64},C::AbstractMatrix{Float64},W::AbstractMatrix{Float64})
ndata = length(d);
if size(W) != (ndata,ndata)
throw(DimensionMismatch("
[
chiexp
]
d
and
W
must
have
same
dimension
"))
...
...
@@ -391,9 +391,9 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
ccsq(x) = chisq(view(x,1:npar),view(x,npar+1:npar+ndata))
ForwardDiff.hessian!(hess,ccsq,[par; d])
return chiexp(hess,C,W)
end
end
function chiexp(chisq::Function,par::AbstractVector,d::AbstractVector{Float64},C::AbstractMatrix{Float64},W::Abstract
Vector{Float64})
function chiexp(chisq::Function,par::Vector,d::Vector{Float64},C::AbstractMatrix{Float64},W::
Vector{Float64})
ndata = length(d);
if length(W) != ndata
throw(DimensionMismatch("
[
chiexp
]
d
and
W
must
have
same
dimension
"))
...
...
@@ -403,7 +403,7 @@ function calc_gamma(a1::ADerrors.uwreal,a2::ADerrors.uwreal,id::Int64,ws::ADerro
ccsq(x) = chisq(view(x,1:npar),view(x,npar+1:npar+ndata))
ForwardDiff.hessian!(hess,ccsq,[par; d])
return chiexp(hess,C,LinearAlgebra.Diagonal(W))
end
end
chiexp(chisq::Function,par::AbstractVector{ADerrors.uwreal},d::Abstract
Vector{ADerrors.uwreal},C,W) = chiexp(chisq,ADerrors.value.(par),ADerrors.value.(d),C,W)
chiexp(chisq::Function,par::Vector{ADerrors.uwreal},d::
Vector{ADerrors.uwreal},C,W) = chiexp(chisq,ADerrors.value.(par),ADerrors.value.(d),C,W)
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment