Skip to content

Commit

Permalink
Merge pull request #142 from lcgraham/master
Browse files Browse the repository at this point in the history
Update example documentation files
  • Loading branch information
lcgraham committed Oct 16, 2015
2 parents a65efe3 + a25c562 commit eb3d87a
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 100 deletions.
3 changes: 0 additions & 3 deletions bet/calculateP/calculateP.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* :mod:`~bet.calculateP.prob_emulated` provides a skeleton class and calculates
the probability for a set of emulation points.
* :mod:`~bet.calculateP.calculateP.prob_samples_ex` calculates the exact
volumes of the interior voronoi cells and estimates the volumes of the
exterior voronoi cells by using a set of bounding points
* :mod:`~bet.calculateP.calculateP.prob_samples_mc` estimates the volumes of
the voronoi cells using MC integration
"""
Expand Down
10 changes: 5 additions & 5 deletions bet/calculateP/voronoiHistogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def center_and_layer1_points_binsize(center_pts_per_edge, center, r_size,
rect_width = r_size*np.ones(sur_domain[:, 0].shape)
rect_domain = np.column_stack([center - .5*rect_width,
center + .5*rect_width])
if np.all(np.greater(r_size, rect_width)):
msg = "The hyperrectangle defined by this size is larger than the "
if np.any(np.greater(r_size, rect_width)):
msg = "The hyperrectangle defined by this size extends outside the "
msg += "original domain."
print msg

Expand Down Expand Up @@ -100,7 +100,7 @@ def center_and_layer1_points(center_pts_per_edge, center, r_ratio, sur_domain):
"""
if np.all(np.greater(r_ratio, 1)):
msg = "The hyperrectangle defined by this ratio is larger than the"
msg += "original domain."
msg += " original domain."
print msg

