Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
05dde3a1
Commit
05dde3a1
authored
Nov 13, 2019
by
Philipp Frank
Browse files
fixes
parent
ab5f0017
Pipeline
#63616
passed with stages
in 8 minutes and 6 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/multi_amplitudes_consistency.py
View file @
05dde3a1
...
...
@@ -5,6 +5,11 @@ import numpy as np
def
testAmplitudesConsistency
(
seed
,
sspace
):
def
stats
(
op
,
samples
):
sc
=
ift
.
StatCalculator
()
for
s
in
samples
:
sc
.
add
(
op
(
s
.
extract
(
op
.
domain
)))
return
sc
.
mean
.
to_global_data
(),
sc
.
var
.
sqrt
().
to_global_data
()
np
.
random
.
seed
(
seed
)
offset_std
=
30
intergated_fluct_std0
=
.
003
...
...
@@ -23,13 +28,13 @@ def testAmplitudesConsistency(seed, sspace):
op
=
fa
.
finalize
(
offset_std
,
1E-8
,
''
)
samples
=
[
ift
.
from_random
(
'normal'
,
op
.
domain
)
for
_
in
range
(
nsam
)]
tot_flm
,
_
=
fa
.
stats
(
fa
.
total_fluctuation
,
samples
)
offset_std
,
_
=
fa
.
stats
(
fa
.
amplitude_total_offset
,
samples
)
intergated_fluct_std0
,
_
=
fa
.
stats
(
fa
.
average_fluctuation
(
0
),
samples
)
intergated_fluct_std1
,
_
=
fa
.
stats
(
fa
.
average_fluctuation
(
1
),
samples
)
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
,
_
=
fa
.
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
slice_fluct_std1
,
_
=
fa
.
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
)
...
...
@@ -76,7 +81,7 @@ def testAmplitudesConsistency(seed, sspace):
fa
.
add_fluctuations
(
sspace
,
x
,
1.5
,
1.1
,
2.
,
2.1
,
.
5
,
-
2
,
1.
,
'spatial'
,
0
)
op
=
fa
.
finalize
(
offset_std
,
.
1
,
''
)
em
,
estd
=
fa
.
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
em
,
estd
=
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
print
(
"Forced slice fluct. space Std: "
+
str
(
m
))
print
(
"Expected slice fluct. Std: "
+
str
(
em
))
np
.
testing
.
assert_allclose
(
m
,
em
,
rtol
=
0.5
)
...
...
nifty5/library/correlated_fields.py
View file @
05dde3a1
...
...
@@ -444,7 +444,7 @@ class CorrelatedFieldMaker:
def
offset_amplitude_realized
(
samples
):
res
=
0.
for
s
in
samples
:
res
+
=
s
.
mean
()
**
2
res
=
res
+
s
.
mean
()
**
2
return
np
.
sqrt
(
res
/
len
(
samples
))
@
staticmethod
...
...
@@ -461,9 +461,13 @@ class CorrelatedFieldMaker:
return
_total_fluctuation_realized
(
samples
)
res1
,
res2
=
0.
,
0.
for
s
in
samples
:
res1
+=
s
**
2
res2
+=
s
.
mean
(
space
)
**
2
return
np
.
sqrt
((
res1
-
res2
).
mean
()
/
len
(
samples
))
res1
=
res1
+
s
**
2
res2
=
res2
+
s
.
mean
(
space
)
**
2
res1
=
res1
/
len
(
samples
)
res2
=
res2
/
len
(
samples
)
res
=
res1
.
mean
()
-
res2
.
mean
()
return
np
.
sqrt
(
res
)
@
staticmethod
def
average_fluctuation_realized
(
samples
,
space
):
...
...
test/test_operators/test_correlated_fields.py
View file @
05dde3a1
...
...
@@ -32,6 +32,11 @@ import nifty5 as ift
@
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
):
sc
=
ift
.
StatCalculator
()
for
s
in
samples
:
sc
.
add
(
op
(
s
.
extract
(
op
.
domain
)))
return
sc
.
mean
.
to_global_data
(),
sc
.
var
.
sqrt
().
to_global_data
()
seed
(
rseed
)
nsam
=
100
...
...
@@ -45,13 +50,13 @@ def testAmplitudesConsistency(rseed, sspace, Astds, offset_std):
op
=
fa
.
finalize
(
offset_std
,
1E-8
,
''
)
samples
=
[
ift
.
from_random
(
'normal'
,
op
.
domain
)
for
_
in
range
(
nsam
)]
tot_flm
,
_
=
fa
.
stats
(
fa
.
total_fluctuation
,
samples
)
offset_std
,
_
=
fa
.
stats
(
fa
.
amplitude_total_offset
,
samples
)
intergated_fluct_std0
,
_
=
fa
.
stats
(
fa
.
average_fluctuation
(
0
),
samples
)
intergated_fluct_std1
,
_
=
fa
.
stats
(
fa
.
average_fluctuation
(
1
),
samples
)
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
,
_
=
fa
.
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
slice_fluct_std1
,
_
=
fa
.
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
)
...
...
@@ -76,7 +81,7 @@ def testAmplitudesConsistency(rseed, sspace, Astds, offset_std):
fa
.
add_fluctuations
(
sspace
,
x
,
1.5
,
1.1
,
2.
,
2.1
,
.
5
,
-
2
,
1.
,
'spatial'
,
0
)
op
=
fa
.
finalize
(
offset_std
,
.
1
,
''
)
em
,
estd
=
fa
.
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
em
,
estd
=
stats
(
fa
.
slice_fluctuation
(
0
),
samples
)
assert_allclose
(
m
,
em
,
rtol
=
0.5
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment