def __init__(self, log_pdf, xlo, xhi, nx, ylo, yhi, ny, xstep='linear', ystep='linear'): self.log_pdf = log_pdf self.xlo, self.xhi = xlo, xhi self.nx = nx if xstep == 'linear' or xstep == 'lin': self.xlinstep = True self.xvals = array([x for x in lin_stepper(xlo, xhi, self.nx)]) self.dx = (xhi - xlo) / (self.nx - 1) elif xstep == 'log' or xstep == 'logarithmic': self.xlinstep = False self.xvals = array([x for x in log_stepper(xlo, xhi, self.nx)]) self.dx = log(xhi / xlo) / (self.nx - 1) else: raise ValueError('Invalid xstep type!') self.ylo, self.yhi = ylo, yhi self.ny = ny if ystep == 'linear' or ystep == 'lin': self.ylinstep = True self.yvals = array([y for y in lin_stepper(ylo, yhi, self.ny)]) self.dy = (yhi - ylo) / (self.ny - 1) elif ystep == 'log' or ystep == 'logarithmic': self.ylinstep = False self.yvals = array([y for y in log_stepper(ylo, yhi, self.ny)]) self.dy = log(yhi / ylo) / (self.ny - 1) else: raise ValueError('Invalid ystep type!') logpdf = zeros((nx, ny), float) for i, x in enumerate(self.xvals): for j, y in enumerate(self.yvals): logpdf[i, j] = log_pdf(x, y) self.logpdf = logpdf self.max = logpdf.max() self.spdf = exp(logpdf - self.max) # Scaled PDF # For log steps, change variables to log(x or y). if not self.xlinstep: for i, x in enumerate(self.xvals): self.spdf[i, :] = self.spdf[i, :] * x if not self.ylinstep: for j, y in enumerate(self.yvals): self.spdf[:, j] = self.spdf[:, j] * y # Find the overall normalization for spdf. self.norm = qgt2d(self.spdf, self.spdf.min()) * self.dx * self.dy # lml is the log marginal likelihood if logpdf = prior*like. self.lml = log(self.norm) + self.max self.probs = [] self.deltas = [] self.levels = []
def __init__(self, log_pdf, xlo, xhi, nx, ylo, yhi, ny, xstep='linear', ystep='linear'): self.log_pdf = log_pdf self.xlo, self.xhi = xlo, xhi self.nx = nx if xstep == 'linear' or xstep=='lin': self.xlinstep = True self.xvals = array( [x for x in lin_stepper(xlo, xhi, self.nx)] ) self.dx = (xhi-xlo)/(self.nx-1) elif xstep=='log' or xstep=='logarithmic': self.xlinstep = False self.xvals = array( [x for x in log_stepper(xlo, xhi, self.nx)] ) self.dx = log(xhi/xlo)/(self.nx-1) else: raise ValueError, 'Invalid xstep type!' self.ylo, self.yhi = ylo, yhi self.ny = ny if ystep == 'linear' or ystep=='lin': self.ylinstep = True self.yvals = array( [y for y in lin_stepper(ylo, yhi, self.ny)] ) self.dy = (yhi-ylo)/(self.ny-1) elif ystep=='log' or ystep=='logarithmic': self.ylinstep = False self.yvals = array( [y for y in log_stepper(ylo, yhi, self.ny)] ) self.dy = log(yhi/ylo)/(self.ny-1) else: raise ValueError, 'Invalid ystep type!' logpdf = zeros((nx, ny), float) for i,x in enumerate(self.xvals): for j,y in enumerate(self.yvals): logpdf[i,j] = log_pdf(x,y) self.logpdf = logpdf self.max = logpdf.max() self.spdf = exp(logpdf-self.max) # Scaled PDF # For log steps, change variables to log(x or y). if not self.xlinstep: for i, x in enumerate(self.xvals): self.spdf[i,:] = self.spdf[i,:]*x if not self.ylinstep: for j, y in enumerate(self.yvals): self.spdf[:,j] = self.spdf[:,j]*y # Find the overall normalization for spdf. self.norm = qgt2d(self.spdf, self.spdf.min())*self.dx*self.dy # lml is the log marginal likelihood if logpdf = prior*like. self.lml = log(self.norm) + self.max self.probs = [] self.deltas = [] self.levels = []
def __init__(self, log_pdf, xlo, xhi, nx, step='linear'): """ Initialize the HPDGrid1D object. :Parameters: log_pdf : float function of scalar argument Function returning log pdf value log_pdf(x) xlo, xhi : float Range spanned by logpdf nx : int Number of points in the logpdf grid step : 'linear' OR 'lin' OR 'logarithmic' OR 'log' 'linear' for a grid linear in x; 'log' for a grid linear in log(x) """ self.log_pdf = log_pdf xlo, xhi = float(xlo), float(xhi) self.xlo, self.xhi = xlo, xhi self.nx = nx if step == 'linear' or step=='lin': self.linstep = True self.xvals = array( [x for x in lin_stepper(xlo, xhi, self.nx)] ) self.dx = (xhi-xlo)/(self.nx-1) elif step=='log' or step=='logarithmic': self.linstep = False self.xvals = [x for x in log_stepper(xlo, xhi, self.nx)] self.dx = log(xhi/xlo)/(self.nx-1) else: raise ValueError, 'Invalid step type!' logpdf = zeros(nx, float) for i, x in enumerate(self.xvals): logpdf[i] = log_pdf(x) self.logpdf = logpdf self.max = logpdf.max() self.spdf = exp(logpdf-self.max) # scaled PDF # For log steps, change variables to log(x). if not self.linstep: for i, x in enumerate(self.xvals): self.spdf[i] = self.spdf[i]*x # Find the overall normalization for spdf. self.snorm = qgt1d(self.spdf, self.spdf.min())*self.dx # lml is the log marginal likelihood if logpdf = prior*like. self.lml = log(self.snorm) + self.max self.probs = [] self.deltas = [] self.levels = [] self.bounds = []
def __init__(self, log_pdf, xlo, xhi, nx, step='linear'): """ Initialize the HPDGrid1D object. :Parameters: log_pdf : float function of scalar argument Function returning log pdf value log_pdf(x) xlo, xhi : float Range spanned by logpdf nx : int Number of points in the logpdf grid step : 'linear' OR 'lin' OR 'logarithmic' OR 'log' 'linear' for a grid linear in x; 'log' for a grid linear in log(x) """ self.log_pdf = log_pdf xlo, xhi = float(xlo), float(xhi) self.xlo, self.xhi = xlo, xhi self.nx = nx if step == 'linear' or step == 'lin': self.linstep = True self.xvals = array([x for x in lin_stepper(xlo, xhi, self.nx)]) self.dx = (xhi - xlo) / (self.nx - 1) elif step == 'log' or step == 'logarithmic': self.linstep = False self.xvals = [x for x in log_stepper(xlo, xhi, self.nx)] self.dx = log(xhi / xlo) / (self.nx - 1) else: raise ValueError('Invalid step type!') logpdf = zeros(nx, float) for i, x in enumerate(self.xvals): logpdf[i] = log_pdf(x) self.logpdf = logpdf self.max = logpdf.max() self.spdf = exp(logpdf - self.max) # scaled PDF # For log steps, change variables to log(x). if not self.linstep: for i, x in enumerate(self.xvals): self.spdf[i] = self.spdf[i] * x # Find the overall normalization for spdf. self.snorm = qgt1d(self.spdf, self.spdf.min()) * self.dx # lml is the log marginal likelihood if logpdf = prior*like. self.lml = log(self.snorm) + self.max self.probs = [] self.deltas = [] self.levels = [] self.bounds = []
def __init__(self, logpdf, xlo, xhi, step='linear'): """ Initialize the HPDGrid1D object. :Parameters: logpdf : float array Array of log pdf values xlo, xhi : float Range spanned by logpdf step : 'linear' OR 'lin' OR 'logarithmic' OR 'log' 'linear' for a grid linear in x; 'log' for a grid linear in log(x) """ if len(logpdf.shape) != 1: raise ValueError('logpdf array must be 1-d!') self.logpdf = logpdf self.xlo, self.xhi = xlo, xhi self.nx = logpdf.shape[0] if step == 'linear' or step == 'lin': self.linstep = True self.xvals = array([x for x in lin_stepper(xlo, xhi, self.nx)]) self.dx = (xhi-xlo)/(self.nx-1.) elif step == 'log' or step == 'logarithmic': self.linstep = False self.xvals = [x for x in log_stepper(xlo, xhi, self.nx)] self.dx = log(xhi/xlo)/(self.nx-1) else: raise ValueError('Invalid step type!') self.max = logpdf.max() self.spdf = exp(logpdf-self.max) # scaled PDF # For log steps, change variables to log(x). if not self.linstep: for i, x in enumerate(self.xvals): self.spdf[i] = self.spdf[i]*x # Find the overall normalization for spdf. self.snorm = qgt1d(self.spdf, self.spdf.min())*self.dx # lml is the log marginal likelihood if logpdf = prior*like. self.lml = log(self.snorm) + self.max self.probs = [] self.deltas = [] self.levels = [] self.bounds = []
def __init__(self, logpdf, xlo, xhi, step='linear'): """ Initialize the HPDGrid1D object. :Parameters: logpdf : float array Array of log pdf values xlo, xhi : float Range spanned by logpdf step : 'linear' OR 'lin' OR 'logarithmic' OR 'log' 'linear' for a grid linear in x; 'log' for a grid linear in log(x) """ if len(logpdf.shape) != 1: raise ValueError, 'logpdf array must be 1-d!' self.logpdf = logpdf self.xlo, self.xhi = xlo, xhi self.nx = logpdf.shape[0] if step == 'linear' or step=='lin': self.linstep = True self.xvals = array( [x for x in lin_stepper(xlo, xhi, self.nx)] ) self.dx = (xhi-xlo)/(self.nx-1.) elif step=='log' or step=='logarithmic': self.linstep = False self.xvals = [x for x in log_stepper(xlo, xhi, self.nx)] self.dx = log(xhi/xlo)/(self.nx-1) else: raise ValueError, 'Invalid step type!' self.max = logpdf.max() self.spdf = exp(logpdf-self.max) # scaled PDF # For log steps, change variables to log(x). if not self.linstep: for i, x in enumerate(self.xvals): self.spdf[i] = self.spdf[i]*x # Find the overall normalization for spdf. self.snorm = qgt1d(self.spdf, self.spdf.min())*self.dx # lml is the log marginal likelihood if logpdf = prior*like. self.lml = log(self.snorm) + self.max self.probs = [] self.deltas = [] self.levels = [] self.bounds = []