Ejemplo n.º 1
0
 def __init__(self, parent, data):
     self.data = data
     self.tool = Mytools()
     self.childNodes = []
     self.parent = parent
     self.childTagName = None
     pass
Ejemplo n.º 2
0
    def rangos(self, Hessii, Etot, n_interv):
        """ 0.5*k*DQ^2 = E_tot"""
        my.hess_check(Hessii)
        d = [dict() for n in range(len(Hessii))]
        DQ = [sqrt(2.0 * Etot / hii) for hii in Hessii]
        n1 = 0
        for bond in self.bonds:
            n2 = 0
            low = self.b0[n1] - DQ[n1]
            interv = 2. * DQ[n1] / float(n_interv)
            for i in range(n_interv):
                rango = (low + i * interv, low + (i + 1) * interv)
                d[n1][rango] = 0
            n1 += 1

        n1 = len(self.b0)
        for ang in self.angles:
            low = self.a0[n1 - len(self.b0)] - DQ[n1]
            interv = 2. * DQ[n1] / float(n_interv)
            for i in range(n_interv):
                rango = (low + i * interv, low + (i + 1) * interv)
                d[n1][rango] = 0
            n1 += 1

        n1 = len(self.b0) + len(self.a0)
        cte = len(self.b0) + len(self.a0)
        for dieh in self.dihedrals:
            low = self.d0[n1 - cte] - DQ[n1]
            interv = 2. * DQ[n1] / float(n_interv)
            for i in range(n_interv):
                rango = (low + i * interv, low + (i + 1) * interv)
                d[n1][rango] = 0
            n1 += 1

        return d
def main():

    datapath = '../TestData/'
    predictionDir = '../Predictions/'
    if not os.path.isdir(predictionDir):
        os.mkdir(predictionDir)
    Single = True
    nbc = 128
    binhalfwins = [2, 3, 4]
    nbc = 128
    lenthresh = 10
    halfwins = [8, 17, 25]
    alpha = 3
    shiftstart = -4
    shiftend = -1
    fileList = os.listdir(datapath)
    siz = 1
    thresh = 0
    samplelist = [files for files in fileList if files.startswith("Sample")]

    for sample in samplelist:
        if Single:
            QuadDir = '{}{}/SpecificQuadDescriptors/'.format(datapath, sample)
        else:
            QuadDir = '{}{}/AllQuadDescriptors/'.format(datapath, sample)
        print 'saving classifction number for', sample
        smp = GestureSample(datapath, sample, training=False)
        Numberofframe = smp.data['numFrames']
        OutDir = '{}ClassifierOutputs/'.format(QuadDir)

        allBinaryLabels = np.zeros((1, Numberofframe))
        ss1 = 0
        for binhalfwin in binhalfwins:
            BinClfFile = BinClfFile = '{}binary_halfwin_{}.mat'.format(
                OutDir, str(binhalfwin))
            BinaryLabels = sio.loadmat(BinClfFile)['frame_label']
            allBinaryLabels += BinaryLabels
            ss1 += 1
        allprobs = np.zeros((20, Numberofframe))
        ss = 0
        for halfwin in halfwins:
            ss += 1
            inFile = '{}Classfication_nbc_{}_halfwin{}.mat'.format(
                OutDir, str(nbc), str(halfwin))
            probabilties = 1 - np.transpose(sio.loadmat(inFile)['frame_probs'])
            allprobs += probabilties
        (r, c) = np.shape(probabilties)
        M = np.zeros((r + 1, c))
        M[:20, :] = allprobs / ss
        #                        M[20,:] = BinaryLabels
        BinaryLabels = mytools.myfilter(allBinaryLabels / ss1, siz, thresh)
        #                        M[20,:] = binprob
        M[20, :] = BinaryLabels
        (p, D) = dpEM(M, alpha)
        (labels, starts, ends) = getLabels(p)
        FinalLabels = refineLabes(labels, starts, ends, M, lenthresh,
                                  Numberofframe, shiftstart, shiftend)

        tempfilename = '../Predictions/{}_prediction.csv'.format(sample)
        mytools.exportPredictions(FinalLabels, tempfilename)
