Skip to content

Commit

Permalink
Merge pull request #148 from lcgraham/master
Browse files Browse the repository at this point in the history
Adds sorting for tails and creation of simple indicator functions
  • Loading branch information
smattis committed Nov 16, 2015
2 parents eb3d87a + 8b9b8f3 commit 4330acc
Show file tree
Hide file tree
Showing 21 changed files with 929 additions and 153 deletions.
34 changes: 27 additions & 7 deletions bet/Comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,84 @@ def __init__(self):

def Get_size(self):
"""
:rtype: int
:returns: 1
"""
return 1

def Get_rank(self):
"""
:rtype: int
:returns 0
:returns: 0
"""
return 0

def allgather(self, val, val2=None):
def allgather(self, val):
"""
:param object val: object to allgather
:rtype: object
:returns: val
"""
return val

def gather(self, val1, val2=None, root=0):
def gather(self, val1, root=0):
"""
:param object val1: object to gather
:param object val2: object to gather
:param int root: 0
:rtype: object
:returns: val1
"""
return [val1]

def allreduce(self, val1, op=None):
"""
:param object val1: object to allreduce
:rtype: object
:returns: val1
"""
return val1

def bcast(self, val, root=0):
"""
:param object val: object to broadcast
:param int root: 0
:rtype: object
:returns: val
"""
return val

def scatter(self, val1, val2=None, root=0):
def scatter(self, val1, root=0):
"""
:param object val1: object to scatter
:param object val2: object to scatter
:param int root: 0
:rtype: object
:returns: val1
"""
if isinstance(val1, collections.Iterable) and len(val1)==1:
if isinstance(val1, collections.Iterable) and len(val1) == 1:
val1 = val1[0]
return val1

def Allgather(self, val, val2=None):
"""
:param object val: object to Allgather
:rtype: object
:returns: val
"""
return val

Expand All @@ -96,17 +110,21 @@ def Allreduce(self, val1, val2=None, op=None):
:param object val1: object to Allreduce
:param object val2: object to Allreduce
:param op: None
:rtype: object
:returns: val1
"""
return val1

def Bcast(self, val, root=0):
"""
:param object val: object to gather
:param int root: 0
:rtype: object
:returns: val
"""
return val

Expand All @@ -115,8 +133,10 @@ def Scatter(self, val1, val2, root=0):
:param object val1: object to Scatter
:param object val2: object to Scatter
:param int root: 0
:rtype: object
:returns: val1
"""
return val1

Expand Down
28 changes: 27 additions & 1 deletion bet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# Copyright (C) 2014-2015 The BET Development Team

__all__ = ['sampling', 'calculateP', 'postProcess', 'sensitivity', 'util', 'Comm']
"""
Butler, Estep, Tavener Method
This package provides tools for solving stochastic inverse problems using a
measure-theoretic. It is named for the developers of the key algorithm in
:mod:`bet.calculateP.calculateP`.
Comm :mod:`~bet.Comm` provides a work around for users who do not which to install
:program:``mpi4py``.
util :mod:`~bet.util` provides some general use methods for creating grids,
checking/fixing dimensions, and globalizing arrays.
calculateP :mod:`~bet.calculateP` provides tools to approximate probabilities.
sampling :mod:`~bet.sampling` provides various sampling algorithms.
sensitivity :mod:`~bet.sensitivity` provides tools for approximating
derivatives and optimally choosing quantities of interest.
postProcess :mod:`~bet.postProcess` provides plotting tools and tools to sort
samples by probabilities.
"""

__all__ = ['sampling', 'calculateP', 'postProcess', 'sensitivity', 'util',
'Comm']
4 changes: 3 additions & 1 deletion bet/calculateP/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
generating points for cells that define a regular grid for use by
:meth:`numpy.histogramdd` and for determining their volumes, etc. This
module is only for use by :mod:`~bet.calculateP.simpleFunP`.
* :mod:`~bet.calculateP.indicatorFunctions` provides methods for creating
indicator functions for use by various other classes.
"""
__all__ = ['calculateP', 'simpleFunP', 'voronoiHistogram']
__all__ = ['calculateP', 'simpleFunP', 'voronoiHistogram', 'indicatorFunctions']
13 changes: 7 additions & 6 deletions bet/calculateP/calculateP.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def emulate_iid_lebesgue(lam_domain, num_l_emulate):
:returns: a set of samples for emulation
"""
num_l_emulate = (num_l_emulate/comm.size) + (comm.rank < num_l_emulate%comm.size)
num_l_emulate = (num_l_emulate/comm.size) + \
(comm.rank < num_l_emulate%comm.size)
lam_width = lam_domain[:, 1] - lam_domain[:, 0]
lambda_emulate = lam_width*np.random.random((num_l_emulate,
lam_domain.shape[0]))+lam_domain[:, 0]
Expand Down Expand Up @@ -63,11 +64,11 @@ def prob_emulated(samples, data, rho_D_M, d_distr_samples,
samples = np.expand_dims(samples, axis=1)
if len(data.shape) == 1:
data = np.expand_dims(data, axis=1)
if type(lambda_emulate) == type(None):
if lambda_emulate is None:
lambda_emulate = samples
if len(d_distr_samples.shape) == 1:
d_distr_samples = np.expand_dims(d_distr_samples, axis=1)
if type(d_Tree) == type(None):
if d_Tree is None:
d_Tree = spatial.KDTree(d_distr_samples)

# Determine which inputs go to which M bins using the QoI
Expand Down Expand Up @@ -121,7 +122,7 @@ def prob(samples, data, rho_D_M, d_distr_samples, d_Tree=None):
data = np.expand_dims(data, axis=1)
if len(d_distr_samples.shape) == 1:
d_distr_samples = np.expand_dims(d_distr_samples, axis=1)
if type(d_Tree) == type(None):
if d_Tree is None:
d_Tree = spatial.KDTree(d_distr_samples)

# Set up local arrays for parallelism
Expand Down Expand Up @@ -183,11 +184,11 @@ def prob_mc(samples, data, rho_D_M, d_distr_samples,
samples = np.expand_dims(samples, axis=1)
if len(data.shape) == 1:
data = np.expand_dims(data, axis=1)
if type(lambda_emulate) == type(None):
if lambda_emulate is None:
lambda_emulate = samples
if len(d_distr_samples.shape) == 1:
d_distr_samples = np.expand_dims(d_distr_samples, axis=1)
if type(d_Tree) == type(None):
if d_Tree is None:
d_Tree = spatial.KDTree(d_distr_samples)

# Determine which inputs go to which M bins using the QoI
Expand Down
Loading

0 comments on commit 4330acc

Please sign in to comment.