Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NIFTy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ift
NIFTy
Commits
d6e82f87
There was a problem fetching the pipeline summary.
Commit
d6e82f87
authored
7 years ago
by
Martin Reinecke
Browse files
Options
Downloads
Patches
Plain Diff
streamlining
parent
86a89ed1
No related branches found
No related tags found
1 merge request
!237
Replace InverseOperator and AdjointOperator with OperatorAdapter, and more
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nifty4/minimization/scipy_minimizer.py
+21
-16
21 additions, 16 deletions
nifty4/minimization/scipy_minimizer.py
with
21 additions
and
16 deletions
nifty4/minimization/scipy_minimizer.py
+
21
−
16
View file @
d6e82f87
...
...
@@ -24,14 +24,26 @@ from ..logger import logger
from
.iteration_controller
import
IterationController
def
_toNdarray
(
fld
):
return
fld
.
to_global_data
().
reshape
(
-
1
)
def
_toFlatNdarray
(
fld
):
return
fld
.
val
.
flatten
()
def
_toField
(
arr
,
dom
):
return
Field
.
from_global_data
(
dom
,
arr
.
reshape
(
dom
.
shape
))
class
_MinHelper
(
object
):
def
__init__
(
self
,
energy
):
self
.
_energy
=
energy
self
.
_domain
=
energy
.
position
.
domain
def
_update
(
self
,
x
):
pos
=
Field
(
self
.
_domain
,
x
.
reshape
(
self
.
_domain
.
shape
)
)
if
(
pos
.
val
!=
self
.
_energy
.
position
.
val
).
any
():
pos
=
_to
Field
(
x
,
self
.
_domain
)
if
(
pos
!=
self
.
_energy
.
position
).
any
():
self
.
_energy
=
self
.
_energy
.
at
(
pos
.
locked_copy
())
def
fun
(
self
,
x
):
...
...
@@ -40,13 +52,12 @@ class _MinHelper(object):
def
jac
(
self
,
x
):
self
.
_update
(
x
)
return
self
.
_energy
.
gradient
.
val
.
flatten
(
)
return
_toFlatNdarray
(
self
.
_energy
.
gradient
)
def
hessp
(
self
,
x
,
p
):
self
.
_update
(
x
)
vec
=
Field
(
self
.
_domain
,
p
.
reshape
(
self
.
_domain
.
shape
))
res
=
self
.
_energy
.
curvature
(
vec
)
return
res
.
val
.
flatten
()
res
=
self
.
_energy
.
curvature
(
_toField
(
p
,
self
.
_domain
))
return
_toFlatNdarray
(
res
)
class
ScipyMinimizer
(
Minimizer
):
...
...
@@ -129,22 +140,16 @@ class ScipyCG(Minimizer):
if
not
isinstance
(
energy
,
QuadraticEnergy
):
raise
ValueError
(
"
need a quadratic energy for CG
"
)
def
toNdarray
(
fld
):
return
fld
.
to_global_data
().
reshape
(
-
1
)
def
toField
(
arr
,
dom
):
return
Field
.
from_global_data
(
dom
,
arr
.
reshape
(
dom
.
shape
))
class
mymatvec
(
object
):
def
__init__
(
self
,
op
):
self
.
_op
=
op
def
__call__
(
self
,
inp
):
return
toNdarray
(
self
.
_op
(
toField
(
inp
,
self
.
_op
.
domain
)))
return
_
toNdarray
(
self
.
_op
(
_
toField
(
inp
,
self
.
_op
.
domain
)))
op
=
energy
.
_A
b
=
toNdarray
(
energy
.
_b
)
sx
=
toNdarray
(
energy
.
position
)
b
=
_
toNdarray
(
energy
.
_b
)
sx
=
_
toNdarray
(
energy
.
position
)
sci_op
=
scipy_linop
(
shape
=
(
op
.
domain
.
size
,
op
.
target
.
size
),
matvec
=
mymatvec
(
op
))
prec_op
=
None
...
...
@@ -155,4 +160,4 @@ class ScipyCG(Minimizer):
maxiter
=
self
.
_maxiter
)
stat
=
(
IterationController
.
CONVERGED
if
stat
>=
0
else
IterationController
.
ERROR
)
return
energy
.
at
(
toField
(
res
,
op
.
domain
)),
stat
return
energy
.
at
(
_
toField
(
res
,
op
.
domain
)),
stat
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
register
or
sign in
to comment