Ejemplo n.º 4
0
 def internas_dihe(self, conex, ndih):
     try:
         self.qt_1 = self.dihedrals
         self.dihedrals = [my.dihedros(self.cart[conex[i][0]-1], self.cart[conex[i][1]-1], \
         self.cart[conex[i][2]-1], self.cart[conex[i][3]-1],self.qt_1[i]) for i in range(ndih)]
     except AttributeError:
         self.qt_1 = [0.0 for w in range(ndih)]
         self.dihedrals = [my.dihedros(self.cart[conex[i][0]-1], self.cart[conex[i][1]-1], \
         self.cart[conex[i][2]-1], self.cart[conex[i][3]-1],self.qt_1[i]) for i in range(ndih)]
def main():
        
    datapath = '../TestData/'
    predictionDir = '../Predictions/'
    if not os.path.isdir(predictionDir):
        os.mkdir(predictionDir)
    Single =True;
    nbc =128
    binhalfwins = [2,3,4];
    nbc =128
    lenthresh = 10
    halfwins = [8,17,25];
    alpha = 3
    shiftstart = -4
    shiftend = -1
    fileList = os.listdir(datapath)
    siz = 1;thresh = 0;
    samplelist=[files for files in fileList if files.startswith("Sample")]  

    for sample in samplelist:
        if Single:
            QuadDir = '{}{}/SpecificQuadDescriptors/'.format(datapath,sample)
        else:
            QuadDir = '{}{}/AllQuadDescriptors/'.format(datapath,sample)
        print 'saving classifction number for',sample
        smp=GestureSample(datapath,sample,training = False);
        Numberofframe = smp.data['numFrames'];
        OutDir = '{}ClassifierOutputs/'.format(QuadDir)

        allBinaryLabels = np.zeros((1,Numberofframe))
        ss1=0
        for binhalfwin in binhalfwins:
            BinClfFile = BinClfFile = '{}binary_halfwin_{}.mat'.format(OutDir,str(binhalfwin))
            BinaryLabels = sio.loadmat(BinClfFile)['frame_label']                        
            allBinaryLabels += BinaryLabels
            ss1+=1
        allprobs = np.zeros((20,Numberofframe))
        ss =0 
        for halfwin in halfwins: 
            ss+=1    
            inFile = '{}Classfication_nbc_{}_halfwin{}.mat'.format(OutDir,str(nbc),str(halfwin))
            probabilties = 1-np.transpose(sio.loadmat(inFile)['frame_probs'])
            allprobs += probabilties
        (r,c) = np.shape(probabilties);
        M = np.zeros((r+1,c));
        M[:20,:] = allprobs/ss
#                        M[20,:] = BinaryLabels
        BinaryLabels = mytools.myfilter(allBinaryLabels/ss1,siz,thresh)
#                        M[20,:] = binprob
        M[20,:] = BinaryLabels;
        (p,D) = dpEM(M,alpha)
        (labels,starts,ends) = getLabels(p)
        FinalLabels = refineLabes(labels,starts,ends,M,lenthresh,Numberofframe,shiftstart,shiftend)

        tempfilename  = '../Predictions/{}_prediction.csv'.format(sample)
        mytools.exportPredictions(FinalLabels,tempfilename)
Ejemplo n.º 6
0
def calc_grad_ext(F_ext, atom1, atom2):
    v1 = my.attr_val(atom1)
    v2 = my.attr_val(atom2)
    #   vector = [v1[i]-v2[i] for i in range(3)]
    vector = [v2[i] - v1[i] for i in range(3)]
    norm = np.linalg.norm(vector)
    U = [x / norm for x in vector]
    g_ext = [F_ext * x for x in U]

    return g_ext
Ejemplo n.º 7
0
class MyNode:
    def __init__(self, parent, data):
        self.data = data
        self.tool = Mytools()
        self.childNodes = []
        self.parent = parent
        self.childTagName = None
        pass

    def parser(self):
        self.name = self.tool.getTagName(self.data)
        self.attr = self.tool.getAttributes(self.data)
        if not self.tool.IsChildrenExist(self.data):
            self.text = self.tool.GetText(self.data)
        pass

    def getChildren(self, tag_name):
        if self.tool.IsChildrenExist(self.data):
            childdatas = self.tool.getChildrenData(self.data)
            self.childTagName = self.tool.getTagName(childdatas)
            subdatas = self.tool.splitChildrenData(childdatas,
                                                   self.childTagName)
            for subdata in subdatas:
                node = MyNode(self, subdata)
                node.parser()
                self.childNodes.append(node)
        return self.childNodes
        pass
def saveFVs(QuadDir,NumberofFrame,gmm,nbc,halfWindows):
    savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfWindows[-1])) 
