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
245e8528
Commit
245e8528
authored
5 years ago
by
Reimar Leike
Browse files
Options
Downloads
Patches
Plain Diff
Test Fisher matrix using definition
parent
ccbf5012
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!543
Nifty627
,
!539
Fix complex samples
,
!537
WIP: Test Fisher matrix using definition
Pipeline
#76502
failed
5 years ago
Stage: build_docker
Stage: test
Stage: demo_runs
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_operators/test_fisher_metric.py
+77
-0
77 additions, 0 deletions
test/test_operators/test_fisher_metric.py
with
77 additions
and
0 deletions
test/test_operators/test_fisher_metric.py
0 → 100644
+
77
−
0
View file @
245e8528
# 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) 2013-2020 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import
numpy
as
np
import
pytest
import
nifty6
as
ift
from
..common
import
list2fixture
,
setup_function
,
teardown_function
spaces
=
[
ift
.
GLSpace
(
5
),
ift
.
MultiDomain
.
make
({
''
:
ift
.
RGSpace
(
5
,
distances
=
.
789
)}),
(
ift
.
RGSpace
(
3
,
distances
=
.
789
),
ift
.
UnstructuredDomain
(
2
))]
pmp
=
pytest
.
mark
.
parametrize
field
=
list2fixture
([
ift
.
from_random
(
sp
,
'
normal
'
)
for
sp
in
spaces
]
+
[
ift
.
from_random
(
sp
,
'
normal
'
,
dtype
=
np
.
complex128
)
for
sp
in
spaces
])
Nsamp
=
1000
def
_to_array
(
d
):
if
isinstance
(
d
,
np
.
ndarray
):
return
d
assert
isinstance
(
d
,
dict
)
return
np
.
concatenate
(
list
(
d
.
values
()))
def
energy_tester
(
pos
,
get_noisy_data
,
energy_initializer
):
domain
=
pos
.
domain
test_vec
=
ift
.
from_random
(
domain
,
'
normal
'
)
results
=
[]
lin
=
ift
.
Linearization
.
make_var
(
pos
)
for
i
in
range
(
Nsamp
):
data
=
get_noisy_data
(
pos
)
energy
=
energy_initializer
(
data
)
grad
=
energy
(
lin
).
jac
.
adjoint
(
ift
.
full
(
energy
.
target
,
1.
))
results
.
append
(
_to_array
((
grad
*
grad
.
s_vdot
(
test_vec
)).
val
))
res
=
np
.
mean
(
np
.
array
(
results
),
axis
=
0
)
std
=
np
.
std
(
np
.
array
(
results
),
axis
=
0
)
/
np
.
sqrt
(
Nsamp
)
energy
=
energy_initializer
(
data
)
lin
=
ift
.
Linearization
.
make_var
(
pos
,
want_metric
=
True
)
res2
=
_to_array
(
energy
(
lin
).
metric
(
test_vec
).
val
)
np
.
testing
.
assert_allclose
(
res
/
std
,
res2
/
std
,
atol
=
5
)
def
test_GaussianEnergy
(
field
):
dtype
=
field
.
dtype
icov
=
ift
.
from_random
(
field
.
domain
,
'
normal
'
)
**
2
icov
=
ift
.
makeOp
(
icov
)
get_noisy_data
=
lambda
mean
:
mean
+
icov
.
draw_sample_with_dtype
(
from_inverse
=
True
,
dtype
=
dtype
)
E_init
=
lambda
mean
:
ift
.
GaussianEnergy
(
mean
=
mean
,
inverse_covariance
=
icov
)
energy_tester
(
field
,
get_noisy_data
,
E_init
)
def
test_PoissonEnergy
(
field
):
if
not
isinstance
(
field
,
ift
.
Field
):
return
if
np
.
iscomplexobj
(
field
.
val
):
return
def
get_noisy_data
(
mean
):
return
ift
.
makeField
(
mean
.
domain
,
np
.
random
.
poisson
(
mean
.
val
))
lam
=
field
**
2
# make rate positive
E_init
=
lambda
mean
:
ift
.
PoissonianEnergy
(
mean
)
energy_tester
(
lam
,
get_noisy_data
,
E_init
)
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