Commit 0bca4b09 authored by Antonino D'Anna's avatar Antonino D'Anna

small changes in get_chi and fit_routine, now xdata is typeless in get_chi and...

small changes in get_chi and fit_routine, now xdata is typeless in get_chi and AbstractVector in fit_routine
parent c7088641
...@@ -1240,11 +1240,11 @@ It computes the chi square of a fit. `model` is assumed to be of the type f(xdat ...@@ -1240,11 +1240,11 @@ It computes the chi square of a fit. `model` is assumed to be of the type f(xdat
If `W::Vector` the chisquare is computed for an uncorrelated fit If `W::Vector` the chisquare is computed for an uncorrelated fit
If `W::Matrix` the chisquare is computed for a correlated fit If `W::Matrix` the chisquare is computed for a correlated fit
""" """
function get_chi(model::Function,x::Vector,par,data,W::Array{Float64,2}) function get_chi(model::Function,x,par,data,W::Array{Float64,2})
return sum((data.-model(x,par))' * W * (data.-model(x,par))) return sum((data.-model(x,par))' * W * (data.-model(x,par)))
end end
function get_chi(model::Function,x::Vector,par,data,W::Vector{Float64}) function get_chi(model::Function,x,par,data,W::Vector{Float64})
return sum((data.-model(x,par)).^2 .* W) return sum((data.-model(x,par)).^2 .* W)
end end
...@@ -1283,12 +1283,12 @@ It returns a NamedTuple with names: ...@@ -1283,12 +1283,12 @@ It returns a NamedTuple with names:
""" """
function fit_routine(model::Function, function fit_routine(model::Function,
xdata::AbstractArray{<:Real}, xdata::AbstractArray{<:Real},
ydata::Array{uwreal}, ydata::Vector{uwreal},
npar::Int64; npar::Int64;
wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}}=Dict{Int64,Vector{Float64}}(), wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}}=Dict{Int64,Vector{Float64}}(),
corr::Bool = true, corr::Bool = true,
W::AbstractVecOrMat{Float64}=Vector{Float64}(), W::AbstractVecOrMat{Float64}=Vector{Float64}(),
guess::Vector{Float64} = fill(0.5,npar), guess::AbstractVector{Float64} = fill(0.5,npar),
logfile = nothing, logfile = nothing,
C::AbstractMatrix{Float64} = Matrix{Float64}(undef,0,0)); C::AbstractMatrix{Float64} = Matrix{Float64}(undef,0,0));
...@@ -1321,12 +1321,13 @@ function fit_routine(model::Function, ...@@ -1321,12 +1321,13 @@ function fit_routine(model::Function,
end end
if !isnothing(logfile) if !isnothing(logfile)
println(logfile, "juobs.fit_routine output:") uwerr.(par);
println(logfile, "\t\tFit routine in [$(xdata[1]),...,$(xdata[2])]") println(logfile, "juobs.fit_routine output:")
println(logfile, "\t\tparameters :", par...) println(logfile, "\t\tFit routine in [$(xdata[1]),...,$(xdata[end])]")
println(logfile, "\t\tchi2: ", chi2) println(logfile, "\t\tparameters :", par...)
println(logfile, "\t\tchiexp: ", chiexp) println(logfile, "\t\tchi2: ", chi2)
println(logfile, "\t\tpvalue: ", pval) println(logfile, "\t\tchiexp: ", chiexp)
println(logfile, "\t\tpvalue: ", pval)
end end
return (par=par,chi2=chi2,chiexp=chiexp,pval=pval) return (par=par,chi2=chi2,chiexp=chiexp,pval=pval)
......
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