Beispiel #1
0
    def __init__(self, layer_sizes, mean_y_train, std_y_train, task):

        var_targets = 1
        self.std_y_train = std_y_train
        self.mean_y_train = mean_y_train

        # We initialize the prior

        self.prior = prior.Prior(layer_sizes, var_targets)

        # We create the network

        params = self.prior.get_initial_params()
        self.network = network.Network(params['m_w'],
                                       params['v_w'],
                                       params['a'],
                                       params['b'],
                                       task=task)

        # We create the input and output variables in theano

        self.x = T.vector('x')
        self.y = T.scalar('y')

        # A function for computing the value of logZ, logZ1 and logZ2

        self.logZ, self.logZ1, self.logZ2 = \
            self.network.logZ_Z1_Z2(self.x, self.y)

        # We create a theano function for updating the posterior

        self.adf_update = theano.function(
            [self.x, self.y],
            self.logZ,
            updates=self.network.generate_updates(self.logZ, self.logZ1,
                                                  self.logZ2))

        # We greate a theano function for the network predictive distribution

        self.predict_probabilistic = theano.function(
            [self.x], self.network.output_probabilistic(self.x))

        self.predict_deterministic = theano.function(
            [self.x], self.network.output_deterministic(self.x))
Beispiel #2
0
    def __init__(self, t, background, signal, tMax=24.):
        """
        Initialize global variables of ship passing model
    
        Args:
            t (array): times of neutrino detection
            tMax (double): maximum time of simulaton
            expBackground (double): average background rate of neutrino detection
        """

        # Set global variables
        self.ndim = 2
        self.t = t
        self.background = background
        self.signal = signal
        self.tMax = tMax

        # Create an array of ndim Priors
        self.priors = [prior.Prior(0, 1) for i in range(self.ndim)]
Beispiel #3
0
    def __init__(self, array, key):
        """
        This class replaces the old function defined in the Data class, called
        `from_input_to_mcmc_parameters`. The traduction is now done inside the
        Parameter class, which interprets the array given as an input inside
        the parameter file, and returns a dictionary having all relevant fields
        initialized.

        .. warning::

            This used to be an ordered dictionary, for no evident reason. It is
            now reverted back to an ordinary dictionary. If this broke
            anything, it will be reverted back

        At the end of this initialization, every field but one is filled for
        the specified parameter, be it fixed or varying. The missing field is
        the 'last_accepted' one, that will be filled in the module :mod:`mcmc`.

        .. note::

            The syntax of the parameter files is defined here - if one
            wants to change it, one should report the changes in there.

        The other fields are

        Attributes
        ----------
        initial : array
            Initial array of input values defined in the parameter file.
            Contains (in this order) `mean`, `minimum`, `maximum`, `1-sigma`.
            If the min/max values (**TO CHECK** proposal density boundaries)
            are unimportant/unconstrained, use `None` or `-1` (without a period
            !)
        scale : float
            5th entry of the initial array in the parameter file, defines the
            factor with which to multiply the values defined in `initial` to
            give the real value.
        role : str
            6th entry of the initial array, can be `cosmo`, `nuisance` or
            `derived`. A `derived` parameter will not be considered as varying,
            but will be instead recovered from the cosmological code for each
            point in the parameter space.
        prior : :class:`Prior <prior.Prior>`
            defined through the optional 7th entry of the initial array, can be
            ommited or set to `flat` (same), or set to `gaussian`. An instance
            of the :class:`prior` defined in :mod:`prior` will be initialized
            and set to this value.
        tex_name : str
            A tentative tex version of the name, provided by the function
            :func:`io_mp.get_tex_name`.
        status : str
            Depending on the `1-sigma` value in the initial array, it will be
            set to `fixed` or `varying` (resp. zero and non-zero)
        current : float
            Stores the value at the current point in parameter space (`not
            allowed initially`)

        Parameters
        ----------
        value : list
            Array read from the parameter file
        key : str
            Name of the parameter

        """
        # calling the parent method initialization
        dict.__init__(self)

        self['initial'] = array[0:4]
        self['scale'] = array[4]
        self['role'] = array[-1]
        self['tex_name'] = io_mp.get_tex_name(key)
        if array[3] == 0:
            self['status'] = 'fixed'
            self['current'] = array[0]
        else:
            self['status'] = 'varying'
        self['prior'] = prior.Prior(array)
Beispiel #4
0
 def test__equals(self, uniform_simple):
     assert uniform_simple != prior.Prior("two")
     assert uniform_simple == prior.Prior("one")