Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

::
Expand All @@ -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 <https://github.com/gerbaudo/fbu>`_ repository:
`GitHub <https://github.com/pyFBU/fbu>`_ repository:

::

git clone https://github.com/gerbaudo/fbu.git
git clone https://github.com/pyFBU/fbu.git


Usage
-----

A `simple tutorial <https://github.com/gerbaudo/fbu/blob/master/tutorial.ipynb>`_ to help you get started.
A `simple tutorial <tutorial.ipynb>`_ to help you get started.



27 changes: 24 additions & 3 deletions fbu/PyFBU.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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):
Expand All @@ -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])
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down