Exemplo n.º 1
0
    def sample(self,
               iter,
               burn=0,
               thin=1,
               tune_interval=1000,
               save_interval=None,
               verbose=0):
        """
        sample(iter, burn, thin, tune_interval, save_interval, verbose)

        Initialize traces, run sampling loop, clean up afterward. Calls _loop.
        """

        self.assign_step_methods()

        if burn >= iter:
            raise ValueError, 'Burn interval must be smaller than specified number of iterations.'
        self._iter = int(iter)
        self._burn = int(burn)
        self._thin = int(thin)
        self._tune_interval = int(tune_interval)
        self._save_interval = save_interval

        length = int(np.ceil((1.0 * iter - burn) / thin))
        self.max_trace_length = length

        # Flags for tuning
        self._tuning = True
        self._tuned_count = 0

        Sampler.sample(self, iter, length, verbose)
Exemplo n.º 2
0
    def sample(
        self,
        iter,
        burn=0,
        thin=1,
        tune_interval=1000,
        tune_throughout=True,
        save_interval=None,
        verbose=0,
        progress_bar=True,
    ):
        """
        sample(iter, burn, thin, tune_interval, tune_throughout, save_interval, verbose)
        
        Initialize traces, run sampling loop, clean up afterward. Calls _loop.
        
        :Parameters:
          - iter : int
            Total number of iterations to do
          - burn : int
            Variables will not be tallied until this many iterations are complete, default 0
          - thin : int
            Variables will be tallied at intervals of this many iterations, default 1
          - tune_interval : int
            Step methods will be tuned at intervals of this many iterations, default 1000
          - tune_throughout : boolean
            If true, tuning will continue after the burnin period (True); otherwise tuning
            will halt at the end of the burnin period.
          - save_interval : int or None
            If given, the model state will be saved at intervals of this many iterations
          - verbose : boolean
        """

        self.assign_step_methods(verbose=verbose)

        if burn >= iter:
            raise ValueError, "Burn interval must be smaller than specified number of iterations."
        self._iter = int(iter)
        self._burn = int(burn)
        self._thin = int(thin)
        self._tune_interval = int(tune_interval)
        self._tune_throughout = tune_throughout
        self._save_interval = save_interval

        length = max(int(np.floor((1.0 * iter - burn) / thin)), 1)
        self.max_trace_length = length

        # Flags for tuning
        self._tuning = True
        self._tuned_count = 0

        # Progress bar
        self.pbar = None
        if not verbose and progress_bar:
            widgets = ["Sampling: ", Percentage(), " ", Bar(marker="0", left="[", right="]"), " ", Iterations()]
            self.pbar = ProgressBar(widgets=widgets, maxval=self._iter)

        # Run sampler
        Sampler.sample(self, iter, length, verbose)
Exemplo n.º 3
0
    def sample(self,
               iter,
               burn=0,
               thin=1,
               tune_interval=1000,
               tune_throughout=True,
               save_interval=None,
               verbose=0):
        """
        sample(iter, burn, thin, tune_interval, tune_throughout, save_interval, verbose)

        Initialize traces, run sampling loop, clean up afterward. Calls _loop.

        :Parameters:
          - iter : int
            Total number of iterations to do
          - burn : int
            Variables will not be tallied until this many iterations are complete, default 0
          - thin : int
            Variables will be tallied at intervals of this many iterations, default 1
          - tune_interval : int
            Step methods will be tuned at intervals of this many iterations, default 1000
          - tune_throughout : boolean
            If true, tuning will continue after the burnin period (True); otherwise tuning
            will halt at the end of the burnin period.
          - save_interval : int or None
            If given, the model state will be saved at intervals of this many iterations
          - verbose : boolean
        """

        self.assign_step_methods()

        if burn >= iter:
            raise ValueError, 'Burn interval must be smaller than specified number of iterations.'
        self._iter = int(iter)
        self._burn = int(burn)
        self._thin = int(thin)
        self._tune_interval = int(tune_interval)
        self._tune_throughout = tune_throughout
        self._save_interval = save_interval

        length = int(np.ceil((1.0 * iter - burn) / thin))
        self.max_trace_length = length

        # Flags for tuning
        self._tuning = True
        self._tuned_count = 0

        Sampler.sample(self, iter, length, verbose)
Exemplo n.º 4
0
    def sample(self, iter, burn=0, thin=1, tune_interval=1000, tune_throughout=True, save_interval=None, verbose=0):
        """
        sample(iter, burn, thin, tune_interval, tune_throughout, save_interval, verbose)

        Initialize traces, run sampling loop, clean up afterward. Calls _loop.

        :Parameters:
          - iter : int
            Total number of iterations to do
          - burn : int
            Variables will not be tallied until this many iterations are complete, default 0
          - thin : int
            Variables will be tallied at intervals of this many iterations, default 1
          - tune_interval : int
            Step methods will be tuned at intervals of this many iterations, default 1000
          - tune_throughout : boolean
            If true, tuning will continue after the burnin period (True); otherwise tuning
            will halt at the end of the burnin period.
          - save_interval : int or None
            If given, the model state will be saved at intervals of this many iterations
          - verbose : boolean
        """

        self.assign_step_methods()

        if burn >= iter:
            raise ValueError, 'Burn interval must be smaller than specified number of iterations.'
        self._iter = int(iter)
        self._burn = int(burn)
        self._thin = int(thin)
        self._tune_interval = int(tune_interval)
        self._tune_throughout = tune_throughout
        self._save_interval = save_interval

        length = int(np.ceil((1.0*iter-burn)/thin))
        self.max_trace_length = length

        # Flags for tuning
        self._tuning = True
        self._tuned_count = 0

        Sampler.sample(self, iter, length, verbose)
Exemplo n.º 5
0
    def sample(self,
               iter,
               burn=0,
               thin=1,
               tune_interval=1000,
               tune_throughout=True,
               save_interval=None,
               verbose=0,
               progress_bar=True):
        """
        sample(iter, burn, thin, tune_interval, tune_throughout, save_interval, verbose)
        
        Initialize traces, run sampling loop, clean up afterward. Calls _loop.
        
        :Parameters:
          - iter : int
            Total number of iterations to do
          - burn : int
            Variables will not be tallied until this many iterations are complete, default 0
          - thin : int
            Variables will be tallied at intervals of this many iterations, default 1
          - tune_interval : int
            Step methods will be tuned at intervals of this many iterations, default 1000
          - tune_throughout : boolean
            If true, tuning will continue after the burnin period (True); otherwise tuning
            will halt at the end of the burnin period.
          - save_interval : int or None
            If given, the model state will be saved at intervals of this many iterations
          - verbose : boolean
        """

        self.assign_step_methods(verbose=verbose)

        if burn >= iter:
            raise ValueError, 'Burn interval must be smaller than specified number of iterations.'
        self._iter = int(iter)
        self._burn = int(burn)
        self._thin = int(thin)
        self._tune_interval = int(tune_interval)
        self._tune_throughout = tune_throughout
        self._save_interval = save_interval

        length = max(int(np.floor((1.0 * iter - burn) / thin)), 1)
        self.max_trace_length = length

        # Flags for tuning
        self._tuning = True
        self._tuned_count = 0

        # Progress bar
        self.pbar = None
        if not verbose and progress_bar:
            widgets = [
                'Sampling: ',
                Percentage(), ' ',
                Bar(marker='0', left='[', right=']'), ' ',
                Iterations()
            ]
            self.pbar = ProgressBar(widgets=widgets, maxval=self._iter)

        # Run sampler
        Sampler.sample(self, iter, length, verbose)