Commit 8aaafe29 authored by Gordian Edenhofer's avatar Gordian Edenhofer Committed by Philipp Arras
Browse files

correlated_field.py: Do not store samples for stat

Instead of drawing samples and storing them in a potentially huge list,
draw individual samples only when needed. Hereby, get rid of the
`_stats` function but instead draw samples during computing the
statistics summary.
parent 8387ab10
......@@ -101,13 +101,6 @@ def _total_fluctuation_realized(samples):
return np.sqrt((res/len(samples)).mean())
def _stats(op, samples):
sc = StatCalculator()
for s in samples:
sc.add(op(s.extract(op.domain)))
return sc.mean.to_global_data(), sc.var.sqrt().to_global_data()
class _LognormalMomentMatching(Operator):
def __init__(self, mean, sig, key, N_copies):
key = str(key)
......@@ -478,19 +471,17 @@ class CorrelatedFieldMaker:
else:
offset = float(offset)
op = Adder(full(op.target, offset)) @ op
self.statistics_summary(prior_info)
return op
if prior_info > 0:
def statistics_summary(self, prior_info):
from ..sugar import from_random
samps = [
from_random('normal', op.domain) for _ in range(prior_info)
]
self.statistics_summary(samps)
return op
def statistics_summary(self, samples):
if prior_info == 0:
return
lst = [('Offset amplitude', self.amplitude_total_offset),
('Total fluctuation amplitude', self.total_fluctuation)]
namps = len(self._a)
if namps > 1:
for ii in range(namps):
......@@ -500,7 +491,11 @@ class CorrelatedFieldMaker:
self.average_fluctuation(ii)))
for kk, op in lst:
mean, stddev = _stats(op, samples)
sc = StatCalculator()
for _ in range(prior_info):
sc.add(op(from_random('normal', op.domain)))
mean = sc.mean.to_global_data()
stddev = sc.var.sqrt().to_global_data()
for m, s in zip(mean.flatten(), stddev.flatten()):
print('{}: {:.02E} ± {:.02E}'.format(kk, m, s))
......
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