Commit a2f4bcfc authored by Antonino's avatar Antonino

bug fixes in fit routine

parent 5f3ab2cc
"""
plat_av(obs::Vector{uwreal}, plat::Vector{Int64}, [W::VecOrMat{Float64},] wpm::Union{Dict{Int64},Vector{Float{64}},Dict{String,Vector{Float{64}},Nothing}=nothing} )
......@@ -159,7 +158,7 @@ function fit_routine(model::Function,
[uwerr(y, wpm) for y in ydata]
if length(W) ==0
if corr
C = length(C) ==0 ? GammaMethod.cov_AD(ydata,wpm) : C
C = length(C) ==0 ? GammaMethod.cov_AD(ydata) : C
W = LinearAlgebra.pinv(C);
W = (W'+W)*0.5
else
......@@ -282,36 +281,36 @@ It returns a `NamedTuple` with names:
- `:chiexp`: chisquare expected
- `:pval`: pvalue
"""
function fit_routines(models::AbstractArray{Function},
function fit_routine(models::AbstractArray{Function},
xdata::AbstractArray{<:AbstractArray},
ydata::AbstractArray{<:AbstractArray{ADerrors.uwreal}},
npar::Int64;
W::AbstractArray = Float64[],
C::AbstractArray = Float64[],
W = Float64[],
C = Float64[],
wpm::AbstractDict = Dict{Int64,Vector{Float64}}(),
corr::Bool = true,
guess::AbstractArray = fill(0.5,npar),
logfile = nothing,
)
Nmodel = length(models)
ndata = length.(xdata)
Ntotal = sum(ndata);
if Nmodel != length(xdata) != length(ydata)
error("[juobs] Error: you need the same number of model, xdata and ydata")
end
if !(length(W) == 0 || length(W)==Nmodel)
error("[juobs] Error: You need to pass a W matrix for model or none")
if !(length(W) == 0 || length(W)==Nmodel || length(W) == Ntotal^2)
error("[juobs] Error: You need to pass a W matrix for model, for all the data or none")
end
if !(length(C) == 0 || length(C)==Nmodel)
error("[juobs] Error: You need to pass a C matrix for model or none")
if !(length(C) == 0 || length(C)==Nmodel || length(C) == Ntotal^2)
error("[juobs] Error: You need to pass a C matrix for model, for all the data or none")
end
ndata = length.(xdata)
if !all(length.(ydata).== ndata)
error("[juobs] Error: Mismatch in xdata and ydata. Make sure that the data corresponds")
end
Ntotal = sum(ndata);
X = vcat(xdata...)
Y = vcat(ydata...)
function make_matrix(M)
function make_matrix(M::Vector{<:AbstractMatrix})
aux = zeros(Ntotal,Ntotal)
ie = 0
for m in 1:Nmodel
......@@ -321,6 +320,7 @@ function fit_routines(models::AbstractArray{Function},
end
return aux
end
make_matrix(M::T where {T<:AbstractMatrix}) = M
WW = length(W)==0 ? W : make_matrix(W);
CC = length(C)==0 ? C : make_matrix(C);
......
#=
using ForwardDiff, LinearAlgebra
for op in (:eigvals, :eigvecs)
@eval function LinearAlgebra.$op(a::Matrix{uwreal})
@eval function LinearAlgebra.$op(a::Matrix{uwreal})
function fvec(x::Matrix)
return LinearAlgebra.$op(x)
end
return fvec(value.(a))
#return uwreal(LinearAlgebra.$op(a.mean), a.prop, ForwardDiff.derivative($op, a.mean)*a.der)
end
function fvec(x::Matrix)
return LinearAlgebra.$op(x)
end
return fvec(value.(a))
#return uwreal(LinearAlgebra.$op(a.mean), a.prop, ForwardDiff.derivative($op, a.mean)*a.der)
end
end
=#
......@@ -893,14 +893,9 @@ Return the square absolute value.
Previously this function returned the absolute value of `uw`, not the square absolute value.
The function was changed to make it consistent with `Base.abs2()` in Julia.
When used, a warning is printed to informe of this change future users, feel free to remove the warning
from your branch!
"""
function Base.abs2(uw::uwreal)
@warn "This function was updated by Antonino to make it consisted with the Julia version of it.
Check the documentation for info and then feel free to comment out this warning in your branch"
return uw^2
end
Base.abs2(uw::uwreal) = uw^2
"""
Base.abs(uw::uwreal)
......
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