def calcAccumulation(new_sol, newFrameLot, r, cost=True): stories = tracking.ordonnancement(new_sol) acc = np.zeros(shape=(len(EVENTS), 3), dtype=list) for plate in newFrameLot.lstFrames: for well in newFrameLot.lstFrames[plate]: for index in newFrameLot.lstFrames[plate][well]: print plate, well, index try: costs = r[plate][well][index] except KeyError: continue sourceC, targetC = accuracy.filtre(newFrameLot.lstFrames[plate][well][index]) # for b in range(len(sourceC)): # print "training set :", sourceC[b], targetC[b] if index not in stories[plate][well]: continue solC = stories[plate][well][index] if type(solC.truth) == str: print "attention, il n'y a pas de prediction pour cet index" continue costs2 = filter(lambda x: x[1] == 1, zip(costs, solC.truth)) predicted = formulation(filter(lambda x: x[1] == 1, zip(solC.hypotheses, solC.truth)), costs2) # for k in range(len(predicted[0])): # print "predictions :", predicted[0][k], predicted[1][k] i = 0 upletsVus = [] for uplet in sourceC: t, ttarg = accuracy.movement(uplet, s=None, tC=targetC[i]) for u in uplet: # moi je voudrais aussi l'index dans predicted ind, (p, ptarg) = movement(u, predicted) if p == 1: # c'est une apparition try: ind = predicted[1][-1].index(ttarg) except ValueError: continue else: upletsVus.append(ttarg) # pdb.set_trace() if t == p: test = (ttarg == ptarg) if t != 1 else (ttarg in ptarg) if test and t != 1: try: acc[t][0].append(predicted[2][ind]) except AttributeError: acc[t][0] = [predicted[2][ind]] elif test and t == 1: # pdb.set_trace() try: acc[t][0].append(predicted[2][-1][ind]) except AttributeError: acc[t][0] = [predicted[2][-1][ind]] else: print "-------------------------------------------------------pas pareil..." if p != -1: try: acc[p][1].append(predicted[2][ind]) except AttributeError: acc[p][1] = [predicted[2][ind]] else: try: # pdb.set_trace() acc[p][1].append(predicted[2][-1][ind]) except AttributeError: acc[p][1] = [predicted[2][-1][ind]] i += 1 # pdb.set_trace() for uplet in filter(lambda x: x != -1 and x not in sourceC, predicted[0]): for u in uplet: ind, (p, ptarg) = movement(u, predicted) try: acc[p][2].append(predicted[2][ind]) except AttributeError: acc[p][2] = [predicted[2][ind]] # if upletsVus!=[]: pdb.set_trace() for u in filter(lambda x: x not in upletsVus, predicted[1][-1]): p = 1 ind = predicted[1][-1].index(u) try: acc[p][2].append(predicted[2][ind]) except AttributeError: acc[p][2] = [predicted[2][ind]] return acc
def movement(uplet, s): z = s tu = filter(lambda x: uplet in x, s[0])[0] index = s[0].index(tu) return index, accuracy.movement(tu, s=None, tC=z[1][z[0].index(tu)])
def calcAccuracy(newFrameLot, output, trees): visu={} acc = np.zeros(shape=(len(EVENTS), 2), dtype=np.int) acc2 = np.zeros(shape=(len(EVENTS), len(EVENTS)), dtype=np.int) compteur = [[0,0] for x in range(len(EVENTS))] for plate in newFrameLot.lstFrames: outPasTrouves = '\n plate {}'.format(plate) if plate not in visu: visu[plate]={} for well in newFrameLot.lstFrames[plate]: print "Accuracy for", plate, well outPasTrouves += 'well {}'.format(well) if well not in visu[plate]: visu[plate][well]={} for index in newFrameLot.lstFrames[plate][well]: #print index, if index not in visu[plate][well]: visu[plate][well][index]=[] if index+1 not in visu[plate][well]: visu[plate][well][index+1]=[] #DATA CELL PROFIleR try: outputC =output[index+1] except KeyError: continue else: treeC = trees[index+1] nextTree = trees[index+2] #DATA TRAINING SET frameC= newFrameLot.lstFrames[plate][well][index] nextFrame = newFrameLot.lstFrames[plate][well][index+1] sourceC, targetC =accuracy.filtre(frameC) sourceC, pasTrouvesS = CeproLabelsTraduction(frameC, sourceC , treeC) targetC, pasTrouvesT = CeproLabelsTraduction(nextFrame, targetC, nextTree) if pasTrouvesS!=[]: print '########################################################################PAS TROUVES DANS LA SOURCE', pasTrouvesS visu[plate][well][index].append(pasTrouvesS) if pasTrouvesT!=[]: print '#######################################################################PAS TROUVES DANS LA CIBLE', pasTrouvesT visu[plate][well][index+1].append(pasTrouvesS) if pasTrouvesT!=[] or pasTrouvesS!=[]: outPasTrouves += '\n index {}'.format(index) outPasTrouves+=str(pasTrouvesS)+' target '+str(pasTrouvesT) i=0 # for k in range(len(outputC[0])): # print 's', outputC[0][k], outputC[1][k], if [] in sourceC: for k, s in enumerate(sourceC): if s==[]: del sourceC[k] del targetC[k] for uplet in sourceC: # if plate =='LT0024_41' and index==76 and uplet==[236]: # pdb.set_trace() t, ttarg = movement(uplet, s = None, tC=targetC[i]) if t==None: if targetC[i]==[]: if pasTrouvesT==[]: pdb.set_trace() else: continue OUT = "truth {},{},{}".format(uplet, t, ttarg) #compteur[0]=nb total de liens, compteur[1]=nb total de matchings compteur[t][0]+=max(len(uplet), len(ttarg)); compteur[t][1]+=1 first = True for u in uplet: try: p, ptarg = movement(u, s=outputC, tC = None) except IndexError: #here it means that there is no appear in the predicted sequence if u==-1: for tt in ttarg: z, ztarg = movement (u, s=outputC, tC = tt, incomplet = True) acc2[t][z]+=1 continue else: pdb.set_trace() OUT+="predit {},{}".format(p, ptarg) if t==p: test = (ttarg==ptarg) if t!=1 else (ttarg in ptarg) if test: #le matching est le bon et la cible egalement : j'enregistre acc[0]=nb de bons liens, acc[1]=nb de bons matchings acc[t][0]+=max(1, len(ttarg)) if first: acc[t][1]+=1 first = False #acc2[t][p]+=1 else: # donc la j'enregistre les erreurs, ici il y en a if t==1: #print OUT, '------------------------FALSE MOVE' for tt in ttarg: z, ztarg = movement (u, s=outputC, tC = tt, incomplet = True) acc2[t][z]+=1 else: #print OUT,"------------------------FALSE TARGET" for tt in ttarg: if tt in ptarg: acc[t][0]+=1 else: z, ztarg = movement(u, s=outputC, tC=tt, incomplet=True) acc2[t][z]+=1 else: #print OUT,'------------------------FALSE MOVE' if len(ttarg)>1: if first: for tt in ttarg: z, ztarg = movement (u, s=outputC, tC = tt, incomplet = True) acc2[t][z]+=1 first = False else: acc2[t][p]+=1 i+=1 compteur =np.array(compteur) print acc, '\n', acc2, '\n', compteur return acc, acc2, np.array(compteur), outPasTrouves