def plot_ModuleLoads(MappingFile, CMSSW_Silicon, CMSSW_Scintillator): #Load external data data = loadDataFile(MappingFile) #dataframe data_tcs_passing, data_tcs_passing_scin = getTCsPassing( CMSSW_Silicon, CMSSW_Scintillator) #from CMSSW lpgbt_loads_tcs, lpgbt_loads_words, lpgbt_layers = getHexModuleLoadInfo( data, data_tcs_passing, data_tcs_passing_scin) plot(lpgbt_loads_tcs, "loads_tcs.png", binwidth=0.1, xtitle='Number of TCs on a single lpGBT') plot(lpgbt_loads_words, "loads_words.png", binwidth=0.1, xtitle='Number of words on a single lpGBT') plot2D(lpgbt_loads_tcs, lpgbt_layers, "tcs_vs_layer.png", xtitle='Number of TCs on a single lpGBT') plot2D(lpgbt_loads_words, lpgbt_layers, "words_vs_layer.png", xtitle='Number of words on a single lpGBT')
# if(constants.URL.__contains__('sonar')) : # best_fitness = output(best_fitness) # print("BEST FITNESS ::",output(best_fitness)) print("BEST FITNESS ::", (best_fitness)) print("labelled :: \n", labelled) ############################## #### FMEASURE if (constants.URL.__contains__('ionosphere') or constants.URL.__contains__('iris') or constants.URL.__contains__('wine') or constants.URL.__contains__('parkinsons') or constants.URL.__contains__('sonar') or constants.URL.__contains__('segmentation') or constants.URL.__contains__('glass')): # classdata = pd.read_csv(constants.cURL) classdata = np.array(y_dataset_glob) #print(classdata) fmeasure(labelled, classdata) ############################## if constants.URL.__contains__('random2'): plot2D(got_back[best_index], pop_distri) if constants.URL.__contains__('random3'): plot3D(got_back[best_index], pop_distri)
def synchroniseAtApex(pts_1, pts_2): syncd1 = [] syncd2 = [] shorter = [] longer = [] short_flag = 0 if len(pts_1) < len(pts_2): shorter = pts_1 longer = pts_2 short_flag = 1 else: shorter = pts_2 longer = pts_1 short_flag = 2 diff = len(longer) - len(shorter) # find the highest y value in each point set apex1 = max(float(p[1]) for p in shorter) apex2 = max(float(p[1]) for p in longer) apex1_i = [i for i, y in enumerate(shorter) if y[1] == str(apex1)] apex2_i = [i for i, y in enumerate(longer) if y[1] == str(apex2)] if debug: print "\n------Apexes------" print "> Short:", apex1, apex1_i, "of", len(shorter) print "> Long:", apex2, apex2_i, "of", len(longer) shift = apex2_i[0] - apex1_i[0] # remove the front end dangle if debug: print "\nShift by:", shift if shift > 0: longer = longer[shift:] if debug: print "Longer front trimmed, new length:", len(longer) else: shorter = shorter[abs(shift):] if debug: print "Shorter front trimmed, new length:", len(shorter) remainder = diff - shift # remove the rear end dangle if remainder >= 0: if debug: print "\nTrim longer by remainder:", remainder index = len(longer) - remainder longer = longer[:index] if remainder < 0: index = len(shorter) - abs(remainder) if debug: print "\nShift > diff in lengths, trim the shorter end to:", index shorter = shorter[:index] if debug: print "New length of shorter:", len(shorter) print "New length of longer:", len(longer) # find the highest y value in each point set apex1 = max(float(p[1]) for p in shorter) apex2 = max(float(p[1]) for p in longer) apex1_i = [i for i, y in enumerate(shorter) if y[1] == str(apex1)] apex2_i = [i for i, y in enumerate(longer) if y[1] == str(apex2)] if debug: print "\nNew apex positions:" print apex1, apex1_i print apex2, apex2_i if short_flag == 1: syncd1 = shorter syncd2 = longer else: syncd1 = longer syncd2 = shorter if view and debug: plot.plot2D(syncd1, name='First Synced Trajectory') plot.plot2D(syncd2, name='Second Synced Trajectory') return syncd1, syncd2
labelled = fitness.get_pop_distri_label(file, centroid, constants.K) print("labelled :: \n", labelled) ############################## #### FMEASURE if (constants.URL.__contains__('ionosphere') or constants.URL.__contains__('iris') or constants.URL.__contains__('wine') or constants.URL.__contains__('parkinsons') or constants.URL.__contains__('sonar') or constants.URL.__contains__('segmentation') or constants.URL.__contains__('glass')): # classdata = pd.read_csv(constants.cURL) classdata = np.array(y_dataset) #print(classdata) fmeasure(labelled, classdata) ############################## if constants.URL.__contains__('random2'): plot2D(centroid, pop_distri) if constants.URL.__contains__('random3'): plot3D(centroid, pop_distri) #data = np.array(data) #print(dist(centroids[0],data[0]),dist(centroids[1],data[0]),dist(centroids[2],data[0])) #print(dist(centroids[0],data[55]),dist(centroids[1],data[55]),dist(centroids[2],data[55])) #print(dist(centroids[0],data[127]),dist(centroids[1],data[127]),dist(centroids[2],data[127]))
def run(): global pts3 global pts4 if simulation and view: plot.plot3D(data3D, 'Original 3D Data') if view: plot.plot2D(pts1_raw, name='First Statics (Noise not shown)') plot.plot2D(pts2_raw, name='Second Statics (Noise not shown)') # FUNDAMENTAL MATRIX F = getFundamentalMatrix(pts1, pts2) # ESSENTIAL MATRIX (HZ 9.12) E, w, u, vt = getEssentialMatrix(F, K1, K2) # PROJECTION/CAMERA MATRICES from E (HZ 9.6.2) P1, P2 = getNormalisedPMatrices(u, vt) P1_mat = np.mat(P1) P2_mat = np.mat(P2) # FULL PROJECTION MATRICES (with K) P = K[Rt] KP1 = K1 * P1_mat KP2 = K2 * P2_mat print "\n> KP1:\n", KP1 print "\n> KP2:\n", KP2 # SYNCHRONISATION + CORRECTION if rec_data and simulation is False: print "---Synchronisation---" pts3, pts4 = synchroniseGeometric(pts3, pts4, F) pts3 = pts3.reshape((1, -1, 2)) pts4 = pts4.reshape((1, -1, 2)) newPoints3, newPoints4 = cv2.correctMatches(F, pts3, pts4) pts3 = newPoints3.reshape((-1, 2)) pts4 = newPoints4.reshape((-1, 2)) elif simulation: print "> Simulation: Use whole point set for reconstruction" pts3 = pts1 pts4 = pts2 # Triangulate the trajectory p3d = triangulateCV(KP1, KP2, pts3, pts4) # Triangulate goalposts if simulation is False: goalPosts = triangulateCV(KP1, KP2, postPts1, postPts2) # SCALING AND PLOTTING if simulation: if view: plot.plot3D(p3d, 'Simulation Reconstruction') reprojectionError(K1, P1_mat, K2, P2_mat, pts3, pts4, p3d) p3d = simScale(p3d) if view: plot.plot3D(p3d, 'Scaled Simulation Reconstruction') else: # add the post point data into the reconstruction for context if len(postPts1) == 4: print "> Concatenate goal posts to trajectory" pts3_gp = np.concatenate((postPts1, pts3), axis=0) pts4_gp = np.concatenate((postPts2, pts4), axis=0) p3d_gp = np.concatenate((goalPosts, p3d), axis=0) scale = getScale(goalPosts) scaled_gp_only = [[a * scale for a in inner] for inner in goalPosts] scaled_gp = [[a * scale for a in inner] for inner in p3d_gp] scaled = [[a * scale for a in inner] for inner in p3d] if view: plot.plot3D(scaled_gp, 'Scaled 3D Reconstruction') reprojectionError(K1, P1_mat, K2, P2_mat, pts3_gp, pts4_gp, p3d_gp) getMetrics(scaled, scaled_gp_only) scaled_gp = transform(scaled_gp) if view: plot.plot3D(scaled_gp, 'Final (Reorientated) 3D Reconstruction') if ground_truth_provided: reconstructionError(data3D, scaled_gp) # write X Y Z to file outfile = open('sessions/' + clip + '/3d_out.txt', 'w') for p in scaled_gp: p0 = round(p[0], 2) p1 = round(p[1], 2) p2 = round(p[2], 2) string = str(p0) + ' ' + str(p1) + ' ' + str(p2) outfile.write(string + '\n') outfile.close()
def reprojectionError(K1, P1_mat, K2, P2_mat, pts_3, pts_4, points3d): # Nx4 array for filling with homogeneous points new = np.zeros((len(points3d), 4)) for i, point in enumerate(points3d): new[i][0] = point[0] new[i][1] = point[1] new[i][2] = point[2] new[i][3] = 1 errors1 = [] errors2 = [] reprojected1 = [] reprojected2 = [] # for each 3d point for i, X in enumerate(new): # x_2d = K * P * X_3d xp1 = K1 * P1_mat * np.mat(X).T xp2 = K2 * P2_mat * np.mat(X).T # normalise the projected (homogenous) coordinates # (x,y,1) = (xz,yz,z) / z xp1 = xp1 / xp1[2] xp2 = xp2 / xp2[2] reprojected1.append(xp1) reprojected2.append(xp2) # and get the orginally measured points x1 = pts_3[i] x2 = pts_4[i] # difference between them is: dist1 = math.hypot(xp1[0] - x1[0], xp1[1] - x1[1]) dist2 = math.hypot(xp2[0] - x2[0], xp2[1] - x2[1]) errors1.append(dist1) errors2.append(dist2) avg1 = sum(errors1) / len(errors1) avg2 = sum(errors2) / len(errors2) std1 = np.std(errors1) std2 = np.std(errors2) errors = errors1 + errors2 avg = np.mean(errors) std = np.std(errors) print "\n> average reprojection error in image 1:", avg1 print "\n> average reprojection error in image 2:", avg2 if view and debug: plot.plotOrderedBar(errors1, 'Reprojection Error Image 1', 'Index', 'px') plot.plotOrderedBar(errors2, 'Reprojection Error Image 2', 'Index', 'px') plot.plot2D(reprojected1, pts_3, 'Reprojection of Reconstruction onto Image 1') plot.plot2D(reprojected2, pts_4, 'Reprojection of Reconstruction onto Image 2') outfile = open('sessions/' + clip + statdir + 'reprojection.txt', 'w') string = 'avg:' + str(avg) + '\nstd:' + str(std) outfile.write(string) outfile.close() statfile.write(str(avg) + ' ')
def synchroniseAtApex(pts_1, pts_2): syncd1 = [] syncd2 = [] shorter = [] longer = [] short_flag = 0 if len(pts_1) < len(pts_2): shorter = pts_1 longer = pts_2 short_flag = 1 else: shorter = pts_2 longer = pts_1 short_flag = 2 diff = len(longer) - len(shorter) # find the highest y value in each point set apex1 = max(float(p[1]) for p in shorter) apex2 = max(float(p[1]) for p in longer) apex1_i = [i for i, y in enumerate(shorter) if y[1] == apex1] apex2_i = [i for i, y in enumerate(longer) if y[1] == apex2] if debug: print "\n------Apexes------" print "> Short:", apex1, apex1_i, "of", len(shorter) print "> Long:", apex2, apex2_i, "of", len(longer) shift = apex2_i[0] - apex1_i[0] # remove the front end dangle if debug: print "\nShift by:", shift if shift > 0: longer = longer[shift:] if debug: print "Longer front trimmed, new length:", len(longer) else: shorter = shorter[abs(shift):] if debug: print "Shorter front trimmed, new length:", len(shorter) remainder = diff - shift # remove the rear end dangle if remainder >= 0: if debug: print "\nTrim longer by remainder:", remainder index = len(longer) - remainder longer = longer[:index] if remainder < 0: index = len(shorter) - abs(remainder) if debug: print "\nShift > diff in lengths, trim the shorter end to:", index shorter = shorter[:index] if debug: print "New length of shorter:", len(shorter) print "New length of longer:", len(longer) # find the highest y value in each point set apex1 = max(float(p[1]) for p in shorter) apex2 = max(float(p[1]) for p in longer) apex1_i = [i for i, y in enumerate(shorter) if y[1] == apex1] apex2_i = [i for i, y in enumerate(longer) if y[1] == apex2] if debug: print "\nNew apex positions:" print apex1, apex1_i print apex2, apex2_i if short_flag == 1: syncd1 = shorter syncd2 = longer else: syncd1 = longer syncd2 = shorter if view and debug: plot.plot2D(syncd1, name='First Synced Trajectory') plot.plot2D(syncd2, name='Second Synced Trajectory') return syncd1, syncd2
def synchroniseGeometric(pts_1, pts_2, F): print "> GEOMETRIC SYNCHRONISATION:" syncd1 = [] syncd2 = [] shorter = [] longer = [] short_flag = 0 # Work out which of two trajectories is shorter if len(pts_1) < len(pts_2): shorter = pts_1 longer = pts_2 short_flag = 1 else: shorter = pts_2 longer = pts_1 short_flag = 2 diff = len(longer) - len(shorter) if debug: print "Longer:", len(longer) print "Shorter:", len(shorter) print "Diff:", diff # Convert to homogeneous shorter_hom = cv2.convertPointsToHomogeneous(shorter) longer_hom = cv2.convertPointsToHomogeneous(longer) averages = [] # Shift the shorter through the longer for offset in xrange(0, diff + 1): err = 0 avg = 0 for i in xrange(0, len(shorter)): # current matching of pts a-b from trajectories A-B a = shorter_hom[i] b = longer_hom[i + offset] # Test x'Fx = 0 this_err = abs(np.mat(a) * F * np.mat(b).T) err += this_err avg = err / len(shorter) avg_off = (avg, offset) averages.append(avg_off) m = min(float(a[0]) for a in averages) ret = [item for item in averages if item[0] == m] # trim the beginning of the longer list offset = ret[0][1] longer = longer[offset:] # trim its end tail = len(longer) - len(shorter) if tail != 0: longer = longer[:-tail] if short_flag == 1: syncd1 = shorter syncd2 = longer else: syncd1 = longer syncd2 = shorter if debug: print "Synced Trajectory Length:", len(longer), len(shorter) if view and debug: plot.plot2D(syncd1, name='First Synced Trajectory') plot.plot2D(syncd2, name='Second Synced Trajectory') return syncd1, syncd2
def reprojectionError(K1, P1_mat, K2, P2_mat, pts_3, pts_4, points3d): # Nx4 array for filling with homogeneous points new = np.zeros((len(points3d), 4)) for i, point in enumerate(points3d): new[i][0] = point[0] new[i][1] = point[1] new[i][2] = point[2] new[i][3] = 1 errors1 = [] errors2 = [] reprojected1 = [] reprojected2 = [] # for each 3d point for i, X in enumerate(new): # x_2d = K * P * X_3d xp1 = K1 * P1_mat * np.mat(X).T xp2 = K2 * P2_mat * np.mat(X).T # normalise the projected (homogenous) coordinates # (x,y,1) = (xz,yz,z) / z xp1 = xp1 / xp1[2] xp2 = xp2 / xp2[2] reprojected1.append(xp1) reprojected2.append(xp2) # and get the orginally measured points x1 = pts_3[i] x2 = pts_4[i] # difference between them is: dist1 = math.hypot(xp1[0] - x1[0], xp1[1] - x1[1]) dist2 = math.hypot(xp2[0] - x2[0], xp2[1] - x2[1]) errors1.append(dist1) errors2.append(dist2) avg1 = sum(errors1) / len(errors1) avg2 = sum(errors2) / len(errors2) std1 = np.std(errors1) std2 = np.std(errors2) errors = errors1 + errors2 avg = np.mean(errors) std = np.std(errors) print "\n> average reprojection error in image 1:", avg1 print "\n> average reprojection error in image 2:", avg2 if view and debug: plot.plotOrderedBar( errors1, 'Reprojection Error Image 1', 'Index', 'px') plot.plotOrderedBar( errors2, 'Reprojection Error Image 2', 'Index', 'px') plot.plot2D(reprojected1, pts_3, 'Reprojection of Reconstruction onto Image 1') plot.plot2D(reprojected2, pts_4, 'Reprojection of Reconstruction onto Image 2') outfile = open('sessions/' + clip + statdir + 'reprojection.txt', 'w') string = 'avg:' + str(avg) + '\nstd:' + str(std) outfile.write(string) outfile.close() statfile.write(str(avg) + ' ')