Commit e9fc5112 authored by Alessandro 's avatar Alessandro

fit routine now returns par and chi^2_corr

parent 46964452
...@@ -398,8 +398,10 @@ function fit_routine(model::Function, xdata::Array{<:Real}, ydata::Array{uwreal} ...@@ -398,8 +398,10 @@ function fit_routine(model::Function, xdata::Array{<:Real}, ydata::Array{uwreal}
print("\n Fit parameter: ", i, ": ") print("\n Fit parameter: ", i, ": ")
details(upar[i]) details(upar[i])
end end
chis2_corrected = (length(yval) - param) * chisq(coef(fit), ydata) / chi_exp
println("Chisq / chiexp: ", chisq(coef(fit), ydata), " / ", chi_exp, " (dof: ", length(yval) - param,")") println("Chisq / chiexp: ", chisq(coef(fit), ydata), " / ", chi_exp, " (dof: ", length(yval) - param,")")
return upar println("Chisq corrected: ", chis2_corrected)
return upar, value(chis2_corrected)
end end
function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal}, param::Int64=3; function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal}, param::Int64=3;
...@@ -454,6 +456,8 @@ function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal} ...@@ -454,6 +456,8 @@ function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal}
(upar, chi2_exp) = isnothing(wpm) ? fit_error(chisq_full_cov, sol.minimizer, data) : fit_error(chisq_full_cov, sol.minimizer, data, wpm) (upar, chi2_exp) = isnothing(wpm) ? fit_error(chisq_full_cov, sol.minimizer, data) : fit_error(chisq_full_cov, sol.minimizer, data, wpm)
println("Chisq / chiexp: ", min_fun_cov(sol.minimizer), " / ", chi2_exp, " (dof: ", length(ydata) - param,")") println("Chisq / chiexp: ", min_fun_cov(sol.minimizer), " / ", chi2_exp, " (dof: ", length(ydata) - param,")")
chis2_corrected = (length(ydata) - param) * min_fun_cov(sol.minimizer) / chi2_exp
println("Chisq corrected: ", chis2_corrected)
else else
chisq_full(p, d) = get_chi2(model, d, ddat, p, Nalpha) chisq_full(p, d) = get_chi2(model, d, ddat, p, Nalpha)
min_fun(t) = chisq_full(t, dat) min_fun(t) = chisq_full(t, dat)
...@@ -461,19 +465,20 @@ function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal} ...@@ -461,19 +465,20 @@ function fit_routine(model::Function, xdata::Array{uwreal}, ydata::Array{uwreal}
(upar, chi2_exp) = isnothing(wpm) ? fit_error(chisq_full, sol.minimizer, data) : fit_error(chisq_full, sol.minimizer, data, wpm) (upar, chi2_exp) = isnothing(wpm) ? fit_error(chisq_full, sol.minimizer, data) : fit_error(chisq_full, sol.minimizer, data, wpm)
println("Chisq / chiexp: ", min_fun(sol.minimizer), " / ", chi2_exp, " (dof: ", length(ydata) - param,")") println("Chisq / chiexp: ", min_fun(sol.minimizer), " / ", chi2_exp, " (dof: ", length(ydata) - param,")")
chis2_corrected = (length(ydata) - param) * min_fun(sol.minimizer) / chi2_exp
println("Chisq corrected: ", chis2_corrected)
end end
#### chisq_full, min_fun out of conditional -> #### chisq_full, min_fun out of conditional ->
#### COMPILER WARNING ** incremental compilation may be fatally broken for this module ** #### COMPILER WARNING ** incremental compilation may be fatally broken for this module **
# Info # Info
for i = 1:length(upar) #for i = 1:length(upar)
isnothing(wpm) ? uwerr(upar[i]) : uwerr(upar[i], wpm) # isnothing(wpm) ? uwerr(upar[i]) : uwerr(upar[i], wpm)
print("\n Fit parameter: ", i, ": ") # print("\n Fit parameter: ", i, ": ")
details(upar[i]) # details(upar[i])
end #end
return upar return upar, chis2_corrected
end end
......
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