Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
FitRoutines
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
Antonino D'Anna
FitRoutines
Commits
271f9a30
Commit
271f9a30
authored
Jul 07, 2026
by
Antonino D'Annaç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added fit function with prior, plus bugfix
parent
45b758e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
4 deletions
+60
-4
src/FitRoutines.jl
src/FitRoutines.jl
+1
-0
src/fit_functions.jl
src/fit_functions.jl
+2
-4
src/fit_routine_prior.jl
src/fit_routine_prior.jl
+31
-0
test/prior.jl
test/prior.jl
+26
-0
No files found.
src/FitRoutines.jl
View file @
271f9a30
...
@@ -6,6 +6,7 @@ using ADerrors, LsqFit, LinearAlgebra, ForwardDiff
...
@@ -6,6 +6,7 @@ using ADerrors, LsqFit, LinearAlgebra, ForwardDiff
include
(
"types.jl"
)
include
(
"types.jl"
)
include
(
"pvalue.jl"
)
include
(
"pvalue.jl"
)
include
(
"fit_functions.jl"
)
include
(
"fit_functions.jl"
)
include
(
"fit_routine_prior.jl"
)
include
(
"find_fit.jl"
)
include
(
"find_fit.jl"
)
include
(
"fit_scan.jl"
)
include
(
"fit_scan.jl"
)
include
(
"utils.jl"
)
include
(
"utils.jl"
)
...
...
src/fit_functions.jl
View file @
271f9a30
...
@@ -10,7 +10,7 @@ It assumes that `x`, `data` and `W` have compatible dimensions.
...
@@ -10,7 +10,7 @@ It assumes that `x`, `data` and `W` have compatible dimensions.
"""
"""
function
get_chi
(
model
,
x
,
par
,
data
,
W
::
AbstractMatrix
)
function
get_chi
(
model
,
x
,
par
,
data
,
W
::
AbstractMatrix
)
ytrue
=
model
(
x
,
par
)
ytrue
=
model
(
x
,
par
)
return
sum
((
data
[
i
]
-
ytrue
[
i
])
*
W
[
i
,
j
]
*
(
data
[
j
]
-
model
(
x
[
j
],
par
)
)
for
i
in
axes
(
W
,
1
),
j
in
axes
(
W
,
2
))
return
sum
((
data
[
i
]
-
ytrue
[
i
])
*
W
[
i
,
j
]
*
(
data
[
j
]
-
ytrue
[
j
]
)
for
i
in
axes
(
W
,
1
),
j
in
axes
(
W
,
2
))
end
end
function
get_chi
(
model
,
x
,
par
,
data
,
W
::
AbstractVector
)
function
get_chi
(
model
,
x
,
par
,
data
,
W
::
AbstractVector
)
...
@@ -84,7 +84,7 @@ function fit_routine(model::Function,
...
@@ -84,7 +84,7 @@ function fit_routine(model::Function,
nobs
=
length
(
ydata
)
nobs
=
length
(
ydata
)
if
length
(
xdata
)
!=
nobs
if
length
(
xdata
)
!=
nobs
error
(
"xdata and ydata must be
the of
same size"
)
error
(
"xdata and ydata must be
of the
same size"
)
end
end
[
uwerr
(
y
,
wpm
)
for
y
in
ydata
]
[
uwerr
(
y
,
wpm
)
for
y
in
ydata
]
...
@@ -270,8 +270,6 @@ function fit_routine(models::AbstractArray{<:Function},
...
@@ -270,8 +270,6 @@ function fit_routine(models::AbstractArray{<:Function},
end
end
fit
=
fit_routine
(
Model
,
X
,
Y
,
npar
,
guess
=
guess
,
W
=
WW
,
C
=
CC
,
corr
=
corr
,
logfile
=
NoPrint
(),
wpm
=
wpm
)
fit
=
fit_routine
(
Model
,
X
,
Y
,
npar
,
guess
=
guess
,
W
=
WW
,
C
=
CC
,
corr
=
corr
,
logfile
=
NoPrint
(),
wpm
=
wpm
)
compute_error_for_logging
(
logfile
,
fit
.
par
)
compute_error_for_logging
(
logfile
,
fit
.
par
)
flag
=
typeof
(
xdata
)
<:
AbstractArray
{
<:
AbstractArray
{
ADerrors
.
uwreal
}}
flag
=
typeof
(
xdata
)
<:
AbstractArray
{
<:
AbstractArray
{
ADerrors
.
uwreal
}}
println
(
logfile
,
"fit_routine output:"
)
println
(
logfile
,
"fit_routine output:"
)
...
...
src/fit_routine_prior.jl
0 → 100644
View file @
271f9a30
@doc
raw
"""
y = model(x,p,prior)
"""
function
fit_routine_prior
(
model
::
Function
,
xdata
::
AbstractArray
{
<:
Real
},
ydata
::
AbstractArray
{
uwreal
},
prior
::
AbstractArray
{
uwreal
},
npar
::
Int64
;
wpm
::
Union
{
Dict
{
Int64
,
Vector
{
Float64
}},
Dict
{
String
,
Vector
{
Float64
}}}
=
Dict
{
Int64
,
Vector
{
Float64
}}(),
corr
::
Bool
=
true
,
W
::
AbstractArray
{
Float64
}
=
Vector
{
Float64
}(),
guess
::
AbstractVector
{
Float64
}
=
fill
(
0.5
,
npar
),
logfile
=
NoPrint
(),
C
::
AbstractArray
{
Float64
}
=
Matrix
{
Float64
}(
undef
,
0
,
0
))
nobs
=
length
(
ydata
)
nprior
=
length
(
prior
)
length
(
xdata
)
==
nobs
||
error
(
"xdata and ydata musth be of the same size"
)
function
F
(
i
::
Vector
,
par
)
res
=
Vector
{
Any
}(
undef
,
nobs
+
nprior
)
res
[
1
:
nobs
]
.=
model
(
xdata
,
par
[
1
:
npar
],
par
[
npar
+
1
:
npar
+
nprior
])
res
[
nobs
+
1
:
nobs
+
nprior
]
.=
par
[
npar
+
1
:
npar
+
nprior
]
return
res
end
guess
=
vcat
(
guess
,
value
.
(
prior
))
y
=
vcat
(
ydata
,
prior
)
fit
=
fit_routine
(
F
,
collect
(
eachindex
(
y
)),
y
,
length
(
guess
),
guess
=
guess
,
W
=
W
,
C
=
C
,
corr
=
corr
,
logfile
=
NoPrint
(),
wpm
=
wpm
)
return
fit
end
test/prior.jl
0 → 100644
View file @
271f9a30
using
Revise
,
ADerrors
,
FitRoutines
,
PyPlot
xdata
=
collect
(
1
:
10
)
true_model
(
x
)
=
1.0
+
3
exp
(
-
x
/
5
)
ydata
=
let
y
=
true_model
.
(
xdata
)
[
uwreal
(
randn
(
1000
)
.+
_y
,
"test"
)
for
_y
in
y
]
end
Q
=
uwreal
([
5.
,
0.1
],
"prior"
)
model
(
x
,
p
,
q
)
=
@.
p
[
1
]
+
p
[
2
]
*
exp
(
-
x
/
q
[
1
])
model
(
x
,
p
)
=
p
[
1
]
+
p
[
2
]
*
exp
(
-
x
/
p
[
3
])
fit
=
FitRoutines
.
fit_routine_prior
(
model
,
xdata
,
ydata
,[
Q
],
2
,
corr
=
true
)
let
fig
,
ax
=
subplots
(
1
)
y
,
dy
=
value
.
(
ydata
),
ADerrors
.
err
.
(
ydata
)
ax
.
errorbar
(
xdata
,
y
,
dy
,
color
=
"k"
,
marker
=
"s"
,
fillstyle
=
"none"
,
ls
=
""
)
r
=
collect
(
1
:
0.1
:
10
)
ax
.
plot
(
r
,
true_model
.
(
r
),
color
=
"r"
,
ls
=
"-"
)
y
=
[
model
(
x
,
fit
.
par
)
for
x
in
r
]
uwerr
.
(
y
)
y
,
dy
=
value
.
(
y
),
ADerrors
.
err
.
(
y
)
ax
.
fill_between
(
r
,
y
.-
dy
,
y
.+
dy
,
color
=
"g"
,
alpha
=
0.5
)
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