Commit b9bb2f47 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Fixes summary

1) Improves the output
2) Fixes a bug in which the while loop got stcuk attempting to rename
the glitch parameters (when ng > 1)
parent 25e5f1ce
...@@ -995,31 +995,39 @@ class MCMCSearch(BaseSearchClass): ...@@ -995,31 +995,39 @@ class MCMCSearch(BaseSearchClass):
maxtwoF = self.lnlikes[jmax] maxtwoF = self.lnlikes[jmax]
d = OrderedDict() d = OrderedDict()
lnl_finite = copy.copy(self.lnlikes) repeats = []
lnl_finite[idxs] = 0
close_idxs = abs((maxtwoF - lnl_finite) / maxtwoF) < threshold
for i, k in enumerate(self.theta_keys): for i, k in enumerate(self.theta_keys):
ng = 1 if k in d and k not in repeats:
while k in d: d[k+'_0'] = d[k] # relabel the old key
if k == 1: d.pop(k)
k = k + '_1' repeats.append(k)
else: if k in repeats:
k.replace('_{}'.format(ng-1), '_{}'.format(ng)) k = k + '_0'
ng += 1 count = 1
while k in d:
k = k.replace('_{}'.format(count-1), '_{}'.format(count))
count += 1
d[k] = self.samples[jmax][i] d[k] = self.samples[jmax][i]
s = self.samples[:, i][close_idxs]
d[k + '_std'] = np.std(s)
return d, maxtwoF return d, maxtwoF
def get_median_stds(self): def get_median_stds(self):
""" Returns a dict of the median and std of all production samples """ """ Returns a dict of the median and std of all production samples """
d = OrderedDict() d = OrderedDict()
repeats = []
for s, k in zip(self.samples.T, self.theta_keys): for s, k in zip(self.samples.T, self.theta_keys):
ng = 1 if k in d and k not in repeats:
while k in d: d[k+'_0'] = d[k] # relabel the old key
k = k.rstrip('_{}'.format(ng-1)) + '_{}'.format(ng) d[k+'_0_std'] = d[k+'_std']
ng += 1 d.pop(k)
d.pop(k+'_std')
repeats.append(k)
if k in repeats:
k = k + '_0'
count = 1
while k in d:
k = k.replace('_{}'.format(count-1), '_{}'.format(count))
count += 1
d[k] = np.median(s) d[k] = np.median(s)
d[k+'_std'] = np.std(s) d[k+'_std'] = np.std(s)
return d return d
...@@ -1044,13 +1052,17 @@ class MCMCSearch(BaseSearchClass): ...@@ -1044,13 +1052,17 @@ class MCMCSearch(BaseSearchClass):
f.write('{} = {:1.16e}\n'.format(key, val)) f.write('{} = {:1.16e}\n'.format(key, val))
def print_summary(self): def print_summary(self):
d, max_twoF = self.get_max_twoF() max_twoFd, max_twoF = self.get_max_twoF()
median_std_d = self.get_median_stds() median_std_d = self.get_median_stds()
print('Max twoF: {}'.format(max_twoF)) print('\nSummary:')
print('theta0 index: {}'.format(self.theta0_idx)) print('theta0 index: {}'.format(self.theta0_idx))
print('Max twoF: {} with parameters:'.format(max_twoF))
for k in np.sort(max_twoFd.keys()):
print(' {:10s} = {:1.9e}'.format(k, max_twoFd[k]))
print('\nMedian +/- std for production values')
for k in np.sort(median_std_d.keys()): for k in np.sort(median_std_d.keys()):
if 'std' not in k: if 'std' not in k:
print('{:10s} = {:1.9e} +/- {:1.9e}'.format( print(' {:10s} = {:1.9e} +/- {:1.9e}'.format(
k, median_std_d[k], median_std_d[k+'_std'])) k, median_std_d[k], median_std_d[k+'_std']))
......
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