示例#1
0
    def __init__(self, name='AP4'):
        """ Initialize EOS instance with interp1d from scipy.interpolate
        """
        if not name in EOS_NAMES:
            print(' <<< EOS %s not found >>> ' % name)

        self.name = name
        self.mB = 1.660538921e-24  # g

        dat = np.genfromtxt('/Users/yonggao/Desktop/scalarized_ns/code/EOS/' +
                            name + '.txt')
        self.rho, self.p, self.e = dat[:, 0], dat[:, 1], dat[:, 2]
        self.min_rho = np.min(self.rho)
        self.max_rho = np.max(self.rho)
        self.min_p = np.min(self.p)
        self.max_p = np.max(self.p)
        self.min_e = np.min(self.e)
        self.max_e = np.max(self.e)
        self.min_n = self.rho2n(self.min_rho)
        self.max_n = self.rho2n(self.max_rho)

        lgrho, lgp, lge = lg(self.rho), lg(self.p), lg(self.e)
        self.lgrho2lgp = sp_interp1d(lgrho, lgp)
        self.lgrho2lge = sp_interp1d(lgrho, lge)
        self.lgp2lgrho = sp_interp1d(lgp, lgrho)
        self.lgp2lge = sp_interp1d(lgp, lge)
        self.lge2lgp = sp_interp1d(lge, lgp)
        self.lge2lgrho = sp_interp1d(lge, lgrho)
示例#2
0
def calculating_h(T, M1, M2, d1, d2, Ecv, p):
    Ea = 1.5 * k * T
    avg_share_transmit_energy = (4 * M1 * M2) / ((M1 + M2)**2)
    E02 = Ecv / 2
    Lambda = (4 * k1 * T) / ((pi * (d1 + d2)**2) * p * (1 + M2 / M1)**0.5)
    Nk = lg(Ea / E02) / lg(1 - avg_share_transmit_energy)
    Lk = Lambda * Nk
    # h = round(Lk * 100, 1) #cm
    return Lambda, Lk
示例#3
0
def main():
    points=np.array([[0,0],[2,0],[3,0],[0,2],[0,-3],[7,0],[7,3],[7,1],[7,-2],[9,-1]],dtype=float)
    print 'Input point cloud:\n'
    print points
    print '\nDiameter of point cloud:\t'+str(max(dmatrix))+'\n'
    link=linkage(points) #linkage can also take the output of pdist(points) -- a flattened distance matrix -- as it input
    root=linkage_to_dendrogram(link)
    maxbits=lg(root.card())
    print 'Minimal spanning tree edges from given list of points:\n'
    print minimum_spanning_tree(csr_matrix(squareform(dmatrix))).todok().keys()
    print '\n'
    print 'Minimal spanning tree midpoints from given list of points:\n'
    print bridges(points,'elltwo')
    print '\n\n'
    print 'Producing dendrogram from linkage matrix:\n'
    print root
    print root.heights()
    
    print 'The entropy of this dendrogram is: '+str(root.entropy())+', which is about'+str(np.floor(100*root.entropy()/maxbits))+'\% of max entropy\n\n'
    print '\n\nNow combing the dendrogram:\n'
    root.comb()
    print root
    print root.heights()
    print 'The entropy of the combed dendrogram is: '+str(root.entropy())+', which is about'+str(np.floor(100*root.entropy()/maxbits))+'\% of max entropy\n\n'
    print 'Here are some slices of the dendrogram:\n'
    print 'At height 5: '
    print root.slice(4)
    print double(root.slice_incidence_matrix(4))
    print double(root.clusters_incidence_matrix())
    print 'At height 3.5: '
    print root.slice(2.5)
    print double(root.slice_incidence_matrix(2.5))
    print double(root.clusters_incidence_matrix())
    print 'At height 1.5: '
    print root.slice(.5)
    print double(root.slice_incidence_matrix(.5))
    print double(root.clusters_incidence_matrix())

    res=[1,3,4,5,6,7,9]
    print '\nRestriction to '+str(res)+' yields the dendrogram:\n'
    new_root=root.restricted(res)
    print new_root
    print new_root.heights()

    delta=1.8
    print '\nTruncation at delta='+str(delta)+' yields the dendrogram:\n'
    trunc_root=root.truncated(delta)
    print trunc_root
    print trunc_root.heights()
    print trunc_root.slice(0)
    print double(trunc_root.slice_incidence_matrix(0))
    print double(trunc_root.clusters_incidence_matrix())


    x=np.array([1,0,2,3,0,0,4,0,0,5,6])
    print x
    choose_half(x)
    print x
示例#4
0
 def entropy(self):
     return (1./self.card()) * sum( (child.card() * child.entropy() - (child.card()-1.) * (lg(child.card())-lg(self.card()))) for child in self._children )
示例#5
0
 def p2e(self, p):
     if p < self.min_p:
         return 1.0e-9
     return 10.0**self.lgp2lge(lg(p))
示例#6
0
 def p2rho(self, p):
     return 10.0**self.lgp2lgrho(lg(p))
示例#7
0
 def rho2e(self, rho):
     return 10.0**self.lgrho2lge(lg(rho))
示例#8
0
 def rho2p(self, rho):
     return 10.0**self.lgrho2lgp(lg(rho))
示例#9
0
 def e2rho(self, e):
     if e < self.min_e:
         return 1.0e-9
     return 10.0**self.lge2lgrho(lg(e))
示例#10
0
 def e2p(self, e):
     if e < self.min_e:
         return 1.0e-9
     return 10.0**self.lge2lgp(lg(e))