Ejemplo n.º 1
0
 def mse_qreg(self, scale,dof,lrt,base):                        
     '''
     For debugging: returns mse for particular scale and dof, given pre-filtered lrt
     '''        
     p = st.chi2.sf(lrt/scale, dof)            
     logp = sp.logn(base,p)
     r = sp.logn(base,self.qnulllrtsort[0:len(lrt)])-logp
     mse = (r*r).mean()                
     return mse
Ejemplo n.º 2
0
    def scale_dof_obj(self,scale,dof):            
        base=sp.exp(1) #fitted params are invariant to this logarithm base (i.e.10, or e)
        
        nfalse=(len(self.alteqnull)-sp.sum(self.alteqnull))

        imax = int(sp.ceil(self.qmax*nfalse))  #of only non zer dof component
        p = st.chi2.sf(self.lrtsort[0:imax]/scale, dof)            
        logp = sp.logn(base,p)
        r = sp.logn(base,self.qnulllrtsort[0:imax])-logp
        if self.abserr:
            err=sp.absolute(r).sum()            
        else:#mean square error
            err = (r*r).mean()              
        return err,imax
Ejemplo n.º 3
0
def symmetric_central_dense_grid(central_length, total_length, min_ds, max_ds,
                                 max_ratio):
    n_center = int(central_length / min_ds)
    n_float = sc.logn(max_ratio, max_ds / min_ds)
    n_geo = int(n_float + 1)
    ratio = (max_ds / min_ds)**(1. / n_geo)

    inc_geo_ds = np.array([min_ds * ratio**idx for idx in xrange(n_geo)])
    dec_geo_ds = inc_geo_ds[::-1]

    geo_length = min_ds * (ratio**n_geo - 1) / (ratio - 1)

    res_length = 0.5 * (total_length - central_length) - geo_length

    n_res = int(res_length / max_ds + 1)

    n_total = n_center + 2 * (n_geo + n_res)

    grid = np.ones(n_total, dtype=np.float64) * min_ds

    indices = np.array([0, n_res, n_geo, n_center, n_geo, n_res]).cumsum()

    grid[indices[0]:indices[1]] = max_ds
    grid[indices[1]:indices[2]] = dec_geo_ds
    grid[indices[2]:indices[3]] = min_ds
    grid[indices[3]:indices[4]] = inc_geo_ds
    grid[indices[4]:indices[5]] = max_ds

    return grid
Ejemplo n.º 4
0
def to_real_page_ranks(vector):
    """Scales the items in the vector to page-rank log-scale from 1 to 10"""
    minimum = min(vector)
    maximum = max(vector)
    span = maximum - minimum
    scale_span = pow(5, 9)  # the importance difference between PR 1 and PR 10
    return [1 + sp.logn(5, 1 + scale_span*(float(v) - minimum)/span) for v in vector]
Ejemplo n.º 5
0
def gettests(L, P, C):
    tests = scipy.logn(C,float(P)/L)
    
    num = scipy.log2(tests)
    if num%1.>0.:
      num +=1
    if num<0:
      num = 0.

    return long(num)
 def define_bins(self, **kwargs):
     r"""
     This defines the bins for a logscaled histogram
     """
     self.data_vector.sort()
     sf = self.args['scale_fact']
     num_bins = int(sp.logn(sf, self.data_vector[-1]) + 1)
     #
     # generating initial bins from 1 - sf**num_bins
     low = list(sp.logspace(0, num_bins, num_bins + 1, base=sf))[:-1]
     high = list(sp.logspace(0, num_bins, num_bins + 1, base=sf))[1:]
     #
     # Adding "catch all" bins for anything between 0 - 1 and less than 0
     if self.data_vector[0] < 1.0:
         low.insert(0, 0.0)
         high.insert(0, 1.0)
     if self.data_vector[0] < 0.0:
         low.insert(0, self.data_vector[0])
         high.insert(0, 0.0)
     #
     self.bins = [bin_ for bin_ in zip(low, high)]
Ejemplo n.º 7
0
 def define_bins(self, **kwargs):
     r"""
     This defines the bins for a logscaled histogram
     """
     self.data_vector.sort()
     sf = self.args['scale_fact']
     num_bins = int(sp.logn(sf, self.data_vector[-1]) + 1)
     #
     # generating initial bins from 1 - sf**num_bins
     low = list(sp.logspace(0, num_bins, num_bins + 1, base=sf))[:-1]
     high = list(sp.logspace(0, num_bins, num_bins + 1, base=sf))[1:]
     #
     # Adding "catch all" bins for anything between 0 - 1 and less than 0
     if self.data_vector[0] < 1.0:
         low.insert(0, 0.0)
         high.insert(0, 1.0)
     if self.data_vector[0] < 0.0:
         low.insert(0, self.data_vector[0])
         high.insert(0, 0.0)
     #
     self.bins = [bin_ for bin_ in zip(low, high)]