Example #1
0
def uniform_hyperrectangle(data, Q_ref, bin_ratio, center_pts_per_edge=1):
    r"""
    Creates a simple function approximation of :math:`\rho_{\mathcal{D},M}`
    where :math:`\rho_{\mathcal{D},M}` is a uniform probability density
    centered at Q_ref with bin_ratio of the width
    of D.

    Since rho_D is a uniform distribution on a hyperrectanlge we should be able
    to represent it exactly with ``M = 3^mdim`` or rather
    ``len(d_distr_samples) == 3^mdim``.

    :param bin_ratio: The ratio used to determine the width of the
        uniform distributiion as ``bin_size = (data_max-data_min)*bin_ratio``
    :type bin_ratio: double or list()
    :param int num_d_emulate: Number of samples used to emulate using an MC
        assumption 
    :param data: Array containing QoI data where the QoI is mdim diminsional
    :type data: :class:`~numpy.ndarray` of size (num_samples, mdim)
    :param Q_ref: :math:`Q(\lambda_{reference})`
    :type Q_ref: :class:`~numpy.ndarray` of size (mdim,)
    :param list() center_pts_per_edge: number of center points per edge and
        additional two points will be added to create the bounding layer

    :rtype: tuple
    :returns: (rho_D_M, d_distr_samples, d_Tree) where ``rho_D_M`` and
        ``d_distr_samples`` are (mdim, M) :class:`~numpy.ndarray` and `d_Tree`
        is the :class:`~scipy.spatial.KDTree` for d_distr_samples

    """
    if len(data.shape) == 1:
        data = np.expand_dims(data, axis=1)
    data_max = np.max(data, 0)
    data_min = np.min(data, 0)

    # TO-DO: Check for inputted center_pts_per_edge in case given as list
    # or as numpy array to see if dimensions match data space dimensions and
    # that positive integer values are being used. Also, create this change
    # elsewhere since center_pts_per_edge is only a scalar if dim(D)=1.
    if not isinstance(center_pts_per_edge, np.ndarray):
        center_pts_per_edge = np.ones((data.shape[1])) * center_pts_per_edge
    else:
        if not len(center_pts_per_edge) == data.shape[1]:
            center_pts_per_edge = np.ones((data.shape[1]))
            print 'Warning: center_pts_per_edge dimension mismatch.'
            print 'Using 1 in each dimension.'

    sur_domain = np.zeros((data.shape[1], 2))
    sur_domain[:, 0] = data_min
    sur_domain[:, 1] = data_max
    points, _, rect_domain = vHist.center_and_layer1_points(center_pts_per_edge, 
            Q_ref, bin_ratio, sur_domain)
    edges = vHist.edges_regular(center_pts_per_edge, Q_ref, bin_ratio,
            sur_domain) 
    _, volumes, _ = vHist.histogramdd_volumes(edges, points)
    return vHist.simple_fun_uniform(points, volumes, rect_domain)