#    if not os.path.isfile(savefilename):
    XX = []
    print "Saving Framwise FVS for ", QuadDir;
    for numFrame in range(1,NumberofFrame+1):
        filename = '{}desc{}.mat'.format(QuadDir,str(numFrame).zfill(5))
        Quads  = sio.loadmat(filename)['QuadDescriptors']
        XX.append(Quads)
    num = np.shape(XX)[0]
#    fvs = np.zeros((NumberofFrame,nbc*13))
    Allfvs = [np.zeros((NumberofFrame,nbc*13)) for k in range(len(halfWindows)) ]
#    del fvs
    print np.shape(Allfvs),' one ',np.shape(Allfvs[0])
    for numFrame in xrange(1,NumberofFrame+1):
        wincount = -1
        for halfwin in halfWindows:
            wincount+=1
            XXtemp = []
            for fnum in np.arange(max(0,numFrame-halfwin-1),min(numFrame+halfwin,NumberofFrame),1):
                Quads = XX[fnum]
                if np.shape(Quads)[0]>1:
                    XXtemp.extend(Quads)
            num = np.shape(XXtemp)[0]
            if num>0:
                Allfvs[wincount][numFrame-1,:] = mytools.fisher_vector(XXtemp, gmm)
    
    wincount = -1    
    for halfwin in halfWindows:
        wincount+=1
        savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfwin))
        fvs = Allfvs[wincount]
        sio.savemat(savefilename,mdict = {'fvs':fvs})
def saveClfOut(QuadDir,OutDir,halfwins,Numberofframe,svmclf,nbc):
              
    for halfwin in halfwins:
            outFile = '{}Classfication_nbc_{}_halfwin{}.mat'.format(OutDir,str(nbc),str(halfwin))
#        if not os.path.isfile(outFile):
            FVsFile = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfwin))
            fvs = sio.loadmat(FVsFile)['fvs']
            vecAllfvs = np.zeros((Numberofframe,nbc*13))
            isFrame_labeled = np.zeros(Numberofframe)
            i = 0;
            for fnum in xrange(Numberofframe):
                fvsum = np.sum(fvs[fnum])
                if abs(fvsum)>0:
                    vecAllfvs[i,:] = fvs[i,:]
                    isFrame_labeled[fnum] = 1
                    i+=1          

            vecAllfvs = vecAllfvs[:i,:]
            vecAllfvs = mytools.power_normalize(vecAllfvs,0.2)
            frame_probs = svmclf.predict_proba(vecAllfvs)
            frame_label = svmclf.predict(vecAllfvs)
            frame_probstemp  = np.zeros((Numberofframe,20))
            frame_probstemp[isFrame_labeled>0,:] = frame_probs
            frame_labelstemp  = np.zeros(Numberofframe)
            frame_labelstemp[isFrame_labeled>0]=frame_label
            print 'saving to ' , outFile
            sio.savemat(outFile,mdict={'frame_probs':frame_probstemp, 'frame_label':frame_labelstemp, 
            'isFrame_labeled':isFrame_labeled})
Ejemplo n.º 10
0
def saveClfOut(sample,QuadDir,OutDir,halfwin,Numberofframe,svmclf,nbc):

        outFile = '{}binary_halfwin_{}.mat'.format(OutDir,str(halfwin))
#        if not os.path.isfile(outFile):
        FVsFile = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfwin))
        fvs = sio.loadmat(FVsFile)['fvs']
        vecAllfvs = np.zeros((Numberofframe,nbc*13))
        isFrame_labeled = np.zeros(Numberofframe)
        i = 0;
        for fnum in xrange(Numberofframe):
            fvsum = np.sum(fvs[fnum])
            if abs(fvsum)>0:
                
                vecAllfvs[i,:] = fvs[i,:]
                isFrame_labeled[fnum] = 1
                i+=1   

        vecAllfvs = vecAllfvs[:i,:]
        vecAllfvs = mytools.power_normalize(vecAllfvs,0.4)

        frame_label = svmclf.predict(vecAllfvs)
        frame_labelstemp  = np.zeros((Numberofframe))
        frame_labelstemp[isFrame_labeled>0]=frame_label
        print 'saving to ' , outFile
        sio.savemat(outFile,mdict={'frame_label':frame_labelstemp,'isFrame_labeled':isFrame_labeled})