# determine r_size from the width of the surrounding domain
Expand Down Expand Up @@ -140,11 +140,11 @@ def edges_regular(center_pts_per_edge, rect_domain, sur_domain):
"""
if np.any(np.greater_equal(sur_domain[:, 0], rect_domain[:, 0])):
msg = "The hyperrectangle defined by this size is larger than the"
msg += "original domain."
msg += " original domain."
print msg
elif np.any(np.less_equal(sur_domain[:, 1], rect_domain[:, 1])):
msg = "The hyperrectangle defined by this size is larger than the"
msg += "original domain."
msg += " original domain."
print msg

rect_edges = list()
Expand Down
385 changes: 309 additions & 76 deletions bet/postProcess/plotDomains.py

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions bet/postProcess/plotP.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from bet.Comm import comm, MPI
import matplotlib.pyplot as plt
#plt.rc('text', usetex=True)
#plt.rc('font', family='serif')
import numpy as np
import copy, math


def calculate_1D_marginal_probs(P_samples, samples, lam_domain, nbins=20):

"""
Expand Down Expand Up @@ -45,7 +46,8 @@ def calculate_1D_marginal_probs(P_samples, samples, lam_domain, nbins=20):
# Calculate marginals
marginals = {}
for i in range(num_dim):
[marg, _] = np.histogram(samples[:,i], bins=bins[i], weights=P_samples)
[marg, _] = np.histogram(samples[:, i], bins=bins[i],
weights=P_samples)
marg_temp = np.copy(marg)
comm.Allreduce([marg, MPI.DOUBLE], [marg_temp, MPI.DOUBLE], op=MPI.SUM)
marginals[i] = marg_temp
Expand Down Expand Up @@ -88,8 +90,9 @@ def calculate_2D_marginal_probs(P_samples, samples, lam_domain, nbins=20):
marginals = {}
for i in range(num_dim):
for j in range(i+1, num_dim):
(marg, _) = np.histogramdd(samples[:,[i,j]], bins = [bins[i], bins[j]], weights = P_samples)
marg=np.ascontiguousarray(marg)
(marg, _) = np.histogramdd(samples[:, [i, j]], bins=[bins[i],
bins[j]], weights=P_samples)
marg = np.ascontiguousarray(marg)
marg_temp = np.copy(marg)
comm.Allreduce([marg, MPI.DOUBLE], [marg_temp, MPI.DOUBLE],
op=MPI.SUM)
Expand Down Expand Up @@ -184,12 +187,12 @@ def plot_2D_marginal_probs(marginals, bins, lam_domain,
ax = fig.add_subplot(111)
boxSize = (bins[i][1]-bins[i][0])*(bins[j][1]-bins[j][0])
quadmesh = ax.imshow(marginals[(i, j)].transpose()/boxSize,
interpolation='bicubic', cmap=cm.jet,
interpolation='bicubic', cmap=cm.CMRmap_r,
extent=[lam_domain[i][0], lam_domain[i][1],
lam_domain[j][0], lam_domain[j][1]], origin='lower',
vmax=marginals[(i, j)].max()/boxSize, vmin=0, aspect='auto')
if type(lam_ref) != type(None):
ax.plot(lam_ref[i], lam_ref[j], 'ko', markersize=10)
ax.plot(lam_ref[i], lam_ref[j], 'wo', markersize=10)
if lambda_label == None:
label1 = r'$\lambda_{' + str(i+1) + '}$'
label2 = r'$\lambda_{' + str(j+1) + '}$'
Expand All @@ -203,7 +206,8 @@ def plot_2D_marginal_probs(marginals, bins, lam_domain,
fig.colorbar(quadmesh, ax=ax, label=label_cbar)
plt.axis([lam_domain[i][0], lam_domain[i][1], lam_domain[j][0],
lam_domain[j][1]])
fig.savefig(filename + "_2D_" + str(i) + "_" + str(j) + ".eps", transparent=True)
fig.savefig(filename + "_2D_" + str(i) + "_" + str(j) + ".eps",
transparent=True)
if interactive:
plt.show()
else:
Expand All @@ -226,7 +230,8 @@ def plot_2D_marginal_probs(marginals, bins, lam_domain,
ax.set_zlabel(r'$P$')
plt.backgroundcolor = 'w'
fig.colorbar(surf, shrink=0.5, aspect=5, label=r'$P$')
fig.savefig(filename + "_surf_"+str(i)+"_"+str(j)+".eps", transparent=True)
fig.savefig(filename + "_surf_"+str(i)+"_"+str(j)+".eps",
transparent=True)
if interactive:
plt.show()
else:
Expand Down
5 changes: 3 additions & 2 deletions bet/postProcess/postTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def sample_highest_prob(top_percentile, P_samples, samples, lam_vol=None,
lam_vol, data)

P_sum = np.cumsum(P_samples)
num_samples = np.sum(P_sum <= top_percentile)
num_samples = np.sum(np.logical_and(0.0 < P_sum, P_sum <= top_percentile))
P_samples = P_samples[0:num_samples]
samples = samples[0:num_samples, :]
if type(lam_vol) != type(None):
Expand Down Expand Up @@ -164,7 +164,8 @@ def save_parallel_probs_mat(P_samples, samples, file_prefix, compress=False):
"""
file_dict = {"P_samples": P_samples,
"samples": samples}
sio.savemat(file_prefix + str(comm.rank), file_dict, do_compression=compress)
sio.savemat(file_prefix + str(comm.rank), file_dict,
do_compression=compress)

def collect_parallel_probs_mat(file_prefix, num_files, save=False,
compress=False):
Expand Down
10 changes: 10 additions & 0 deletions doc/examples/example_rst_files/Q_2D.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ defined and the approximation of the volume of :math:`\mathcal{V}_j`. See
this example is essentially the same as :ref:`q1D` we will only highlight the
differences between the two.


.. note::

* In line 36 reduce number of emulated points to 1e4 so that it will run
quickly.
* reduce number of ``ref_nums`` to a single number so that we only
examine a single set of QoI
* add plotting of marginals using
:mod:`bet.postProcess.plotP.plot_2D_marginal_probs`

Define the filename to save :math:`\hat{\rho}_{\Lambda, j}` to::

filename = 'P_q'+str(station_nums[0]+1)+'_q'+str(station_nums[1]+1)
Expand Down
8 changes: 7 additions & 1 deletion doc/examples/example_rst_files/fromfile2D.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ We will walk through the following `example
<https://github.com/UT-CHG/BET/blob/master/examples/fromFile_ADCIRCMap/fromFile2D.py>`_ that uses a linear interpolant of
the QoI map :math:`Q(\lambda) = (q_1(\lambda), q_6(\lambda))` for a
2-dimensional data space. The parameter space in this example is also
2-dimensional.
2-dimensional.

.. note::

* In the lines 56, 57 change chain length and num chains to
reduce the total number of forward solves.
* Saves to ``sandbox2d.mat``.

The modules required by this example are::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Example: Linear Map with Uniform Sampling
===========================

We will wailk through the following `example
We will walk through the following `example
<https://github.com/UT-CHG/BET/blob/master/examples/linearMap/linearMapUniformSampling.py>`_. This example
generates uniform samples in a 3D input parameter space and evaluates a
linear map to a 2D data space. The stochastic inverse problem solved here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Example: Nonlinear Map with Uniform Sampling
============================================

We will wailk through the following `example
We will walk through the following `example
<https://github.com/UT-CHG/BET/blob/master/examples/nonlinearMap/nonlinearMapUniformSampling.py>`_.
This example generates uniform samples in a 2D input parameter space
and evaluates a nonlinear map to either a 1D or 2D output data space.
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/example_rst_files/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Example: Validation
============================================

We will wailk through the following `example
We will walk through the following `example
<https://github.com/UT-CHG/BET/blob/master/examples/validationExample/linearMap.py>`_.
This 2D linear example shows that geometrically distinct QoI can
recreate a probability measure on the input parameter space
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.. _examples:

=======================================
Some References and Examples
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright (C) 2014-2015 Lindley Graham and Steven Mattis
# Copyright (C) 2014-2015 BET Development Team

'''
The python script for building the BET package and subpackages.
Expand All @@ -11,7 +11,7 @@
from distutils.core import setup

setup(name='bet',
version='0.2.0',
version='1.0.0',
description='Butler, Estep, Tavener method',
author='Steven Mattis',
author_email='[email protected]',
Expand Down

0 comments on commit eb3d87a

Please sign in to comment.