Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
339a5bc6
Commit
339a5bc6
authored
Aug 14, 2018
by
Martin Reinecke
Browse files
Merge branch 'operator_documentation' into 'NIFTy_5'
Operator documentation See merge request ift/niftydev!86
parents
a54c890a
9ef50969
Changes
4
Hide whitespace changes
Inline
Sidebyside
Showing
4 changed files
with
79 additions
and
1 deletion
+79
1
demos/getting_started_3.py
demos/getting_started_3.py
+1
1
nifty5/operators/central_zero_padder.py
nifty5/operators/central_zero_padder.py
+43
0
nifty5/operators/exp_transform.py
nifty5/operators/exp_transform.py
+18
0
nifty5/operators/slope_operator.py
nifty5/operators/slope_operator.py
+17
0
No files found.
demos/getting_started_3.py
View file @
339a5bc6
...
...
@@ 100,7 +100,7 @@ if __name__ == '__main__':
for
_
in
range
(
N_samples
)]
KL
=
ift
.
SampledKullbachLeiblerDivergence
(
H
,
samples
)
KL
=
ift
.
EnergyAdapter
(
position
,
KL
,
ic_cg
)
KL
=
ift
.
EnergyAdapter
(
position
,
KL
,
ic_cg
,
constants
=
[
"xi"
]
)
KL
,
convergence
=
minimizer
(
KL
)
position
=
KL
.
position
...
...
nifty5/operators/central_zero_padder.py
View file @
339a5bc6
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 20132018 MaxPlanckSociety
#
# NIFTy is being developed at the MaxPlanckInstitut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
absolute_import
,
division
,
print_function
import
numpy
as
np
...
...
@@ 15,11 +33,29 @@ from .. import dobj
# MR FIXME: for even axis lengths, we probably should split the value at the
# highest frequency.
class
CentralZeroPadder
(
LinearOperator
):
"""Operator that enlarges a fields domain by adding zeros from the middle.
Parameters

domain: Domain, tuple of Domains or DomainTuple
The domain of the data that is input by "times" and output by
"adjoint_times"
new_shape: tuple
Shape of the target domain.
space: int, optional
The index of the subdomain on which the operator should act
If None, it is set to 0 if `domain` contains exactly one space.
`domain[space]` must be an RGSpace.
"""
def
__init__
(
self
,
domain
,
new_shape
,
space
=
0
):
self
.
_domain
=
DomainTuple
.
make
(
domain
)
self
.
_space
=
utilities
.
infer_space
(
self
.
_domain
,
space
)
dom
=
self
.
_domain
[
self
.
_space
]
# verify domains
if
not
isinstance
(
dom
,
RGSpace
):
raise
TypeError
(
"RGSpace required"
)
if
dom
.
harmonic
:
...
...
@@ 29,12 +65,15 @@ class CentralZeroPadder(LinearOperator):
if
any
([
a
<
b
for
a
,
b
in
zip
(
new_shape
,
dom
.
shape
)]):
raise
ValueError
(
"New shape must be larger than old shape"
)
# make target space
tgt
=
RGSpace
(
new_shape
,
dom
.
distances
)
self
.
_target
=
list
(
self
.
_domain
)
self
.
_target
[
self
.
_space
]
=
tgt
self
.
_target
=
DomainTuple
.
make
(
self
.
_target
)
self
.
_capability
=
self
.
TIMES

self
.
ADJOINT_TIMES
# define the axes along which the input field is sliced
slicer
=
[]
axes
=
self
.
_target
.
axes
[
self
.
_space
]
for
i
in
range
(
len
(
self
.
_domain
.
shape
)):
...
...
@@ 65,10 +104,14 @@ class CentralZeroPadder(LinearOperator):
x
=
dobj
.
local_data
(
x
)
if
mode
==
self
.
TIMES
:
# slice along each axis and copy the data to an
# array of zeros which has the shape of the target domain
y
=
np
.
zeros
(
dobj
.
local_shape
(
shp_out
,
curax
),
dtype
=
x
.
dtype
)
for
i
in
self
.
slicer
:
y
[
i
]
=
x
[
i
]
else
:
# slice along each axis and copy the data to an array of zeros
# which has the shape of the input domain to remove excess zeros
y
=
np
.
empty
(
dobj
.
local_shape
(
shp_out
,
curax
),
dtype
=
x
.
dtype
)
for
i
in
self
.
slicer
:
y
[
i
]
=
x
[
i
]
...
...
nifty5/operators/exp_transform.py
View file @
339a5bc6
...
...
@@ 31,6 +31,24 @@ from ..utilities import infer_space, special_add_at
class
ExpTransform
(
LinearOperator
):
"""
Transforms logspace to target.
This operator creates a logspace subject to the degrees of freedom and
and its targetdomain.
Then transforms between this logspace and its target, which lives in
normal units.
E.g: A field in loglogspace can be transformed into lognormspace,
that is the yaxis stays logarithmic, but the xaxis is transfromed.
Parameters

target : domain, tuple of domains or DomainTuple
The full output domain
dof : int
The degrees of freedom of the logdomain, i.e. the number of bins.
"""
def
__init__
(
self
,
target
,
dof
,
space
=
0
):
self
.
_target
=
DomainTuple
.
make
(
target
)
self
.
_capability
=
self
.
TIMES

self
.
ADJOINT_TIMES
...
...
nifty5/operators/slope_operator.py
View file @
339a5bc6
...
...
@@ 29,6 +29,23 @@ from .linear_operator import LinearOperator
class
SlopeOperator
(
LinearOperator
):
"""
Creates a slope on target.
This operator creates a field on a LogRGSpace, which is created
according to a slope of given entries, (mean, yintercept).
The slope mean is the powerlaw of the field in normalspace.
Parameters

domain : domain or DomainTuple, shape=(2,)
It has to be and UnstructuredDomain.
The domain of the slope mean and the yintercept mean.
target : domain or DomainTuple
The output domain has to a LogRGSpace
sigmas : np.array, shape=(2,)
The slope variance and the yintercept variance.
"""
def
__init__
(
self
,
domain
,
target
,
sigmas
):
if
not
isinstance
(
target
,
LogRGSpace
):
raise
TypeError
...
...
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