Ejemplo n.º 11
0
def flat_points(lists_points):
    L = []
    for val in lists_points:
        x, y, z = my.attr_val(val)
        L.append(x)
        L.append(y)
        L.append(z)

    return L
Ejemplo n.º 12
0
def saveQuads(saveDir, isAll, numFrame, Joints3D, Single, combs):
    savefilename = '{}desc{}.mat'.format(saveDir, str(numFrame).zfill(5))
    QuadDescriptors = []
    #    AllQuadDescriptors = []
    if np.sum(Joints3D[0, :]) > 0.05:
        for combination in combs:
            quadrupleJoints = Joints3D[combination - 1]
            QuadDescriptor = mytools.ComputeQuadDescriptor(
                quadrupleJoints, Single, isAll)
            if isAll:
                QuadDescriptors.extend(QuadDescriptor)
            else:
                QuadDescriptors.append(QuadDescriptor)
    QuadDescriptors = checkDescs4NAN(QuadDescriptors)
    sio.savemat(savefilename, mdict={'QuadDescriptors': QuadDescriptors})
Ejemplo n.º 13
0
def saveFVs(QuadDir, NumberofFrame, gmm, nbc, halfWindows):
    savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(
        QuadDir, str(nbc), str(halfWindows[-1]))
    #    if not os.path.isfile(savefilename):
    XX = []
    print "Saving Framwise FVS for ", QuadDir
    for numFrame in range(1, NumberofFrame + 1):
        filename = '{}desc{}.mat'.format(QuadDir, str(numFrame).zfill(5))
        Quads = sio.loadmat(filename)['QuadDescriptors']
        XX.append(Quads)
    num = np.shape(XX)[0]
    #    fvs = np.zeros((NumberofFrame,nbc*13))
    Allfvs = [
        np.zeros((NumberofFrame, nbc * 13)) for k in range(len(halfWindows))
    ]
    #    del fvs
    print np.shape(Allfvs), ' one ', np.shape(Allfvs[0])
    for numFrame in xrange(1, NumberofFrame + 1):
        wincount = -1
        for halfwin in halfWindows:
            wincount += 1
            XXtemp = []
            for fnum in np.arange(max(0, numFrame - halfwin - 1),
                                  min(numFrame + halfwin, NumberofFrame), 1):
                Quads = XX[fnum]
                if np.shape(Quads)[0] > 1:
                    XXtemp.extend(Quads)
            num = np.shape(XXtemp)[0]
            if num > 0:
                Allfvs[wincount][numFrame - 1, :] = mytools.fisher_vector(
                    XXtemp, gmm)

    wincount = -1
    for halfwin in halfWindows:
        wincount += 1
        savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(
            QuadDir, str(nbc), str(halfwin))
        fvs = Allfvs[wincount]
        sio.savemat(savefilename, mdict={'fvs': fvs})
Ejemplo n.º 14
0
"""
Created on 2011-10-6

@author: huangkan
"""
import Mytools

ten10 = 10 ** 10
l = list(Mytools.int2(7830457, 2))

ans = 1
for i in l:
    if i == "0":
        ans = ans * ans % ten10
    else:
        ans = ans * ans * 2 % ten10
ans = (ans * 28433 + 1) % ten10
print(ans)
print(l)
Ejemplo n.º 15
0
    newdes = des
    if NANs.any() > 0:
        print 'There is NAN case', np.shape(des)
        newdes = des[not NANs]
        print 'sahpe after', np.shape(newdes)
    return newdes


if __name__ == '__main__':
    #    main()
    # Path which contains sample files in .zip format

    datapaths = ['../TestData/']
    # Keep an copy the the sample files We delete what is not required
    # _depth.mp4 _video.mp4 _user.mp4  and sampleXXXXX.zip files will be deteted
    mytools.UnzipAllfiles(datapaths[0])
    kk = 0
    isAll = False
    Single = True
    for datapath in datapaths:
        # Get the list of training samples
        fileList = os.listdir(datapath)
        print datapath
        #     Filter input files (only ZIP files)

        samplelist = [
            files for files in fileList if files.startswith("Sample")
        ]

        for sample in samplelist:
            #print("\t Processing file " + sample)
Ejemplo n.º 16
0
'''
Created on 2011-4-30

@author: huangkan
'''
import Mytools

i=144
while 1:
    o=Mytools.hexagonal(i)
    if Mytools.Ispentagon(o) and Mytools.Istriangle(o): 
        print(o)
        break
    i+=1
   
