Commit 0cb2d984 authored by Philipp Arras's avatar Philipp Arras
Browse files

Add changelog entry

parent 8353227e
...@@ -10,9 +10,34 @@ convention is consistent with almost all other numerical FFT libraries. ...@@ -10,9 +10,34 @@ convention is consistent with almost all other numerical FFT libraries.
Interface change in EndomorphicOperator.draw_sample() Interface change in EndomorphicOperator.draw_sample()
===================================================== =====================================================
This method now requires a `dtype` argument to be passed. Both complex-valued and real-valued Gaussian probability distributions have
As a consequence, `dtype` moves to the first place of the argument list. hermitian and positive endomorphisms as covariance. Just by looking at an
(This of course applies to all derived classes as well.) endomorphic operator itself it is not clear whether it is viewed as covariance
for real or complex Gaussians when a sample of the respective distribution shall
be drawn. Therefore, we introduce the method `draw_sample_with_dtype()` which
needs to be given the data type of the probability distribution. This function
is implemented for all operators which actually draw random numbers
(`DiagonalOperator` and `ScalingOperator`). The class `SamplingDtypeSetter` acts
as a wrapper for these kind of operators in order to fix the data type of the
distribution. Samples from these operators can be drawn with `.draw_sample()`.
In order to dive into those subtleties I suggest running the following code and
playing around with the dtypes.
import nifty6 as ift
import numpy as np
dom = ift.UnstructuredDomain(5)
dtype = [np.float64, np.complex128][1]
invcov = ift.ScalingOperator(dom, 3)
e = ift.GaussianEnergy(mean=ift.from_random('normal', dom, dtype=dtype),
pos = ift.from_random('normal', dom, dtype=np.complex128)
lin = e(ift.Linearization.make_var(pos, want_metric=True))
met = lin.metric
MPI parallelisation over samples in MetricGaussianKL MPI parallelisation over samples in MetricGaussianKL
==================================================== ====================================================
...@@ -46,6 +46,10 @@ class BlockDiagonalOperator(EndomorphicOperator): ...@@ -46,6 +46,10 @@ class BlockDiagonalOperator(EndomorphicOperator):
for op, v in zip(self._ops, x.values())) for op, v in zip(self._ops, x.values()))
return MultiField(self._domain, val) return MultiField(self._domain, val)
def draw_sample(self, from_inverse=False):
val = tuple(op.draw_sample(from_inverse) for op in self._ops)
return MultiField(self._domain, val)
def draw_sample_with_dtype(self, dtype, from_inverse=False): def draw_sample_with_dtype(self, dtype, from_inverse=False):
from ..sugar import from_random from ..sugar import from_random
val = tuple( val = tuple(
...@@ -146,3 +146,9 @@ class SamplingDtypeSetter(EndomorphicOperator): ...@@ -146,3 +146,9 @@ class SamplingDtypeSetter(EndomorphicOperator):
def draw_sample(self, from_inverse=False): def draw_sample(self, from_inverse=False):
return self._op.draw_sample_with_dtype(self._dtype, return self._op.draw_sample_with_dtype(self._dtype,
from_inverse=from_inverse) from_inverse=from_inverse)
def __repr__(self):
from ..utilities import indent
return "\n".join((
f"SamplingDtypeSetter {self._dtype}:",
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment