Commit 8aaafe29 authored by Gordian Edenhofer's avatar Gordian Edenhofer Committed by Philipp Arras 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): ...@@ -101,13 +101,6 @@ def _total_fluctuation_realized(samples):
return np.sqrt((res/len(samples)).mean()) return np.sqrt((res/len(samples)).mean())
def _stats(op, samples):
sc = StatCalculator()
for s in samples:
return sc.mean.to_global_data(), sc.var.sqrt().to_global_data()
class _LognormalMomentMatching(Operator): class _LognormalMomentMatching(Operator):
def __init__(self, mean, sig, key, N_copies): def __init__(self, mean, sig, key, N_copies):
key = str(key) key = str(key)
...@@ -478,19 +471,17 @@ class CorrelatedFieldMaker: ...@@ -478,19 +471,17 @@ class CorrelatedFieldMaker:
else: else:
offset = float(offset) offset = float(offset)
op = Adder(full(, offset)) @ op op = Adder(full(, offset)) @ op
if prior_info > 0:
from ..sugar import from_random
samps = [
from_random('normal', op.domain) for _ in range(prior_info)
return op return op
def statistics_summary(self, samples): def statistics_summary(self, prior_info):
from ..sugar import from_random
if prior_info == 0:
lst = [('Offset amplitude', self.amplitude_total_offset), lst = [('Offset amplitude', self.amplitude_total_offset),
('Total fluctuation amplitude', self.total_fluctuation)] ('Total fluctuation amplitude', self.total_fluctuation)]
namps = len(self._a) namps = len(self._a)
if namps > 1: if namps > 1:
for ii in range(namps): for ii in range(namps):
...@@ -500,7 +491,11 @@ class CorrelatedFieldMaker: ...@@ -500,7 +491,11 @@ class CorrelatedFieldMaker:
self.average_fluctuation(ii))) self.average_fluctuation(ii)))
for kk, op in lst: 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()): for m, s in zip(mean.flatten(), stddev.flatten()):
print('{}: {:.02E} ± {:.02E}'.format(kk, m, s)) 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