Ejemplo n.º 17
0
'''
Created on 2011-10-1

@author: huangkan
'''
import Mytools
import math
l=50
ans=l*l*3
for x in range(1,l+1):
    for y in range(1,l+1):
        g=Mytools.gcd(x, y)
        x1=x/g
        y1=y/g
        k=min(math.floor((l-x)/y1),math.floor(y/x1))
        ans+=k*2
print(ans)
        
Ejemplo n.º 18
0
 def cinetica(self):
     k = 0.5 * my.cuad(self.vel, self.vel) * self.mass
     return k
Ejemplo n.º 19
0
    return L


###########  READING DATA ########################

# READING DATA FROM THE INPUT FILE

input = open('input.dat')
files = [line for line in input.read().split()]

#reading of the Cartesian Cordinates, number of Atoms, type of Atoms,
#Masses and Energy
file_st1 = files[0]

cord, numat, typ, symb, mass, st1_energy, st1_grad_cart, st1_hess_cart = \
my.initial_data(file_st1,'state1')

# READING CONECTIVITY

#my.mtx_conect('conex.dat')
conexion = list(open('internas.dat'))
nbond = int(conexion[0])
nang = int(conexion[nbond + 1])
ndih = int(conexion[nbond + nang + 2])
bond = [tuple([int(m) for m in w.split()]) for w in conexion[1:nbond + 1]]
ang = [
    tuple([int(m) for m in w.split()])
    for w in conexion[nbond + 2:nbond + nang + 2]
]
dih = [
    tuple([int(m) for m in w.split()])
Ejemplo n.º 20
0
'''
Created on 2011-8-7

@author: huangkan
'''
limit=50*10**6
flag=[False]*(limit+1)
import Mytools
ps=Mytools.primes(int(limit**.5)+1)
for i in ps:
    sum=i*i
    for j in ps:
        sum=i*i+j*j*j
        if sum>limit:
            break
        else:
            for k in ps:
                sum=i**2+j**3+k**4
                if sum>limit:break
                else: flag[sum]=True
ans=0
for i in flag:
    if i:ans+=1
print(ans)
Ejemplo n.º 21
0
'''
Created on 2011-7-31

@author: huangkan
'''
import math
import Mytools

sum=0
print(int(Mytools.mysqrt(2*10**200)))
for i in range(2,100):
    if i**.5!=int(i**.5):
        t=int(math.sqrt(i*10**200))
        #print(len(str(t)))
        ints=list(str(t))
        for j in ints[1:]:
            sum+=int(j)
print(sum)
Ejemplo n.º 22
0
 def internas_bonds(self, conex, nbond):
     self.bonds = [my.enlaces(self.cart[conex[i][0]-1], self.cart[conex[i][1]-1]) \
     for i in range(nbond)]
Ejemplo n.º 23
0
 def internas_ang(self, conex, nang):
     self.angles = [my.angulos(self.cart[conex[i][0]-1], self.cart[conex[i][1]-1], \
     self.cart[conex[i][2]-1]) for i in range(nang)]
Ejemplo n.º 24
0
'''
Created on 2011-7-9

@author: huangkan
'''
def cont(i,j):
    return int(str(i)+str(j))
#from Mytools import primes
from Mytools import Isprime
import Mytools
from itertools import combinations
estimate=1000000
limit=100000
pr=Mytools.primes_shelter(limit)
p1=[i for i in range(limit) if pr[i] and i%3==1 and i>673]
t=[3,7,109,673]
Oracle=Mytools.PrimeOracle()
i=673
while True:
    if Mytools.Isprime(i):
    
        for j in t:
            
            if not Mytools.Isprime(cont(i,j)) or not Mytools.Isprime(cont(j,i)):
                break
        else:
            print(i)
            break
    i+=6

    
Ejemplo n.º 25
0
"""
Created on 2011-7-30

@author: huangkan
"""
import Mytools

limit = 100
l = [0] * (limit + 1)
for i in range(0, limit + 1):
    if i % 2 == 0:
        l[i] = 1
p = Mytools.primes(limit)
for i in p[1:]:
    tl = l[:]
    for j in range(1, int(limit / i) + 1):
        for k in range(limit + 1):
            if k + i * j < limit:
                l[k + i * j] += tl[k]
            else:
                break
print(l)
for i in range(limit):
    if l[i] > 5000:
        print(i)
        break