Example #2
0
def uniform_hyperrectangle_binsize(data, Q_ref, bin_size,
        center_pts_per_edge=1): 
    r"""
    Creates a simple function approximation of :math:`\rho_{\mathcal{D},M}`
    where :math:`\rho_{\mathcal{D},M}` is a uniform probability density
    centered at Q_ref with bin_size of the width of D.

    Since rho_D is a uniform distribution on a hyperrectanlge we should be able
    to represent it exactly with ``M = 3^mdim`` or rather
    ``len(d_distr_samples) == 3^mdim``.

    :param bin_size: The size used to determine the width of the uniform
        distribution 
    :type bin_size: double or list() 
    :param int num_d_emulate: Number of samples used to emulate using an MC 
        assumption 
    :param data: Array containing QoI data where the QoI is mdim diminsional 
    :type data: :class:`~numpy.ndarray` of size (num_samples, mdim) 
    :param Q_ref: :math:`Q(\lambda_{reference})` 
    :type Q_ref: :class:`~numpy.ndarray` of size (mdim,) 
    :param list() center_pts_per_edge: number of center points per edge
        and additional two points will be added to create the bounding layer

    :rtype: tuple 
    :returns: (rho_D_M, d_distr_samples, d_Tree) where
        ``rho_D_M`` is (M,) and ``d_distr_samples`` are (M, mdim)
        :class:`~numpy.ndarray` and `d_Tree` is the :class:`~scipy.spatial.KDTree`
        for d_distr_samples

    """
    data = util.fix_dimensions_data(data)

    if not isinstance(center_pts_per_edge, collections.Iterable):
        center_pts_per_edge = np.ones((data.shape[1],)) * center_pts_per_edge
    else:
        if not len(center_pts_per_edge) == data.shape[1]:
            center_pts_per_edge = np.ones((data.shape[1],))
            print 'Warning: center_pts_per_edge dimension mismatch.'
            print 'Using 1 in each dimension.'
    if np.any(np.less(center_pts_per_edge, 0)):
        print 'Warning: center_pts_per_edge must be greater than 0'
    if not isinstance(bin_size, collections.Iterable):
        bin_size = bin_size*np.ones((data.shape[1],))
    if np.any(np.less(bin_size, 0)):
        print 'Warning: center_pts_per_edge must be greater than 0'

    sur_domain = np.array([np.min(data, 0), np.max(data, 0)]).transpose()

    points, _, rect_domain = vHist.center_and_layer1_points_binsize\
            (center_pts_per_edge, Q_ref, bin_size, sur_domain)
    edges = vHist.edges_regular(center_pts_per_edge, rect_domain, sur_domain) 
    _, volumes, _ = vHist.histogramdd_volumes(edges, points)
    return vHist.simple_fun_uniform(points, volumes, rect_domain)
Example #3
0
def uniform_hyperrectangle_binsize(data, Q_ref, bin_size, center_pts_per_edge=1):
    r"""
    Creates a simple function approximation of :math:`\rho_{\mathcal{D},M}`
    where :math:`\rho_{\mathcal{D},M}` is a uniform probability density
    centered at Q_ref with bin_size of the width of D.

    Since rho_D is a uniform distribution on a hyperrectanlge we should be able
    to represent it exactly with ``M = 3^mdim`` or rather
    ``len(d_distr_samples) == 3^mdim``.

    :param bin_size: The size used to determine the width of the uniform
        distribution 
    :type bin_size: double or list() 
    :param int num_d_emulate: Number of samples used to emulate using an MC 
        assumption 
    :param data: Array containing QoI data where the QoI is mdim diminsional 
    :type data: :class:`~numpy.ndarray` of size (num_samples, mdim) 
    :param Q_ref: :math:`Q(\lambda_{reference})` 
    :type Q_ref: :class:`~numpy.ndarray` of size (mdim,) 
    :param list() center_pts_per_edge: number of center points per edge
        and additional two points will be added to create the bounding layer

    :rtype: tuple :returns: (rho_D_M, d_distr_samples, d_Tree) where
    ``rho_D_M`` is (M,) and ``d_distr_samples`` are (M, mdim)
    :class:`~numpy.ndarray` and `d_Tree` is the :class:`~scipy.spatial.KDTree`
    for d_distr_samples

    """
    data = util.fix_dimensions_data(data)

    if not isinstance(center_pts_per_edge, collections.Iterable):
        center_pts_per_edge = np.ones((data.shape[1],)) * center_pts_per_edge
    else:
        if not len(center_pts_per_edge) == data.shape[1]:
            center_pts_per_edge = np.ones((data.shape[1],))
            print 'Warning: center_pts_per_edge dimension mismatch.'
            print 'Using 1 in each dimension.'
    if np.any(np.less(center_pts_per_edge, 0)):
        print 'Warning: center_pts_per_edge must be greater than 0'
    if not isinstance(bin_size, collections.Iterable):
        bin_size = bin_size*np.ones((data.shape[1],))
    if np.any(np.less(bin_size, 0)):
        print 'Warning: center_pts_per_edge must be greater than 0'

    sur_domain = np.array([np.min(data, 0), np.max(data, 0)]).transpose()

    points, _, rect_domain = vHist.center_and_layer1_points_binsize(center_pts_per_edge, 
            Q_ref, bin_size, sur_domain)
    edges = vHist.edges_regular(center_pts_per_edge, rect_domain, sur_domain) 
    _, volumes, _ = vHist.histogramdd_volumes(edges, points)
    return vHist.simple_fun_uniform(points, volumes, rect_domain)
