Example #1
0
    def __init__(self,
                 function,
                 abscissa,
                 ordinate,
                 bounds=None,
                 ordinate_error=None):
        """
        Initialisation function for a :py:class:`~uravu.relationship.Relationship` object.
        """
        self.function = function
        self.abscissa = abscissa

        potential_y = []
        for i, y in enumerate(ordinate):
            if not isinstance(y, Distribution):
                if not isinstance(y, stats._distn_infrastructure.rv_frozen):
                    if ordinate_error is not None:
                        potential_y.append(
                            Distribution(
                                stats.norm.rvs(loc=y,
                                               scale=ordinate_error[i],
                                               size=5000)))
                    else:
                        raise ValueError(
                            "uravu ordinate should be a list of uravu.distribution.Distribution objects or an ordinate_error should be given."
                        )
                else:
                    potential_y.append(Distribution(y.rvs(size=5000)))
                self.ordinate = Axis(potential_y)
            else:
                self.ordinate = Axis(ordinate)

        if abscissa.shape[0] != len(ordinate):
            raise ValueError(
                "The number of data points in the abscissa does not match that for the ordinate."
            )

        self.bounds = bounds
        self.variables = []
        if bounds is not None:
            if len(self.bounds) != self.len_parameters or not isinstance(
                    bounds[0], tuple):
                raise ValueError(
                    "The number of bounds does not match the number of parameters"
                )
            for i, b in enumerate(self.bounds):
                self.variables.append(
                    Distribution(
                        stats.uniform.rvs(loc=b[0],
                                          scale=b[1] - b[0],
                                          size=500)))
        else:
            for i in range(self.len_parameters):
                self.variables.append(Distribution(1))

        self.ln_evidence = None
        self.mcmc_results = None
        self.nested_sampling_results = None
Example #2
0
 def test_init_kde_size_change(self):
     distro2 = Distribution(
         norm.rvs(loc=1,
                  scale=1,
                  size=1000,
                  random_state=np.random.RandomState(2)))
     AX = Axis([DISTRO1, distro2])
     assert_equal(AX.values[1].samples, distro2.samples)
Example #3
0
 def test_shape_array(self):
     ax = Axis(np.ones((3, 3)))
     assert_equal(ax.shape, (3, 3))
Example #4
0
import unittest
import numpy as np
from numpy.testing import assert_almost_equal, assert_equal
from uravu.distribution import Distribution
import scipy.stats
from uravu.axis import Axis
from scipy.stats import norm, uniform, gaussian_kde

DISTRO1 = Distribution(
    norm.rvs(loc=0, scale=1, size=10000,
             random_state=np.random.RandomState(1)))
DISTRO2 = Distribution(
    norm.rvs(loc=1, scale=1, size=10000,
             random_state=np.random.RandomState(2)))
AX = Axis([DISTRO1, DISTRO2])

AX_ARRAY = Axis([0, 1])


class TestDistribution(unittest.TestCase):
    """
    Testing the Axis class.
    """
    def test_init_values(self):
        assert_equal(AX.values[0].samples, DISTRO1.samples)
        assert_equal(AX.values[1].samples, DISTRO2.samples)

    def test_init_kde(self):
        assert_equal(isinstance(AX.kde, gaussian_kde), True)