Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SemiSmoothNewton.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Hilb
SemiSmoothNewton.jl
Commits
fb12a137
Commit
fb12a137
authored
Sep 8, 2021
by
Stephan Hilb
Browse files
Options
Downloads
Patches
Plain Diff
finalize primal-dual comparison experiment
parent
370069e3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/run_experiments.jl
+72
-49
72 additions, 49 deletions
scripts/run_experiments.jl
scripts/util.jl
+5
-6
5 additions, 6 deletions
scripts/util.jl
with
77 additions
and
55 deletions
scripts/run_experiments.jl
+
72
−
49
View file @
fb12a137
...
@@ -410,6 +410,9 @@ function estimate!(ctx::L1L2TVContext)
...
@@ -410,6 +410,9 @@ function estimate!(ctx::L1L2TVContext)
nablau
=
nabla
(
ctx
.
u
),
w
,
nablaw
=
nabla
(
w
),
ctx
.
tdata
)
nablau
=
nabla
(
ctx
.
u
),
w
,
nablaw
=
nabla
(
w
),
ctx
.
tdata
)
end
end
estimate_error
(
st
::
L1L2TVContext
)
=
sqrt
(
sum
(
st
.
est
.
data
)
/
area
(
st
.
mesh
))
# minimal Dörfler marking
# minimal Dörfler marking
function
mark
(
ctx
::
L1L2TVContext
;
theta
=
0.5
)
function
mark
(
ctx
::
L1L2TVContext
;
theta
=
0.5
)
n
=
ncells
(
ctx
.
mesh
)
n
=
ncells
(
ctx
.
mesh
)
...
@@ -529,113 +532,132 @@ function denoise(img; name, params...)
...
@@ -529,113 +532,132 @@ function denoise(img; name, params...)
end
end
function
denoise_pd
(
ctx
,
img
;
df
=
nothing
,
name
,
algorithm
,
params_
...
)
function
denoise_pd
(
st
,
img
;
df
=
nothing
,
name
,
algorithm
,
params_
...
)
params
=
NamedTuple
(
params_
)
params
=
NamedTuple
(
params_
)
m
=
1
m
=
1
img
=
from_img
(
img
)
# coord flip
img
=
from_img
(
img
)
# coord flip
mesh
=
init_grid
(
img
;
type
=:
vertex
)
mesh
=
init_grid
(
img
)
#mesh = init_grid(img, 5, 5)
#mesh = init_grid(img, 5, 5)
T
(
tdata
,
u
)
=
u
T
(
tdata
,
u
)
=
u
S
(
u
,
nablau
)
=
u
S
(
u
,
nablau
)
=
u
ctx
=
L1L2TVContext
(
name
,
mesh
,
m
;
st
=
L1L2TVContext
(
name
,
mesh
,
m
;
T
,
tdata
=
nothing
,
S
,
T
,
tdata
=
nothing
,
S
,
params
.
alpha1
,
params
.
alpha2
,
params
.
lambda
,
params
.
beta
,
params
.
alpha1
,
params
.
alpha2
,
params
.
lambda
,
params
.
beta
,
params
.
gamma1
,
params
.
gamma2
)
params
.
gamma1
,
params
.
gamma2
)
# semi-implicit primal dual parameters
# semi-implicit primal dual parameters
gamma
=
ctx
.
alpha2
+
ctx
.
beta
# T = I, S = I
mu
=
st
.
alpha2
+
st
.
beta
# T = I, S = I
gamma
/=
100
# kind of arbitrary?
#mu
/= 100 # kind of arbitrary?
tau
=
1e-1
tau
=
1e-1
L
=
100
L
=
100
sigma
=
inv
(
tau
*
L
^
2
)
sigma
=
inv
(
tau
*
L
^
2
)
theta
=
1.
theta
=
1.
#project_img!(
ctx
.g, img)
#project_img!(
st
.g, img)
interpolate!
(
ctx
.
g
,
x
->
interpolate_bilinear
(
img
,
x
))
interpolate!
(
st
.
g
,
x
->
interpolate_bilinear
(
img
,
x
))
ctx
.
u
.
data
.=
ctx
.
g
.
data
st
.
u
.
data
.=
st
.
g
.
data
save_denoise
(
ctx
,
i
)
=
save_denoise
(
st
,
i
)
=
output
(
ctx
,
"output/
$
(
ctx
.name)_
$
(lpad(i, 5, '0')).vtu"
,
output
(
st
,
"output/
$
(
st
.name)_
$
(lpad(i, 5, '0')).vtu"
,
ctx
.
g
,
ctx
.
u
,
ctx
.
p1
,
ctx
.
p2
)
st
.
g
,
st
.
u
,
st
.
p1
,
st
.
p2
)
log!
(
x
::
Nothing
;
kwargs
...
)
=
x
log!
(
x
::
Nothing
;
kwargs
...
)
=
x
function
log!
(
df
::
DataFrame
;
k
,
norm_step
,
norm_residual
)
function
log!
(
df
::
DataFrame
;
kwargs
...
)
push!
(
df
,
(;
row
=
NamedTuple
(
kwargs
)
k
,
push!
(
df
,
row
)
primal_energy
=
primal_energy
(
ctx
),
#println(df)
norm_step
,
println
(
row
)
norm_residual
))
println
(
NamedTuple
(
last
(
df
)))
end
end
#pvd = paraview_collection("output/$(
ctx
.name).pvd")
#pvd = paraview_collection("output/$(
st
.name).pvd")
#pvd[0] = save_denoise(
ctx
, 0)
#pvd[0] = save_denoise(
st
, 0)
k
=
0
k
=
0
println
(
"primal energy:
$
(primal_energy(
ctx
))"
)
println
(
"primal energy:
$
(primal_energy(
st
))"
)
while
true
while
true
k
+=
1
k
+=
1
if
algorithm
==
:
pd1
if
algorithm
==
:
pd1
# no step size control
# no step size control
step_pd2!
(
ctx
;
sigma
,
tau
,
theta
)
step_pd2!
(
st
;
sigma
,
tau
,
theta
)
elseif
algorithm
==
:
pd2
elseif
algorithm
==
:
pd2
theta
=
1
/
sqrt
(
1
+
2
*
gamma
*
tau
)
theta
=
1
/
sqrt
(
1
+
2
*
mu
*
tau
)
tau
*=
theta
tau
*=
theta
sigma
/=
theta
sigma
/=
theta
step_pd2!
(
ctx
;
sigma
,
tau
,
theta
)
step_pd2!
(
st
;
sigma
,
tau
,
theta
)
elseif
algorithm
==
:
newton
elseif
algorithm
==
:
newton
step!
(
ctx
)
step!
(
st
)
end
end
#pvd[k] = save_denoise(
ctx
, k)
#pvd[k] = save_denoise(
st
, k)
domain_factor
=
1
/
sqrt
(
area
(
mesh
))
domain_factor
=
1
/
sqrt
(
area
(
mesh
))
norm_step_
=
norm_step
(
ctx
)
*
domain_factor
norm_step_
=
norm_step
(
st
)
*
domain_factor
norm_residual_
=
norm_residual
(
ctx
)
*
domain_factor
#estimate!(st)
log!
(
df
;
k
,
norm_step
=
norm_step_
,
norm_residual
=
norm_residual_
)
log!
(
df
;
k
,
norm_step
=
norm_step_
,
#est = estimate_error(st),
primal_energy
=
primal_energy
(
st
))
#norm_residual_ < params.tol && norm_step_ < params.tol && break
#norm_residual_ < params.tol && norm_step_ < params.tol && break
haskey
(
params
,
:
tol
)
&&
norm_step_
<
params
.
tol
&&
break
haskey
(
params
,
:
tol
)
&&
norm_step_
<
params
.
tol
&&
break
haskey
(
params
,
:
max_iters
)
&&
k
>=
params
.
max_iters
&&
break
haskey
(
params
,
:
max_iters
)
&&
k
>=
params
.
max_iters
&&
break
end
end
#pvd[1] = save_denoise(
ctx
, 1)
#pvd[1] = save_denoise(
st
, 1)
#vtk_save(pvd)
#vtk_save(pvd)
return
ctx
return
st
end
end
function
experiment_pd_comparison
(
ctx
)
function
experiment_pd_comparison
(
ctx
)
img
=
loadimg
(
joinpath
(
ctx
.
indir
,
"input.png"
))
img
=
loadimg
(
joinpath
(
ctx
.
indir
,
"input.png"
))
img
=
from_img
(
img
)
# coord flip
#
img =
[0. 0.; 1. 0.]
algparams
=
(
algparams
=
(
alpha1
=
0.
,
alpha2
=
30.
,
lambda
=
1.
,
beta
=
0.
,
alpha1
=
0.
,
alpha2
=
30.
,
lambda
=
1.
,
beta
=
0.
,
gamma1
=
1e-3
,
gamma2
=
1e-3
,
gamma1
=
1e-2
,
gamma2
=
1e-3
,
tol
=
1e-6
,
max_iters
=
50
,
tol
=
1e-10
,
max_iters
=
10000
,
)
)
df1
=
DataFrame
()
df1
=
DataFrame
()
df2
=
DataFrame
()
df2
=
DataFrame
()
df3
=
DataFrame
()
df3
=
DataFrame
()
denoise_pd
(
ctx
,
img
;
name
=
"test"
,
algorithm
=:
pd1
,
df
=
df1
,
algparams
...
);
st1
=
denoise_pd
(
ctx
,
img
;
name
=
"test"
,
denoise_pd
(
ctx
,
img
;
name
=
"test"
,
algorithm
=:
pd2
,
df
=
df2
,
algparams
...
);
algorithm
=:
pd1
,
df
=
df1
,
algparams
...
);
denoise_pd
(
ctx
,
img
;
name
=
"test"
,
algorithm
=:
newton
,
df
=
df3
,
algparams
...
);
st2
=
denoise_pd
(
ctx
,
img
;
name
=
"test"
,
algorithm
=:
pd2
,
df
=
df2
,
algparams
...
);
st3
=
denoise_pd
(
ctx
,
img
;
name
=
"test"
,
algorithm
=:
newton
,
df
=
df3
,
algparams
...
);
energy_min
=
min
(
minimum
(
df1
.
primal_energy
),
minimum
(
df2
.
primal_energy
),
energy_min
=
min
(
minimum
(
df1
.
primal_energy
),
minimum
(
df2
.
primal_energy
),
minimum
(
df3
.
primal_energy
))
minimum
(
df3
.
primal_energy
))
df1
[
!
,
:
energy_min
]
.=
energy_min
#df1.primal_energy .-= energy_min
df2
[
!
,
:
energy_min
]
.=
energy_min
#df2.primal_energy .-= energy_min
df3
[
!
,
:
energy_min
]
.=
energy_min
#df3.primal_energy .-= energy_min
CSV
.
write
(
joinpath
(
ctx
.
outdir
,
"semi-implicit.csv"
),
CSV
.
write
(
joinpath
(
ctx
.
outdir
,
"semiimplicit.csv"
),
logfilter
(
df1
))
logfilter
(
df1
))
CSV
.
write
(
joinpath
(
ctx
.
outdir
,
"semiimplicit-accelerated.csv"
),
logfilter
(
df2
))
CSV
.
write
(
joinpath
(
ctx
.
outdir
,
"semi-implicit-accelerated.csv"
),
CSV
.
write
(
joinpath
(
ctx
.
outdir
,
"newton.csv"
),
logfilter
(
df3
))
logfilter
(
df2
))
CSV
.
write
(
joinpath
(
ctx
.
outdir
,
"newton.csv"
),
logfilter
(
df3
))
saveimg
(
joinpath
(
ctx
.
outdir
,
"input.png"
),
img
)
saveimg
(
joinpath
(
ctx
.
outdir
,
"semi-implicit.png"
),
to_img
(
sample
(
st1
.
u
)))
saveimg
(
joinpath
(
ctx
.
outdir
,
"semi-implicit-accelerated.png"
),
to_img
(
sample
(
st2
.
u
)))
saveimg
(
joinpath
(
ctx
.
outdir
,
"newton.png"
),
to_img
(
sample
(
st3
.
u
)))
savedata
(
joinpath
(
ctx
.
outdir
,
"data.tex"
);
energy_min
,
algparams
...
)
end
end
function
denoise_approximation
(
ctx
)
function
denoise_approximation
(
ctx
)
...
@@ -662,7 +684,8 @@ function denoise_approximation(ctx)
...
@@ -662,7 +684,8 @@ function denoise_approximation(ctx)
function
log!
(
df
::
DataFrame
;
kwargs
...
)
function
log!
(
df
::
DataFrame
;
kwargs
...
)
row
=
NamedTuple
(
kwargs
)
row
=
NamedTuple
(
kwargs
)
push!
(
df
,
row
)
push!
(
df
,
row
)
println
(
row
)
println
(
df
)
#println(row)
end
end
pvd_path
=
joinpath
(
ctx
.
outdir
,
"
$
(ctx.params.name).pvd"
)
pvd_path
=
joinpath
(
ctx
.
outdir
,
"
$
(ctx.params.name).pvd"
)
...
@@ -716,9 +739,9 @@ function experiment_approximation(ctx)
...
@@ -716,9 +739,9 @@ function experiment_approximation(ctx)
denoise_approximation
(
Util
.
Context
(
ctx
;
name
=
"test"
,
df
,
denoise_approximation
(
Util
.
Context
(
ctx
;
name
=
"test"
,
df
,
img
,
mesh
,
img
,
mesh
,
#
alpha1 = 0., alpha2 = 30., lambda = 1., beta = 0.,
alpha1
=
0.
,
alpha2
=
30.
,
lambda
=
1.
,
beta
=
0.
,
alpha1
=
0.5
,
alpha2
=
0.
,
lambda
=
0.
,
beta
=
1.
,
#
alpha1 = 0.5, alpha2 = 0., lambda = 0., beta = 1.,
gamma1
=
1e-5
,
gamma2
=
1e-
3
,
gamma1
=
1e-5
,
gamma2
=
1e-
5
,
tol
=
1e-10
,
adaptive
=
true
,
tol
=
1e-10
,
adaptive
=
true
,
))
))
end
end
...
...
...
...
This diff is collapsed.
Click to expand it.
scripts/util.jl
+
5
−
6
View file @
fb12a137
...
@@ -44,13 +44,12 @@ end
...
@@ -44,13 +44,12 @@ end
# LaTeX Data Output
# LaTeX Data Output
# TODO: don't depend on ctx.path and use filename only
savedata
(
filename
;
data
...
)
=
savedata
(
ctx
::
Context
,
filename
;
data
...
)
=
open
(
filename
;
write
=
true
)
do
io
open
(
joinpath
(
ctx
.
outdir
,
filename
);
write
=
true
)
do
io
_savedata
(
io
;
data
...
)
_savedata
(
io
,
ctx
.
path
;
data
...
)
end
end
function
_savedata
(
io
,
path
;
data
...
)
function
_savedata
(
io
;
data
...
)
isvalidname
(
x
)
=
contains
(
string
(
x
),
r
"^[^/
\\
]+
$
"
)
isvalidname
(
x
)
=
contains
(
string
(
x
),
r
"^[^/
\\
]+
$
"
)
# define tex command to access data
# define tex command to access data
...
@@ -67,7 +66,7 @@ function _savedata(io, path; data...)
...
@@ -67,7 +66,7 @@ function _savedata(io, path; data...)
# actual data encoded as tex-commands
# actual data encoded as tex-commands
write
(
io
,
"
\\
expandafter
\\
def"
)
write
(
io
,
"
\\
expandafter
\\
def"
)
write
(
io
,
"
\\
csname
$(texcmd)
/
$(path)
/
$(key)
\\
endcsname{"
)
write
(
io
,
"
\\
csname
$(texcmd)
/
\\
DataPrefix
/
$(key)
\\
endcsname{"
)
show
(
io
,
MIME
(
"text/latex"
),
value
)
show
(
io
,
MIME
(
"text/latex"
),
value
)
write
(
io
,
"}
\n
"
)
write
(
io
,
"}
\n
"
)
end
end
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment