Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
empyre
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
Model registry
Operate
Environments
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
empyre
empyre
Commits
da72aa9a
Commit
da72aa9a
authored
7 years ago
by
Fengshan Zheng
Browse files
Options
Downloads
Patches
Plain Diff
Reconstruction Updated
parent
c89aaf69
No related branches found
No related tags found
1 merge request
!12
Reconstruction
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyramid/costfunction.py
+3
-3
3 additions, 3 deletions
pyramid/costfunction.py
pyramid/reconstruction.py
+18
-18
18 additions, 18 deletions
pyramid/reconstruction.py
with
21 additions
and
21 deletions
pyramid/costfunction.py
+
3
−
3
View file @
da72aa9a
...
...
@@ -3,7 +3,7 @@
# Author: J. Caron
#
"""
This module provides the :class:`~.Costfunction` class which represents a strategy to calculate
the so called `cost` of a threedimensional magnetization distribution.
"""
the so called `cost` of a three
dimensional magnetization distribution.
"""
import
logging
...
...
@@ -20,7 +20,7 @@ class Costfunction(object):
Represents a strategy for the calculation of the `cost` of a 3D magnetic distribution in
relation to two-dimensional phase maps. The `cost` is a measure for the difference of the
simulated phase maps from the magnetic distributions to the given set of phase maps and from
a prior
i
knowledge represented by a :class:`~.Regularisator` object. Furthermore this class
a prior knowledge represented by a :class:`~.Regularisator` object. Furthermore this class
provides convenient methods for the calculation of the derivative :func:`~.jac` or the product
with the Hessian matrix :func:`~.hess_dot` of the costfunction, which can be used by
optimizers. All required data should be given in a :class:`~DataSet` object.
...
...
@@ -41,7 +41,7 @@ class Costfunction(object):
Size of the input space.
Se_inv : :class:`~numpy.ndarray` (N=2), optional
Inverted covariance matrix of the measurement errors. The matrix has size `m x m` with m
being the length of the targetvector y.
being the length of the target
vector y.
"""
...
...
This diff is collapsed.
Click to expand it.
pyramid/reconstruction.py
+
18
−
18
View file @
da72aa9a
...
...
@@ -16,15 +16,15 @@ import logging
import
numpy
as
np
from
pyramid.fielddata
import
VectorData
from
pyramid.fielddata
import
VectorData
,
ScalarData
__all__
=
[
'
optimize_linear
'
,
'
optimize_nonlin
'
,
'
optimize_splitbregman
'
]
__all__
=
[
'
optimize_linear
'
,
'
optimize_linear_charge
'
,
'
optimize_nonlin
'
,
'
optimize_splitbregman
'
]
_log
=
logging
.
getLogger
(
__name__
)
def
optimize_linear
(
costfunction
,
mag_0
=
None
,
ramp_0
=
None
,
max_iter
=
None
,
verbose
=
False
):
"""
Reconstruct a three-dimensional magnetic distribution from given phase maps via the
conjugate gradient optimizaion method :func:`~.scipy.sparse.linalg.cg`.
conjugate gradient optimiza
t
ion method :func:`~.scipy.sparse.linalg.cg`.
Blazingly fast for l2-based cost functions.
Parameters
...
...
@@ -35,11 +35,11 @@ def optimize_linear(costfunction, mag_0=None, ramp_0=None, max_iter=None, verbos
mag_0: :class:`~.VectorData`
The starting magnetisation distribution used for the reconstruction. A zero vector will be
used if no VectorData object is specified.
mag
_0: :class:`~.Ramp`
ramp
_0: :class:`~.Ramp`
The starting ramp for the reconstruction. A zero vector will be
used if no Ramp object is specified.
max_iter : int, optional
The maximum number of iterations for the opimization.
The maximum number of iterations for the op
t
imization.
verbose: bool, optional
If set to True, information like a progressbar is displayed during reconstruction.
The default is False.
...
...
@@ -78,8 +78,8 @@ def optimize_linear(costfunction, mag_0=None, ramp_0=None, max_iter=None, verbos
def
optimize_linear_charge
(
costfunction
,
charge_0
=
None
,
ramp_0
=
None
,
max_iter
=
None
,
verbose
=
False
):
"""
Reconstruct a three-dimensional
magnetic
distribution from given phase maps via the
conjugate gradient optimizaion method :func:`~.scipy.sparse.linalg.cg`.
"""
Reconstruct a three-dimensional
charge
distribution from given phase maps via the
conjugate gradient optimiza
t
ion method :func:`~.scipy.sparse.linalg.cg`.
Blazingly fast for l2-based cost functions.
Parameters
...
...
@@ -87,22 +87,22 @@ def optimize_linear_charge(costfunction, charge_0=None, ramp_0=None, max_iter=No
costfunction : :class:`~.Costfunction`
A :class:`~.Costfunction` object which implements a specified forward model and
regularisator which is minimized in the optimization process.
mag
_0: :class:`~.VectorData`
charge
_0: :class:`~.VectorData`
The starting magnetisation distribution used for the reconstruction. A zero vector will be
used if no VectorData object is specified.
mag
_0: :class:`~.Ramp`
ramp
_0: :class:`~.Ramp`
The starting ramp for the reconstruction. A zero vector will be
used if no Ramp object is specified.
max_iter : int, optional
The maximum number of iterations for the opimization.
The maximum number of iterations for the op
t
imization.
verbose: bool, optional
If set to True, information like a progressbar is displayed during reconstruction.
The default is False.
Returns
-------
mag
data : :class:`~pyramid.fielddata.
Vecto
rData`
The reconstructed
magnetic
distribution as a :class:`~.
Vecto
rData` object.
elec
data : :class:`~pyramid.fielddata.
Scala
rData`
The reconstructed
charge
distribution as a :class:`~.
Scala
rData` object.
"""
import
jutil.cg
as
jcg
...
...
@@ -113,8 +113,8 @@ def optimize_linear_charge(costfunction, charge_0=None, ramp_0=None, max_iter=No
# Get starting distribution vector x_0:
x_0
=
np
.
empty
(
costfunction
.
n
)
if
charge_0
is
not
None
:
costfunction
.
fwd_model
.
mag
data
=
charge_0
x_0
[:
data_set
.
n
]
=
costfunction
.
fwd_model
.
mag
data
.
get_vector
(
mask
=
data_set
.
mask
)
costfunction
.
fwd_model
.
elec
data
=
charge_0
x_0
[:
data_set
.
n
]
=
costfunction
.
fwd_model
.
elec
data
.
get_vector
(
mask
=
data_set
.
mask
)
if
ramp_0
is
not
None
:
ramp_vec
=
ramp_0
.
param_cache
.
ravel
()
else
:
...
...
@@ -126,10 +126,10 @@ def optimize_linear_charge(costfunction, charge_0=None, ramp_0=None, max_iter=No
_log
.
info
(
'
Cost after optimization: {:.3e}
'
.
format
(
costfunction
(
x_opt
)))
# Cut ramp parameters if necessary (this also saves the final parameters in the ramp class!):
x_opt
=
costfunction
.
fwd_model
.
ramp
.
extract_ramp_params
(
x_opt
)
# Create and return fitting
Vecto
rData object:
mag
_opt
=
Vecto
rData
(
data_set
.
a
,
np
.
zeros
(
(
3
,)
+
data_set
.
dim
))
mag
_opt
.
set_vector
(
x_opt
,
data_set
.
mask
)
return
mag
_opt
# Create and return fitting
Scala
rData object:
charge
_opt
=
Scala
rData
(
data_set
.
a
,
np
.
zeros
(
data_set
.
dim
))
charge
_opt
.
set_vector
(
x_opt
,
data_set
.
mask
)
return
charge
_opt
def
optimize_nonlin
(
costfunction
,
first_guess
=
None
):
...
...
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