Exemplo n.º 1
0
    def setUp(self):
        self.set_new = samp.rectangle_sample_set(dim=2)
        self.set_new.set_domain(np.array([[0.0, 1.0], [0.0, 1.0]]))
        self.set_new.setup(maxes=[[0.75, 0.75]], mins=[[0.25, 0.25]])

        self.set_old = samp.cartesian_sample_set(dim=2)
        self.set_old.set_domain(np.array([[0.0, 1.0], [0.0, 1.0]]))
        self.set_old.setup([np.linspace(0, 1, 21), np.linspace(0, 1, 21)])
        num_old = self.set_old.check_num()
        probs = np.zeros((num_old,))
        probs[0:-1] = 1.0/float(num_old-1)
        self.set_old.set_probabilities(probs)

        self.set_em = samp.cartesian_sample_set(dim=2)
        self.set_em.set_domain(np.array([[0.0, 1.0], [0.0, 1.0]]))
        self.set_em.setup([np.linspace(0, 1, 101), np.linspace(0, 1, 101)])
Exemplo n.º 2
0
    def setUp(self):
        self.set_new = samp.rectangle_sample_set(dim=2)
        self.set_new.set_domain(np.array([[0.0, 1.0], [0.0, 1.0]]))
        self.set_new.setup(maxes=[[0.75, 0.75]], mins=[[0.25, 0.25]])

        self.set_old = samp.cartesian_sample_set(dim=2)
        self.set_old.set_domain(np.array([[0.0, 1.0], [0.0, 1.0]]))
        self.set_old.setup([np.linspace(0, 1, 21), np.linspace(0, 1, 21)])
        num_old = self.set_old.check_num()
        probs = np.zeros((num_old, ))
        probs[0:-1] = 1.0 / float(num_old - 1)
        self.set_old.set_probabilities(probs)

        self.set_em = samp.cartesian_sample_set(dim=2)
        self.set_em.set_domain(np.array([[0.0, 1.0], [0.0, 1.0]]))
        self.set_em.setup([np.linspace(0, 1, 101), np.linspace(0, 1, 101)])
Exemplo n.º 3
0
def regular_partition_uniform_distribution_rectangle_size(data_set, Q_ref=None,
                                                          rect_size=None,
                                                          cells_per_dimension=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`` (or the ``reference_value``
    of a sample set. If ``Q_ref`` is not given the reference value is used) 
    with ``rect_size`` of the width of a hyperrectangle.

    Since rho_D is a uniform distribution on a hyperrectanlge we can represent
    it exactly.

    :param rect_size: The size used to determine the width of the uniform
        distribution
    :type rect_size: double or list
    :param data_set: Sample set that the probability measure is defined for.
    :type data_set: :class:`~bet.sample.discretization` or
        :class:`~bet.sample.sample_set` or :class:`~numpy.ndarray`
    :param Q_ref: :math:`Q(\lambda_{reference})`
    :type Q_ref: :class:`~numpy.ndarray` of size (mdim,)
    :param list cells_per_dimension: number of cells per dimension.

    :rtype: :class:`~bet.sample.rectangle_sample_set`
    :returns: sample_set object defining simple function approximation

    """
    (num, dim, values, Q_ref) = check_inputs(data_set, Q_ref)

    data = values
    
    if rect_size is None:
        raise wrong_argument_type("Missing rectangle size.")
    elif not isinstance(rect_size, collections.Iterable):
        rect_size = rect_size * np.ones((dim,))
    if np.any(np.less_equal(rect_size, 0)):
        msg = 'rect_size must be greater than 0'
        raise wrong_argument_type(msg)

    if not isinstance(cells_per_dimension, collections.Iterable):
        cells_per_dimension = np.ones((dim,)) * cells_per_dimension

    maxes = [Q_ref + 0.5*np.array(rect_size)]
    mins = [Q_ref - 0.5*np.array(rect_size)]

    xi = []
    for i in xrange(dim):
        xi.append(np.linspace(mins[0][i], maxes[0][i], 
            cells_per_dimension[i] + 1))
    
    s_set = samp.cartesian_sample_set(dim)
    s_set.setup(xi)
    domain = np.zeros((dim, 2))
    domain[:, 0] = mins[0]
    domain[:, 1] = maxes[0]
    s_set.set_domain(domain)
    s_set.exact_volume_lebesgue()
    vol = np.sum(s_set._volumes[0:-1])
    prob = np.zeros(s_set._volumes.shape)
    prob[0:-1] = s_set._volumes[0:-1]/vol
    s_set.set_probabilities(prob)

    if isinstance(data_set, samp.discretization):
        data_set._output_probability_set = s_set
    return s_set