Exemplo n.º 1
0
    def create_chains(self, nchains, betas, swap_interval=1):
        """Creates a list of :py:class:`chain.ParallelTemperedChain`.

        Parameters
        ----------
        nchains : int
            The number of parallel tempered chains to create.
        betas : array
            Array of inverse temperatures to use for each parallel tempered
            chain.
        swap_interval : int, optional
            How often to calculate temperature swaps. Default is 1 (= swap on
            every iteration).
        """
        if nchains < 1:
            raise ValueError("nchains must be >= 1")
        self._chains = [
            ParallelTemperedChain(
                self.parameters,
                self.model, [copy.deepcopy(p) for p in self.proposals],
                betas=betas,
                swap_interval=swap_interval,
                bit_generator=create_bit_generator(self.seed, stream=cid),
                chain_id=cid) for cid in range(nchains)
        ]
Exemplo n.º 2
0
 def bit_generator(self):
     """The random bit generator instance being used.
     """
     try:
         return self._bit_generator
     except AttributeError:
         self._bit_generator = epsie.create_bit_generator()
         return self._bit_generator
Exemplo n.º 3
0
Arquivo: base.py Projeto: ahnitz/epsie
    def bit_generator(self):
        """The random bit generator instance being used.

        A bit generator will be created if it doesn't exist yet.
        """
        try:
            return self._bit_generator
        except AttributeError:
            self._bit_generator = epsie.create_bit_generator()
            return self._bit_generator
Exemplo n.º 4
0
Arquivo: base.py Projeto: ahnitz/epsie
    def bit_generator(self, bit_generator):
        """Sets the random bit generator.

        Parameters
        ----------
        bit_generator : :py:class:`epsie.BIT_GENERATOR`, int, or None
            Either the bit generator to use or an integer/None. If the latter,
            a generator will be created by passing ``bit_generator`` as the
            ``seed`` argument to :py:func:`epsie.create_bit_generator`.
        """
        if not isinstance(bit_generator, epsie.BIT_GENERATOR):
            bit_generator = epsie.create_bit_generator(bit_generator)
        self._bit_generator = bit_generator
Exemplo n.º 5
0
    def bit_generator(self, bit_generator=None):
        """Sets the random bit generator

        Parameters
        ----------
        bit_generator : :py:class:`epsie.BIT_GENERATOR` instance, optional
            Use the given random bit generator for generating random variates.
            If an int or None is provided, a generator will be created instead
            using ``bit_generator`` as a seed.
        """
        if bit_generator is None:
            bit_generator = epsie.create_bit_generator(None,
                                                       stream=self.chain_id)
        self._bit_generator = bit_generator
Exemplo n.º 6
0
    def create_chains(self, nchains):
        """Creates a list of :py:class:`chain.Chain`.

        Parameters
        ----------
        nchains : int
            The number of Markov chains to create.
        """
        if nchains < 1:
            raise ValueError("nchains must be >= 1")
        self._chains = [
            Chain(self.parameters,
                  self.model, [copy.deepcopy(p) for p in self.proposals],
                  bit_generator=create_bit_generator(self.seed, stream=cid),
                  chain_id=cid) for cid in range(nchains)
        ]