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
012feede
Commit
012feede
authored
Aug 06, 2018
by
Martin Reinecke
Browse files
cleanup
parent
561a434c
Changes
2
Hide whitespace changes
Inline
Side-by-side
nifty5/minimization/energy_adapter.py
View file @
012feede
...
...
@@ -17,18 +17,14 @@ class EnergyAdapter(Energy):
def
_fill_all
(
self
):
tmp
=
self
.
_op
(
Linearization
.
make_var
(
self
.
_position
))
self
.
_val
=
tmp
.
val
if
not
np
.
isscalar
(
self
.
_val
):
self
.
_val
=
self
.
_val
.
local_data
[()]
self
.
_val
=
tmp
.
val
.
local_data
[()]
self
.
_grad
=
tmp
.
gradient
self
.
_metric
=
tmp
.
metric
@
property
def
value
(
self
):
if
self
.
_val
is
None
:
self
.
_val
=
self
.
_op
(
self
.
_position
)
if
not
np
.
isscalar
(
self
.
_val
):
self
.
_val
=
self
.
_val
.
local_data
[()]
self
.
_val
=
self
.
_op
(
self
.
_position
).
local_data
[()]
return
self
.
_val
@
property
...
...
nifty5/operators/energy_operators.py
View file @
012feede
...
...
@@ -127,7 +127,7 @@ class PoissonianEnergy(EnergyOperator):
x
=
self
.
_op
(
x
)
res
=
x
.
sum
()
-
x
.
log
().
vdot
(
self
.
_d
)
if
not
isinstance
(
x
,
Linearization
):
return
res
return
Field
(
self
.
_target
,
res
)
metric
=
SandwichOperator
.
make
(
x
.
jac
,
makeOp
(
1.
/
x
.
val
))
return
res
.
add_metric
(
metric
)
...
...
@@ -145,7 +145,7 @@ class BernoulliEnergy(EnergyOperator):
x
=
self
.
_p
(
x
)
v
=
x
.
log
().
vdot
(
-
self
.
_d
)
-
(
1.
-
x
).
log
().
vdot
(
1.
-
self
.
_d
)
if
not
isinstance
(
x
,
Linearization
):
return
v
return
Field
(
self
.
_target
,
v
)
met
=
makeOp
(
1.
/
(
x
.
val
*
(
1.
-
x
.
val
)))
met
=
SandwichOperator
.
make
(
x
.
jac
,
met
)
return
v
.
add_metric
(
met
)
...
...
@@ -164,7 +164,7 @@ class Hamiltonian(EnergyOperator):
def
apply
(
self
,
x
):
if
self
.
_ic_samp
is
None
or
not
isinstance
(
x
,
Linearization
):
return
self
.
_lh
(
x
)
+
self
.
_prior
(
x
)
return
self
.
_lh
(
x
)
+
self
.
_prior
(
x
)
else
:
lhx
=
self
.
_lh
(
x
)
prx
=
self
.
_prior
(
x
)
...
...
@@ -189,5 +189,6 @@ class SampledKullbachLeiblerDivergence(EnergyOperator):
return
self
.
_h
.
domain
def
apply
(
self
,
x
):
return
(
utilities
.
my_sum
(
map
(
lambda
v
:
self
.
_h
(
x
+
v
),
self
.
_res_samples
))
*
(
1.
/
len
(
self
.
_res_samples
)))
res
=
(
utilities
.
my_sum
(
map
(
lambda
v
:
self
.
_h
(
x
+
v
),
self
.
_res_samples
))
*
(
1.
/
len
(
self
.
_res_samples
)))
return
res
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