JohannesBuchner/PyMultiNest — Issue #3: Not handeling negative log evidence
Author: harpsoe
Created: 2012-02-17 22:08:15+00:00
State: open

Dear Johannes

It seems that the analyse module break at negative log evidence.

def _read_error_line(self, l):
#print '_read_error_line', l
name, values = l.split(' ', 1)
name = name.strip(': ').strip()
v, error = values.split(" +/- ")
return name, float(v), float(error)

The strip(' ',1) breaks as negative log evidence gives a ' -' not a ' ', I tried a fix along the lines of:

def _read_error_line(self, l):
#print '_read_error_line', l
index = re.search("[-0-9]",l).start()
name = l[0:index]
values = l[index:]
name, values = l.split(':', 1)
name = name.rstrip().lstrip().strip(':')
v, error = values.split(" +/- ")
return name, float(v), float(error)

But it break the code when trying to detect number of modes somewhere in

def get_stats(self):
"""
information about the modes found:
mean, sigma, maximum a posterior in each dimension
"""
lines = file(self.stats_file).readlines()
text = "".join(lines)
parts = text.split("\n\n\n")
del parts[0]
stats = {
'modes':[]
}
# Global Evidence
self._read_error_into_dict(lines[0], stats)
i = 0
for p in parts:
modelines = p.split("\n\n")
mode = {
'index':i
}
i = i + 1
modelines1 = modelines[0].split("\n")
# Strictly local evidence
self._read_error_into_dict(modelines1[1], mode)
self._read_error_into_dict(modelines1[2], mode)
t = self._read_table(modelines[1], title = "Parameters")
mode['mean'] = t[:,1].tolist()
mode['sigma'] = t[:,2].tolist()
mode['maximum'] = self._read_table(modelines[1])[:,1].tolist()
mode['maximum a posterior'] = self._read_table(modelines[1])[:,1].tolist()
stats['modes'].append(mode)
return stats

Do you have a suggestion for a quick fix?