Ejemplo n.º 1
0
 def __init__(self, data, nbins=None, qpts=None):
     """
     Initialize a piecewise-constant model, copying the data, and optionally
     setting the number of bins for the PC model, and
     the number of points for a quadrature marginalizing over phase
     (these can be altered after initialization).  qpts=0 results in an
     exact calculation.
     """
     if len(data.shape) != 1:
         raise ValueError('Input must be 1-d float array!')
     self.data = data.copy()
     self.ndata = len(data)
     self.lndfac = gammaln(self.ndata+1)
     if qpts is None:
         self.qpts = None
         self.absc = None
     elif qpts >= 0:
         self.qpts = qpts
         if nbins and qpts > 0:
             # This depends on nbins b/c we integ. over one bin width.
             self.absc = gl.trap_absc(qpts, nbins)
         else:
             self.absc = None
     else:
         raise ValueError('qpts must be a positive integer!')
     if nbins is not None:
         self.set_nbins(nbins)
     else:
         self.bins = None
     self.offset = None # Offset for logs to avoid over/underflow
     self.w = None
     self.wdot = 0.
     self.wddot = 0.
     self.phases = zeros(len(data))
Ejemplo n.º 2
0
 def __init__(self, data, nbins=None, qpts=None):
     """
     Initialize a piecewise-constant model, copying the data, and optionally
     setting the number of bins for the PC model, and
     the number of points for a quadrature marginalizing over phase
     (these can be altered after initialization).  qpts=0 results in an
     exact calculation.
     """
     if len(data.shape) != 1:
         raise ValueError, 'Input must be 1-d float array!'
     self.data = data.copy()
     self.ndata = len(data)
     self.lndfac = gammaln(self.ndata+1)
     if qpts is None:
         self.qpts = None
         self.absc = None
     elif qpts >= 0:
         self.qpts = qpts
         if nbins and qpts > 0:
             # This depends on nbins b/c we integ. over one bin width.
             self.absc = gl.trap_absc(qpts, nbins)
         else:
             self.absc = None
     else:
         raise ValueError, 'qpts must be a positive integer!'
     if nbins is not None:
         self.set_nbins(nbins)
     else:
         self.bins = None
     self.offset = None # Offset for logs to avoid over/underflow
     self.w = None
     self.wdot = 0.
     self.wddot = 0.
     self.phases = zeros(len(data))
Ejemplo n.º 3
0
 def set_qpts(self, n):
     if n >= 0:
         self.qpts = n
         if self.nbins and n > 0:
             self.absc = gl.trap_absc(n, self.nbins)
         else:
             self.absc = None
     else:
         raise ValueError('qpts must be a positive integer!')
Ejemplo n.º 4
0
 def set_qpts(self, n):
     if n >= 0:
         self.qpts = n
         if self.nbins and n > 0:
             self.absc = gl.trap_absc(n, self.nbins)
         else:
             self.absc = None
     else:
         raise ValueError, 'qpts must be a positive integer!'
Ejemplo n.º 5
0
 def set_nbins(self, nbins):
     """Set the number of bins for the piecewise-constant rate model."""
     self.nbins = nbins
     self.bins = zeros(nbins, int)  # For storing event counts
     # *** Rewrite .f so these two could be replaced by one call.
     self.phibins = zeros(nbins)
     gl.binbounds(self.phibins)  # Phase boundaries for bins
     self.offset = None
     # nbins-dependent part of the Ockham factor:
     self.logbfac = gammaln(nbins) + self.ndata*log(nbins) + \
                    gammaln(self.ndata+1) - gammaln(self.ndata+nbins)
     if self.qpts > 0:
         self.absc = gl.trap_absc(self.qpts, nbins)
     else:
         self.absc = None
Ejemplo n.º 6
0
 def set_nbins(self, nbins):
     """Set the number of bins for the piecewise-constant rate model."""
     self.nbins = nbins
     self.bins = zeros(nbins, int)  # For storing event counts
     # *** Rewrite .f so these two could be replaced by one call.
     self.phibins = zeros(nbins)
     gl.binbounds(self.phibins)  # Phase boundaries for bins
     self.offset = None
     # nbins-dependent part of the Ockham factor:
     self.logbfac = gammaln(nbins) + self.ndata*log(nbins) + \
                    gammaln(self.ndata+1) - gammaln(self.ndata+nbins)
     if self.qpts > 0:
         self.absc = gl.trap_absc(self.qpts, nbins)
     else:
         self.absc = None