Example #4
0
def uniform_hyperrectangle_binsize(data, Q_ref, bin_size, center_pts_per_edge=1):
    r"""
    Creates a simple function approximation of :math:`\rho_{\mathcal{D},M}`
    where :math:`\rho_{\mathcal{D},M}` is a uniform probability density
    centered at Q_ref with bin_size of the width
    of D.

    Since rho_D is a uniform distribution on a hyperrectanlge we should be able
    to represent it exactly with ``M = 3^mdim`` or rather
    ``len(d_distr_samples) == 3^mdim``.

    :param bin_size: The size used to determine the width of the
        uniform distribution 
    :type bin_size: double or list()
    :param int num_d_emulate: Number of samples used to emulate using an MC
        assumption 
    :param data: Array containing QoI data where the QoI is mdim diminsional
    :type data: :class:`~numpy.ndarray` of size (num_samples, mdim)
    :param Q_ref: :math:`Q(\lambda_{reference})`
    :type Q_ref: :class:`~numpy.ndarray` of size (mdim,)
    :param list() center_pts_per_edge: number of center points per edge and
        additional two points will be added to create the bounding layer

    :rtype: tuple
    :returns: (rho_D_M, d_distr_samples, d_Tree) where ``rho_D_M`` and
        ``d_distr_samples`` are (mdim, M) :class:`~numpy.ndarray` and `d_Tree`
        is the :class:`~scipy.spatial.KDTree` for d_distr_samples

    """
    if len(data.shape) == 1:
        data = np.expand_dims(data, axis=1)
    data_max = np.max(data, 0)
    data_min = np.min(data, 0)

    sur_domain = np.zeros((data.shape[1], 2))
    sur_domain[:, 0] = data_min
    sur_domain[:, 1] = data_max
    points, _, rect_domain = vHist.center_and_layer1_points_binsize(center_pts_per_edge, 
            Q_ref, bin_size, sur_domain)
    edges = vHist.edges_regular_binsize(center_pts_per_edge, Q_ref, bin_size,
            sur_domain) 
    _, volumes, _ = vHist.histogramdd_volumes(edges, points)
    return vHist.simple_fun_uniform(points, volumes, rect_domain)
 def setUp(self):
     """
     Set up the problem
     """
     points = list()
     edges = list()
     self.rect_domain = np.empty((self.mdim, 2))
     for dim in xrange(self.mdim):
         points_dim = np.linspace(self.sur_domain[dim, 0],
                                  self.sur_domain[dim, 1], 4)
         points.append(points_dim[1:-1])
         edge = (points_dim[1:] + points_dim[:-1]) / 2.0
         edges.append(edge)
         self.rect_domain[dim, :] = edge[[0, -1]]
     points = util.meshgrid_ndim(points)
     H, _ = np.histogramdd(points, edges, normed=True)
     volume = 1.0 / (H * (2.0**self.mdim))
     volumes = volume.ravel()
     output = vHist.simple_fun_uniform(points, volumes, self.rect_domain)
     self.rho_D_M, self.d_distr_samples, self.d_Tree = output
Example #6
0
 def setUp(self):
     """
     Set up the problem
     """
     points = list()
     edges = list()
     self.rect_domain = np.empty((self.mdim, 2))
     for dim in xrange(self.mdim):
         points_dim = np.linspace(self.sur_domain[dim, 0],
             self.sur_domain[dim, 1], 4)
         points.append(points_dim[1:-1])
         edge = (points_dim[1:]+points_dim[:-1])/2.0
         edges.append(edge)
         self.rect_domain[dim, :] = edge[[0, -1]]
     points = util.meshgrid_ndim(points)
     H, _ = np.histogramdd(points, edges, normed=True)
     volume = 1.0/(H*(2.0**self.mdim))
     volumes = volume.ravel()
     output = vHist.simple_fun_uniform(points, volumes, self.rect_domain)
     self.rho_D_M, self.d_distr_samples, self.d_Tree = output