diff --git a/README.rst b/README.rst index 40301ce..98de71a 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,8 @@ -.. image:: https://travis-ci.org/gerbaudo/fbu.png - :target: https://travis-ci.org/gerbaudo/fbu +.. image:: https://travis-ci.com/pyFBU/fbu.png + :target: https://travis-ci.com/pyFBU/fbu + +.. image:: https://img.shields.io/pypi/v/fbu.svg + :target: https://pypi.python.org/pypi/fbu ===== PyFBU @@ -31,6 +34,20 @@ PyMC 3 can be installed using conda conda install -c conda-forge pymc3 +The following packages also need to be installed + +:: + + conda install mkl + conda install numpy + conda install mkl-service + +And this export needs to be added to your bashrc or similar to avoid warings + +:: + + export MKL_THREADING_LAYER=GNU + or pip :: @@ -45,15 +62,17 @@ The latest stable version of PyFBU can be installed using pip. pip install fbu Alternatively one can check out the development version of the code from the -`GitHub `_ repository: +`GitHub `_ repository: :: - git clone https://github.com/gerbaudo/fbu.git + git clone https://github.com/pyFBU/fbu.git Usage ----- -A `simple tutorial `_ to help you get started. +A `simple tutorial `_ to help you get started. + + diff --git a/fbu/PyFBU.py b/fbu/PyFBU.py index 48f7ec9..8cf0ac4 100644 --- a/fbu/PyFBU.py +++ b/fbu/PyFBU.py @@ -1,6 +1,7 @@ import pymc3 as mc from numpy import random, dot, array, inf import theano +import copy class PyFBU(object): """A class to perform a MCMC sampling. @@ -14,7 +15,7 @@ class PyFBU(object): def __init__(self,data=[],response=[],background={}, backgroundsyst={},objsyst={'signal':{},'background':{}}, lower=[],upper=[],regularization=None, - rndseed=-1,verbose=False,name='',monitoring=False): + rndseed=-1,verbose=False,name='',monitoring=False, mode=False): # [MCMC parameters] self.nTune = 1000 self.nMCMC = 10000 # N of sampling points @@ -25,7 +26,7 @@ def __init__(self,data=[],response=[],background={}, self.lower = lower # lower sampling bounds self.upper = upper # upper sampling bounds # [unfolding model parameters] - self.prior = 'DiscreteUniform' + self.prior = 'Uniform' self.priorparams = {} self.regularization = regularization # [input] @@ -41,6 +42,9 @@ def __init__(self,data=[],response=[],background={}, self.name = name self.monitoring = monitoring self.sampling_progressbar = True + # [mode] + self.mode = mode + self.MAP_method = 'L-BFGS-B' #__________________________________________________________ def validateinput(self): @@ -67,6 +71,7 @@ def run(self): nbckg = len(backgroundkeys) backgrounds = [] + backgroundnormsysts = array([]) if nbckg>0: backgrounds = array([self.background[key] for key in backgroundkeys]) backgroundnormsysts = array([self.backgroundsyst[key] for key in backgroundkeys]) @@ -83,7 +88,7 @@ def run(self): for bckg in backgroundkeys]) recodim = len(data) - resmat = self.response + resmat = self.response truthdim = len(resmat) model = mc.Model() @@ -150,6 +155,18 @@ def unfold(): import time from datetime import timedelta init_time = time.time() + + print(self.nuts_kwargs) + + + if self.mode: + map_estimate = mc.find_MAP(model=model, method=self.MAP_method) + print (map_estimate) + self.MAP = map_estimate + self.trace = [] + self.nuisancestrace = [] + return + trace = mc.sample(self.nMCMC,tune=self.nTune,cores=self.nCores, chains=self.nChains, nuts_kwargs=self.nuts_kwargs, discard_tuned_samples=self.discard_tuned_samples, @@ -161,16 +178,20 @@ def unfold(): )) self.trace = [trace['truth%d'%bin][:] for bin in range(truthdim)] + #self.trace = [copy.deepcopy(trace['truth%d'%bin][:]) for bin in range(truthdim)] self.nuisancestrace = {} if nbckg>0: for name,err in zip(backgroundkeys,backgroundnormsysts): if err<0.: self.nuisancestrace[name] = trace['norm_%s'%name][:] + #self.nuisancestrace[name] = copy.deepcopy(trace['norm_%s'%name][:]) if err>0.: self.nuisancestrace[name] = trace['gaus_%s'%name][:] + #self.nuisancestrace[name] = copy.deepcopy(trace['gaus_%s'%name][:]) for name in objsystkeys: if self.systfixsigma==0.: self.nuisancestrace[name] = trace['gaus_%s'%name][:] + #self.nuisancestrace[name] = copy.deepcopy(trace['gaus_%s'%name][:]) if self.monitoring: from fbu import monitoring diff --git a/setup.py b/setup.py index 379f8c1..1e500f6 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,10 @@ DISTNAME = 'fbu' DESCRIPTION = "PyFBU" #VERSION = '0.0.2' -VERSION = '0.1.1' +VERSION = '0.1.2' AUTHOR = 'Davide Gerbaudo, Clement Helsens and Francesco Rubbo' -AUTHOR_EMAIL = 'rubbo.francesco@gmail.com' -URL = 'https://github.com/gerbaudo/fbu' +AUTHOR_EMAIL = 'clement.helsens@gmail.com' +URL = 'https://github.com/pyFBU/fbu' classifiers = [ 'Development Status :: 3 - Alpha',