Skip to content
GitLab
Menu
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
0f74839a
Commit
0f74839a
authored
Sep 11, 2016
by
theos
Browse files
Implemented DiagonalProber.
parent
4940efce
Changes
3
Hide whitespace changes
Inline
Side-by-side
nifty/probing/diagonal_prober.py
0 → 100644
View file @
0f74839a
# -*- coding: utf-8 -*-
from
nifty.operators
import
EndomorphicOperator
from
operator_prober
import
OperatorProber
class
DiagonalProber
(
OperatorProber
):
# ---Mandatory properties and methods---
# --- ->Mandatory from OperatorProber---
@
property
def
is_inverse
(
self
):
return
False
@
property
def
valid_operator_class
(
self
):
return
EndomorphicOperator
# --- ->Mandatory from Prober---
def
evaluate_probe
(
self
,
probe
):
""" processes a probe """
return
self
.
operator
.
times
(
probe
[
1
])
def
finish_probe
(
self
,
probe
,
pre_result
):
return
probe
[
1
].
conjugate
()
*
pre_result
nifty/probing/operator_prober.py
View file @
0f74839a
...
...
@@ -2,6 +2,8 @@
import
abc
from
nifty.config
import
about
from
prober
import
Prober
...
...
@@ -17,6 +19,10 @@ class OperatorProber(Prober):
distribution_strategy
=
distribution_strategy
,
compute_variance
=
compute_variance
)
if
not
isinstance
(
operator
,
self
.
valid_operator_class
):
raise
TypeError
(
about
.
_errors
.
cstring
(
"WARNING: operator must be an instance of %s"
%
str
(
self
.
valid_operator_class
)))
self
.
_operator
=
operator
# ---Mandatory properties and methods---
...
...
nifty/probing/prober.py
View file @
0f74839a
...
...
@@ -67,7 +67,7 @@ class Prober(object):
def
random_type
(
self
,
random_type
):
if
random_type
not
in
[
"pm1"
,
"normal"
]:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: unsupported random type: '"
+
str
(
random
)
+
"'."
))
"ERROR: unsupported random type: '"
+
str
(
random
_type
)
+
"'."
))
else
:
self
.
_random_type
=
random_type
...
...
@@ -81,7 +81,7 @@ class Prober(object):
for
index
in
xrange
(
self
.
probe_count
):
current_probe
=
self
.
get_probe
(
index
)
pre_result
=
self
.
process_probe
(
current_probe
,
index
)
result
=
self
.
finish_probe
(
pre_result
)
result
=
self
.
finish_probe
(
current_probe
,
pre_result
)
sum_of_probes
+=
result
if
self
.
compute_variance
:
...
...
@@ -111,8 +111,9 @@ class Prober(object):
""" processes a probe """
raise
NotImplementedError
def
finish_probe
(
self
,
probe
):
return
probe
@
abc
.
abstractmethod
def
finish_probe
(
self
,
probe
,
pre_result
):
return
pre_result
def
finalize
(
self
,
sum_of_probes
,
sum_of_squares
):
probe_count
=
self
.
probe_count
...
...
Write
Preview
Supports
Markdown
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