Exemplo n.º 1
0
 def __init__(self, stochastic, inits=None, kernel_probs=[0.4918, 0.4918, 0.0082, 0.0082], walk_theta=1.5, traverse_theta=6.0, n1=4, support=lambda x: True, verbose=None, tally=True):
     
     # Initialize superclass
     StepMethod.__init__(self, [stochastic], verbose=verbose, tally=tally)
     
     # Ordered list of proposal kernels
     self.kernels = [self.walk, self.traverse, self.blow, self.hop]
     
     # Kernel for current iteration
     self.current_kernel = None
     
     self.accepted = zeros(len(kernel_probs))
     self.rejected = zeros(len(kernel_probs))
     
     # Cumulative kernel probabilities
     self.cum_probs = np.cumsum(kernel_probs)
     
     self.walk_theta = walk_theta
     self.traverse_theta = traverse_theta
     
     # Set public attributes
     self.stochastic = stochastic
     if verbose is not None:
         self.verbose = verbose
     else:
         self.verbose = stochastic.verbose
     
     # Determine size of stochastic
     if isinstance(self.stochastic.value, ndarray):
         self._len = len(self.stochastic.value.ravel())
     else:
         self._len = 1
     
     # Create attribute for holding value and secondary value
     self.values = [self.stochastic.value]
     
     # Initialize to different value from stochastic or supplied values
     if inits is None:
         self.values.append(self.stochastic.random())
         # Reset original value
         self.stochastic.value = self.values[0]
     else:
         self.values.append(inits)
     
     # Flag for using second point in log-likelihood calculations
     self._prime = False
     
     # Proposal adjustment factor for current iteration
     self.hastings_factor = 0.0
     
     # Set probability of selecting any parameter
     self.p = 1.*min(self._len, n1)/self._len
     
     # Support function
     self._support = support
     
     self._state = ['accepted', 'rejected', 'p']
Exemplo n.º 2
0
  def __init__(self, stochastic, w=1, m=20, n_tune=0, verbose=-1, tally=False):
    """ 
    Slice sampler class initialization
    """
    #a Initialize superclass
    StepMethod.__init__(self, [stochastic], tally=tally)

    # id string
    self._id = "Slicer"

    # Set public attributes
    self.stochastic = stochastic
    if verbose > -1:
      self.verbose = verbose
    else:
      self.verbose = stochastic.verbose

    self.w_tune = []
    self.n_tune = n_tune
    self._tuning_info = ["w_tune", "n_tune"]
    self.w = w
    self.m = m