Commit 10be5ac1 authored by moritz's avatar moritz

Moritz Huebner: Moved the Result class from sampler.py into a separate module

parent cddbbcb8
import logging
import os
import pickle
class Result(dict):
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
def __repr__(self):
"""Print a summary """
return ("nsamples: {:d}\n"
"logz: {:6.3f} +/- {:6.3f}\n"
.format(len(self.samples), self.logz, self.logzerr))
def save_to_file(self, outdir, label):
file_name = '{}/{}_results.p'.format(outdir, label)
if os.path.isdir(outdir) is False:
os.makedirs(outdir)
if os.path.isfile(file_name):
logging.info(
'Renaming existing file {} to {}.old'.format(file_name,
file_name))
os.rename(file_name, file_name + '.old')
logging.info("Saving result to {}".format(file_name))
with open(file_name, 'wb+') as f:
pickle.dump(self, f)
......@@ -3,46 +3,14 @@ from __future__ import print_function, division, absolute_import
import inspect
import logging
import os
import pickle
import sys
import numpy as np
from result import Result
from .parameter import Parameter
class Result(dict):
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
def __repr__(self):
"""Print a summary """
return ("nsamples: {:d}\n"
"logz: {:6.3f} +/- {:6.3f}\n"
.format(len(self.samples), self.logz, self.logzerr))
def save_to_file(self, outdir, label):
file_name = '{}/{}_results.p'.format(outdir, label)
if os.path.isdir(outdir) is False:
os.makedirs(outdir)
if os.path.isfile(file_name):
logging.info(
'Renaming existing file {} to {}.old'
.format(file_name, file_name))
os.rename(file_name, file_name + '.old')
logging.info("Saving result to {}".format(file_name))
with open(file_name, 'wb+') as f:
pickle.dump(self, f)
class Sampler(object):
""" A sampler object to aid in setting up an inference run
......
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