Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
92a79911
Commit
92a79911
authored
Dec 09, 2019
by
Philipp Arras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formatting
parent
76130897
Pipeline
#65155
passed with stages
in 8 minutes and 31 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
36 deletions
+33
-36
nifty6/library/correlated_fields.py
nifty6/library/correlated_fields.py
+9
-11
test/test_operators/test_correlated_fields.py
test/test_operators/test_correlated_fields.py
+24
-25
No files found.
nifty6/library/correlated_fields.py
View file @
92a79911
...
...
@@ -206,8 +206,7 @@ class _Normalization(Operator):
mode_multiplicity
=
pd
.
adjoint
(
full
(
pd
.
target
,
1.
)).
val_rw
()
zero_mode
=
(
slice
(
None
),)
*
self
.
_domain
.
axes
[
space
][
0
]
+
(
0
,)
mode_multiplicity
[
zero_mode
]
=
0
self
.
_mode_multiplicity
=
makeField
(
self
.
_domain
,
mode_multiplicity
)
self
.
_mode_multiplicity
=
makeField
(
self
.
_domain
,
mode_multiplicity
)
self
.
_specsum
=
_SpecialSum
(
self
.
_domain
,
space
)
def
apply
(
self
,
x
):
...
...
@@ -299,14 +298,15 @@ class _Amplitude(Operator):
shift
=
DiagonalOperator
(
makeField
(
dom
[
space
],
foo
),
dom
,
space
)
vslope
=
DiagonalOperator
(
makeField
(
target
[
space
],
_relative_log_k_lengths
(
target
[
space
])),
makeField
(
target
[
space
],
_relative_log_k_lengths
(
target
[
space
])),
target
,
space
)
foo
,
bar
=
[
np
.
zeros
(
target
[
space
].
shape
)
for
_
in
range
(
2
)]
bar
[
1
:]
=
foo
[
0
]
=
totvol
vol0
,
vol1
=
[
DiagonalOperator
(
makeField
(
target
[
space
],
aa
),
target
,
space
)
for
aa
in
(
foo
,
bar
)]
vol0
,
vol1
=
[
DiagonalOperator
(
makeField
(
target
[
space
],
aa
),
target
,
space
)
for
aa
in
(
foo
,
bar
)
]
# Prepare fields for Adder
shift
,
vol0
=
[
op
(
full
(
op
.
domain
,
1
))
for
op
in
(
shift
,
vol0
)]
...
...
@@ -413,13 +413,11 @@ class CorrelatedFieldMaker:
self
.
_prefix
+
prefix
+
'flexibility'
,
N
)
asp
=
_LognormalMomentMatching
(
asperity_mean
,
asperity_stddev
,
self
.
_prefix
+
prefix
+
'asperity'
,
N
)
self
.
_prefix
+
prefix
+
'asperity'
,
N
)
avgsl
=
_normal
(
loglogavgslope_mean
,
loglogavgslope_stddev
,
self
.
_prefix
+
prefix
+
'loglogavgslope'
,
N
)
amp
=
_Amplitude
(
PowerSpace
(
harmonic_partner
),
fluct
,
flex
,
asp
,
avgsl
,
self
.
_azm
,
position_space
[
-
1
].
total_volume
,
amp
=
_Amplitude
(
PowerSpace
(
harmonic_partner
),
fluct
,
flex
,
asp
,
avgsl
,
self
.
_azm
,
position_space
[
-
1
].
total_volume
,
self
.
_prefix
+
prefix
+
'spectrum'
,
dofdex
)
if
index
is
not
None
:
...
...
test/test_operators/test_correlated_fields.py
View file @
92a79911
...
...
@@ -16,55 +16,56 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import
pytest
from
numpy.testing
import
assert_allclose
from
numpy.random
import
seed
from
numpy.testing
import
assert_allclose
import
nifty6
as
ift
@
pytest
.
mark
.
parametrize
(
'sspace'
,
[
ift
.
RGSpace
(
4
),
ift
.
RGSpace
((
4
,
4
),
(
0.123
,
0.4
)),
ift
.
RGSpace
((
4
,
4
),
(
0.123
,
0.4
)),
ift
.
HPSpace
(
8
),
ift
.
GLSpace
(
4
)
])
@
pytest
.
mark
.
parametrize
(
'rseed'
,
[
13
,
2
])
@
pytest
.
mark
.
parametrize
(
'Astds'
,
[[
1.
,
3.
],[
0.2
,
1.4
]])
@
pytest
.
mark
.
parametrize
(
'offset_std'
,
[
1.
,
10.
])
@
pytest
.
mark
.
parametrize
(
'Astds'
,
[[
1.
,
3.
],
[
0.2
,
1.4
]])
@
pytest
.
mark
.
parametrize
(
'offset_std'
,
[
1.
,
10.
])
def
testAmplitudesConsistency
(
rseed
,
sspace
,
Astds
,
offset_std
):
def
stats
(
op
,
samples
):
def
stats
(
op
,
samples
):
sc
=
ift
.
StatCalculator
()
for
s
in
samples
:
sc
.
add
(
op
(
s
.
extract
(
op
.
domain
)))
return
sc
.
mean
.
val
,
sc
.
var
.
sqrt
().
val
seed
(
rseed
)
nsam
=
100
fsspace
=
ift
.
RGSpace
((
12
,),
(
0.4
,))
fa
=
ift
.
CorrelatedFieldMaker
.
make
(
offset_std
,
1E-8
,
''
)
fa
.
add_fluctuations
(
sspace
,
Astds
[
0
],
1E-8
,
1.1
,
2.
,
2.1
,
.
5
,
-
2
,
1.
,
'spatial'
)
fa
.
add_fluctuations
(
fsspace
,
Astds
[
1
],
1E-8
,
3.1
,
1.
,
.
5
,
.
1
,
-
4
,
1.
,
'freq'
)
fa
.
add_fluctuations
(
sspace
,
Astds
[
0
],
1E-8
,
1.1
,
2.
,
2.1
,
.
5
,
-
2
,
1.
,
'spatial'
)
fa
.
add_fluctuations
(
fsspace
,
Astds
[
1
],
1E-8
,
3.1
,
1.
,
.
5
,
.
1
,
-
4
,
1.
,
'freq'
)
op
=
fa
.
finalize
()
samples
=
[
ift
.
from_random
(
'normal'
,
op
.
domain
)
for
_
in
range
(
nsam
)]
tot_flm
,
_
=
stats
(
fa
.
total_fluctuation
,
samples
)
offset_std
,
_
=
stats
(
fa
.
amplitude_total_offset
,
samples
)
intergated_fluct_std0
,
_
=
stats
(
fa
.
average_fluctuation
(
0
),
samples
)
intergated_fluct_std1
,
_
=
stats
(
fa
.
average_fluctuation
(
1
),
samples
)
samples
=
[
ift
.
from_random
(
'normal'
,
op
.
domain
)
for
_
in
range
(
nsam
)]
tot_flm
,
_
=
stats
(
fa
.
total_fluctuation
,
samples
)
offset_std
,
_
=
stats
(
fa
.
amplitude_total_offset
,
samples
)
intergated_fluct_std0
,
_
=
stats
(
fa
.
average_fluctuation
(
0
),
samples
)
intergated_fluct_std1
,
_
=
stats
(
fa
.
average_fluctuation
(
1
),
samples
)
slice_fluct_std0
,
_
=
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
slice_fluct_std1
,
_
=
stats
(
fa
.
slice_fluctuation
(
1
),
samples
)
slice_fluct_std0
,
_
=
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
slice_fluct_std1
,
_
=
stats
(
fa
.
slice_fluctuation
(
1
),
samples
)
sams
=
[
op
(
s
)
for
s
in
samples
]
fluct_total
=
fa
.
total_fluctuation_realized
(
sams
)
fluct_space
=
fa
.
average_fluctuation_realized
(
sams
,
0
)
fluct_freq
=
fa
.
average_fluctuation_realized
(
sams
,
1
)
fluct_space
=
fa
.
average_fluctuation_realized
(
sams
,
0
)
fluct_freq
=
fa
.
average_fluctuation_realized
(
sams
,
1
)
zm_std_mean
=
fa
.
offset_amplitude_realized
(
sams
)
sl_fluct_space
=
fa
.
slice_fluctuation_realized
(
sams
,
0
)
sl_fluct_freq
=
fa
.
slice_fluctuation_realized
(
sams
,
1
)
sl_fluct_space
=
fa
.
slice_fluctuation_realized
(
sams
,
0
)
sl_fluct_freq
=
fa
.
slice_fluctuation_realized
(
sams
,
1
)
assert_allclose
(
offset_std
,
zm_std_mean
,
rtol
=
0.5
)
assert_allclose
(
intergated_fluct_std0
,
fluct_space
,
rtol
=
0.5
)
...
...
@@ -74,14 +75,12 @@ def testAmplitudesConsistency(rseed, sspace, Astds, offset_std):
assert_allclose
(
slice_fluct_std1
,
sl_fluct_freq
,
rtol
=
0.5
)
fa
=
ift
.
CorrelatedFieldMaker
.
make
(
offset_std
,
.
1
,
''
)
fa
.
add_fluctuations
(
fsspace
,
Astds
[
1
],
1.
,
3.1
,
1.
,
.
5
,
.
1
,
-
4
,
1.
,
'freq'
)
fa
.
add_fluctuations
(
fsspace
,
Astds
[
1
],
1.
,
3.1
,
1.
,
.
5
,
.
1
,
-
4
,
1.
,
'freq'
)
m
=
3.
x
=
fa
.
moment_slice_to_average
(
m
)
fa
.
add_fluctuations
(
sspace
,
x
,
1.5
,
1.1
,
2.
,
2.1
,
.
5
,
-
2
,
1.
,
'spatial'
,
0
)
fa
.
add_fluctuations
(
sspace
,
x
,
1.5
,
1.1
,
2.
,
2.1
,
.
5
,
-
2
,
1.
,
'spatial'
,
0
)
op
=
fa
.
finalize
()
em
,
estd
=
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
em
,
estd
=
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
assert_allclose
(
m
,
em
,
rtol
=
0.5
)
...
...
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