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
Neel Shah
NIFTy
Commits
cc38c3de
Commit
cc38c3de
authored
May 31, 2021
by
Philipp Arras
Browse files
Cosmetics
parent
938935b9
Changes
2
Show whitespace changes
Inline
Side-by-side
src/minimization/kl_energies.py
View file @
cc38c3de
...
...
@@ -12,7 +12,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2021 Max-Planck-Society
# Authors: Philipp Frank
# Authors: Philipp Frank
, Philipp Arras
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
...
...
src/operators/energy_operators.py
View file @
cc38c3de
...
...
@@ -235,14 +235,18 @@ class VariableCovarianceGaussianEnergy(LikelihoodOperator):
return
None
,
res
def
get_transformation
(
self
):
"""Note that for the metric of a `VariableCovarianceGaussianEnergy` no
global transformation to Euclidean space exists. A local approximation
invoking the residual is used instead.
"""
Note
----
For `VariableCovarianceGaussianEnergy`, a global transformation to
Euclidean space does not exist. A local approximation invoking the
residual is used instead.
"""
r
=
FieldAdapter
(
self
.
_domain
[
self
.
_kr
],
self
.
_kr
)
ivar
=
FieldAdapter
(
self
.
_domain
[
self
.
_kr
],
self
.
_ki
).
real
sc
=
1.
if
self
.
_cplx
else
0.5
return
self
.
_dt
,
r
.
adjoint
@
(
ivar
.
ptw
(
'sqrt'
)
*
r
)
+
ivar
.
adjoint
@
(
sc
*
ivar
.
ptw
(
'log'
))
f
=
r
.
adjoint
@
(
ivar
.
sqrt
()
*
r
)
+
ivar
.
adjoint
@
(
sc
*
ivar
.
log
())
return
self
.
_dt
,
f
class
_SpecialGammaEnergy
(
LikelihoodOperator
):
...
...
@@ -267,6 +271,7 @@ class _SpecialGammaEnergy(LikelihoodOperator):
sc
=
1.
if
self
.
_cplx
else
np
.
sqrt
(
0.5
)
return
self
.
_dt
,
sc
*
ScalingOperator
(
self
.
_domain
,
1.
).
ptw
(
'log'
)
class
GaussianEnergy
(
LikelihoodOperator
):
"""Computes a negative-log Gaussian.
...
...
@@ -400,7 +405,8 @@ class PoissonianEnergy(LikelihoodOperator):
return
res
.
add_metric
(
self
.
get_metric_at
(
x
.
val
))
def
get_transformation
(
self
):
return
np
.
float64
,
2.
*
ScalingOperator
(
self
.
_domain
,
1.
).
sqrt
()
return
np
.
float64
,
2.
*
ScalingOperator
(
self
.
_domain
,
1.
).
sqrt
()
class
InverseGammaLikelihood
(
LikelihoodOperator
):
"""Computes the negative log-likelihood of the inverse gamma distribution.
...
...
@@ -450,6 +456,7 @@ class InverseGammaLikelihood(LikelihoodOperator):
res
=
makeOp
(
fact
)
@
ScalingOperator
(
self
.
_domain
,
1.
).
ptw
(
'log'
)
return
self
.
_sampling_dtype
,
res
class
StudentTEnergy
(
LikelihoodOperator
):
"""Computes likelihood energy corresponding to Student's t-distribution.
...
...
@@ -487,6 +494,7 @@ class StudentTEnergy(LikelihoodOperator):
th
=
full
(
self
.
_domain
,
self
.
_theta
)
return
np
.
float64
,
makeOp
(((
th
+
1
)
/
(
th
+
3
)).
ptw
(
'sqrt'
))
class
BernoulliEnergy
(
LikelihoodOperator
):
"""Computes likelihood energy of expected event frequency constrained by
event data.
...
...
@@ -525,6 +533,7 @@ class BernoulliEnergy(LikelihoodOperator):
res
=
res
*
ScalingOperator
(
self
.
_domain
,
1
).
ptw
(
'reciprocal'
)
return
np
.
float64
,
-
2.
*
res
.
ptw
(
'sqrt'
).
ptw
(
'arctan'
)
class
StandardHamiltonian
(
EnergyOperator
):
"""Computes an information Hamiltonian in its standard form, i.e. with the
prior being a Gaussian with unit covariance.
...
...
@@ -572,7 +581,8 @@ class StandardHamiltonian(EnergyOperator):
if
not
x
.
want_metric
or
self
.
_ic_samp
is
None
:
return
(
self
.
_lh
+
self
.
_prior
)(
x
)
lhx
,
prx
=
self
.
_lh
(
x
),
self
.
_prior
(
x
)
return
(
lhx
+
prx
).
add_metric
(
SamplingEnabler
(
lhx
.
metric
,
prx
.
metric
,
self
.
_ic_samp
))
met
=
SamplingEnabler
(
lhx
.
metric
,
prx
.
metric
,
self
.
_ic_samp
)
return
(
lhx
+
prx
).
add_metric
(
met
)
def
__repr__
(
self
):
subs
=
'Likelihood:
\n
{}'
.
format
(
utilities
.
indent
(
self
.
_lh
.
__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