Commit 4e062f6b authored by Martin Reinecke's avatar Martin Reinecke

renamings and cleanups

parent 27dce226
Pipeline #24401 passed with stage
in 6 minutes and 16 seconds
......@@ -93,7 +93,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "-"
}
......@@ -161,7 +160,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "-"
}
......@@ -225,9 +223,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"s_space = ift.RGSpace(N_pixels)\n",
......@@ -268,7 +264,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "-"
}
......@@ -293,7 +288,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "-"
}
......@@ -414,7 +408,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
......@@ -448,7 +441,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "-"
}
......@@ -471,7 +463,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
......@@ -503,12 +494,7 @@
},
"outputs": [],
"source": [
"sc = ift.probing.utils.StatCalculator()\n",
"for i in range(200):\n",
" print(i)\n",
" sc.add(HT(curv.generate_posterior_sample()))\n",
"\n",
"m_var = sc.var"
"m_mean, m_var = ift.probe_with_posterior_samples(curv, m, HT, 200)\n"
]
},
{
......@@ -526,7 +512,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
......@@ -601,9 +586,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"N_pixels = 256 # Number of pixels\n",
......@@ -661,18 +644,7 @@
"m = D(j)\n",
"\n",
"# Uncertainty\n",
"sc = ift.probing.utils.StatCalculator()\n",
"\n",
"IC = ift.GradientNormController(iteration_limit=50000,\n",
" tol_abs_gradnorm=0.1)\n",
"inverter = ift.ConjugateGradient(controller=IC)\n",
"curv = ift.library.wiener_filter_curvature.WienerFilterCurvature(R,N,Sh,inverter)\n",
"\n",
"for i in range(20):\n",
" print(i)\n",
" sc.add(HT(curv.generate_posterior_sample()))\n",
"\n",
"m_var = sc.var\n",
"m_mean, m_var = ift.probe_with_posterior_samples(curv, m, HT, 20)\n",
"\n",
"# Get data\n",
"s_power = ift.power_analyze(sh)\n",
......@@ -793,21 +765,21 @@
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
......
......@@ -108,5 +108,5 @@ if __name__ == "__main__":
ift.plot(ift.Field(plot_space,val=data.val), name='data.png', **plotdict)
ift.plot(ift.Field(plot_space,val=m.val), name='map.png', **plotdict)
# sampling the uncertainty map
mean, variance = ift.probe_with_posterior_samples(wiener_curvature, ht, 10)
mean, variance = ift.probe_with_posterior_samples(wiener_curvature, m_k, ht, 10)
ift.plot(ift.Field(plot_space, val=ift.sqrt(variance).val), name="uncertainty.png", **plotdict)
......@@ -72,7 +72,7 @@ if __name__ == "__main__":
sample_mean = ift.Field.zeros(signal_space)
n_samples = 10
for i in range(n_samples):
sample = ht(wiener_curvature.generate_posterior_sample()) + m
sample = ht(wiener_curvature.draw_sample()) + m
sample_variance += sample**2
sample_mean += sample
variance = sample_variance/n_samples - (sample_mean/n_samples)**2
......
......@@ -91,7 +91,7 @@ class CriticalPowerEnergy(Energy):
if self.D is not None:
w = Field.zeros(self.position.domain, dtype=self.m.dtype)
for i in range(self.samples):
sample = self.D.generate_posterior_sample() + self.m
sample = self.D.draw_sample() + self.m
w += P(abs(sample)**2)
w *= 1./self.samples
......
......@@ -46,7 +46,7 @@ class NoiseEnergy(Energy):
if samples is None or samples == 0:
xi_sample_list = [xi]
else:
xi_sample_list = [D.generate_posterior_sample() + xi
xi_sample_list = [D.draw_sample() + xi
for _ in range(samples)]
self.xi_sample_list = xi_sample_list
self.inverter = inverter
......
......@@ -70,7 +70,7 @@ class NonlinearPowerEnergy(Energy):
if samples is None or samples == 0:
xi_sample_list = [xi]
else:
xi_sample_list = [D.generate_posterior_sample() + xi
xi_sample_list = [D.draw_sample() + xi
for _ in range(samples)]
self.xi_sample_list = xi_sample_list
self.inverter = inverter
......
......@@ -59,23 +59,22 @@ class WienerFilterCurvature(EndomorphicOperator):
def apply(self, x, mode):
return self._op.apply(x, mode)
def generate_posterior_sample(self):
""" Generates a posterior sample from a Gaussian distribution with
given mean and covariance.
def draw_sample(self):
""" Generates a sample from a Gaussian distribution with
covariance given by the operator.
This method generates samples by setting up the observation and
reconstruction of a mock signal in order to obtain residuals of the
right correlation which are added to the given mean.
right correlation.
Returns
-------
sample : Field
Returns the a sample from the Gaussian of mean zero and
given covariance.
Returns the a sample from the Gaussian of given covariance.
"""
mock_signal = self.S.generate_posterior_sample()
mock_noise = self.N.generate_posterior_sample()
mock_signal = self.S.draw_sample()
mock_noise = self.N.draw_sample()
mock_data = self.R(mock_signal) + mock_noise
......
......@@ -141,19 +141,18 @@ class DiagonalOperator(EndomorphicOperator):
return DiagonalOperator(self._diagonal.conjugate(), self._domain,
self._spaces)
def generate_posterior_sample(self):
""" Generates a posterior sample from a Gaussian distribution with
given mean and covariance.
def draw_sample(self):
""" Generates a sample from a Gaussian distribution with
covariance given by the operator.
This method generates samples by setting up the observation and
reconstruction of a mock signal in order to obtain residuals of the
right correlation which are added to the given mean.
right correlation.
Returns
-------
sample : Field
Returns the a sample from the Gaussian of given mean and
covariance.
Returns the a sample from the Gaussian of given covariance.
"""
if self._spaces is not None:
......
......@@ -89,19 +89,18 @@ class ScalingOperator(EndomorphicOperator):
return (self.TIMES | self.ADJOINT_TIMES |
self.INVERSE_TIMES | self.ADJOINT_INVERSE_TIMES)
def generate_posterior_sample(self):
""" Generates a posterior sample from a Gaussian distribution with
given mean and covariance.
def draw_sample(self):
""" Generates a sample from a Gaussian distribution with
covariance given by the operator.
This method generates samples by setting up the observation and
reconstruction of a mock signal in order to obtain residuals of the
right correlation which are added to the given mean.
right correlation.
Returns
-------
sample : Field
Returns the a sample from the Gaussian of given mean and
covariance.
Returns the a sample from the Gaussian of given covariance.
"""
return Field.from_random(random_type="normal",
......
......@@ -50,7 +50,7 @@ class StatCalculator(object):
def probe_with_posterior_samples(op, m, post_op, nprobes):
sc = StatCalculator()
for i in range(nprobes):
sample = post_op(op.generate_posterior_sample() + m)
sample = post_op(op.draw_sample() + m)
sc.add(sample)
if nprobes == 1:
......
Markdown is supported
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