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
b2330148
Commit
b2330148
authored
Aug 12, 2018
by
Martin Reinecke
Browse files
more __repr__ work
parent
d68a5a82
Changes
4
Hide whitespace changes
Inline
Side-by-side
nifty5/operators/diagonal_operator.py
View file @
b2330148
...
...
@@ -157,17 +157,21 @@ class DiagonalOperator(EndomorphicOperator):
xdiag
=
1.
/
xdiag
return
self
.
_from_ldiag
((),
xdiag
)
def
draw_sample
(
self
,
from_inverse
=
False
,
dtype
=
np
.
float64
):
if
self
.
_complex
:
raise
ValueError
(
"operator not positive definite"
)
if
self
.
_diagmin
<
0.
:
raise
ValueError
(
"operator not positive definite"
)
if
self
.
_diagmin
==
0.
and
from_inverse
:
raise
ValueError
(
"operator not positive definite"
)
res
=
Field
.
from_random
(
random_type
=
"normal"
,
domain
=
self
.
_domain
,
dtype
=
dtype
)
def
process_sample
(
self
,
samp
,
from_inverse
):
if
(
self
.
_complex
or
(
self
.
_diagmin
<
0.
)
or
(
self
.
_diagmin
==
0.
and
from_inverse
)):
raise
ValueError
(
"operator not positive definite"
)
if
from_inverse
:
res
=
res
.
local_data
/
np
.
sqrt
(
self
.
_ldiag
)
res
=
samp
.
local_data
/
np
.
sqrt
(
self
.
_ldiag
)
else
:
res
=
res
.
local_data
*
np
.
sqrt
(
self
.
_ldiag
)
res
=
samp
.
local_data
*
np
.
sqrt
(
self
.
_ldiag
)
return
Field
.
from_local_data
(
self
.
_domain
,
res
)
def
draw_sample
(
self
,
from_inverse
=
False
,
dtype
=
np
.
float64
):
res
=
Field
.
from_random
(
random_type
=
"normal"
,
domain
=
self
.
_domain
,
dtype
=
dtype
)
return
self
.
process_sample
(
res
,
from_inverse
)
def
__repr__
(
self
):
subs
=
utilities
.
indent
(
self
.
_domain
.
__repr__
())
return
"DiagonalOperator:
\n
Spaces={}
\n
"
.
format
(
self
.
_spaces
)
+
subs
nifty5/operators/operator_adapter.py
View file @
b2330148
...
...
@@ -66,3 +66,9 @@ class OperatorAdapter(LinearOperator):
if
self
.
_trafo
&
self
.
INVERSE_BIT
:
return
self
.
_op
.
draw_sample
(
not
from_inverse
,
dtype
)
return
self
.
_op
.
draw_sample
(
from_inverse
,
dtype
)
def
__repr__
(
self
):
from
..utilities
import
indent
mode
=
[
"adjoint"
,
"inverse"
,
"adjoint inverse"
][
self
.
_trafo
]
res
=
"OperatorAdapter: {}
\n
"
.
format
(
mode
)
return
res
+
indent
(
self
.
_op
.
__repr__
())
nifty5/operators/sampling_enabler.py
View file @
b2330148
...
...
@@ -79,3 +79,11 @@ class SamplingEnabler(EndomorphicOperator):
def
apply
(
self
,
x
,
mode
):
return
self
.
_op
.
apply
(
x
,
mode
)
def
__repr__
(
self
):
from
..utilities
import
indent
return
"
\n
"
.
join
((
"SamplingEnabler:"
,
indent
(
"
\n
"
.
join
((
"Likelihood:"
,
self
.
_likelihood
.
__repr__
(),
"Prior:"
,
self
.
_prior
.
__repr__
())))))
nifty5/operators/sandwich_operator.py
View file @
b2330148
...
...
@@ -72,7 +72,7 @@ class SandwichOperator(EndomorphicOperator):
def
draw_sample
(
self
,
from_inverse
=
False
,
dtype
=
np
.
float64
):
# Inverse samples from general sandwiches are not possible
if
from_inverse
:
if
self
.
_bun
.
capabilit
ies
&
self
.
_bun
.
INVERSE_TIMES
:
if
self
.
_bun
.
capabilit
y
&
self
.
_bun
.
INVERSE_TIMES
:
try
:
s
=
self
.
_cheese
.
draw_sample
(
from_inverse
,
dtype
)
return
self
.
_bun
.
inverse_times
(
s
)
...
...
@@ -84,3 +84,11 @@ class SandwichOperator(EndomorphicOperator):
# Samples from general sandwiches
return
self
.
_bun
.
adjoint_times
(
self
.
_cheese
.
draw_sample
(
from_inverse
,
dtype
))
def
__repr__
(
self
):
from
..utilities
import
indent
return
"
\n
"
.
join
((
"SandwichOperator:"
,
indent
(
"
\n
"
.
join
((
"Cheese:"
,
self
.
_cheese
.
__repr__
(),
"Bun:"
,
self
.
_bun
.
__repr__
())))))
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