def plot_differences(img_points, obj_points, homography, filename): util.info("Plotting difference of object points and projected points...") correspondences = util.get_correspondences(img_points, homography) x1 = obj_points[:, 0].tolist() y1 = obj_points[:, 1].tolist() plt.plot(x1, y1, label="Object Points") x2 = util.column(correspondences, 0) y2 = util.column(correspondences, 1) plt.plot(x2, y2, label="Projected Points") plt.xlabel('X Axis') plt.ylabel('Y Axis') plt.title('Comparison of object points and projected points') plt.legend() util.info("Writing graph...") plt.savefig("graphs/differences_" + filename + ".png") plt.clf() util.info("DONE.\n")
def compute_extrinsics(A, homography): util.info("Computing extrinsic parameters...") h1 = util.column(homography, 0) h2 = util.column(homography, 1) h3 = util.column(homography, 2) A_inv = np.linalg.inv(A) # We have lambda defined in the page 6. h1, h2 or h3 can be used in the calculation of lambda. lmbda = 1. / np.linalg.norm(np.dot(A_inv, h1)) # Compute r1, r2, r3 and t with the values given above. r1 = lmbda * np.dot(A_inv, h1) r2 = lmbda * np.dot(A_inv, h2) # r3 can be calculated with the orthogonality between r1 and r2. r3 = np.cross(r1, r2) t = lmbda * np.dot(A_inv, h3) # Reconstitute the rotation component of the extrinsics and reorthogonalize. # R = [r1, r2, r3] R = np.vstack((r1, r2, r3)).T R = util.reorthogonalize(R) # Reconstitute full extrinsics E = np.hstack((R, t[:, np.newaxis])) util.info("DONE.") return E
def run(): """Entry point and print the real metrics.""" data = p.read_csv("DrivingData.csv") num = data.values # The time column is the X axis for practically every graph time = util.column(num, util.TIME_INDEX) # Time is recorded in milliseconds, convert to seconds. time = [time / 1000.0 for time in time] # Extract all of our sensor snapshots which are in low light. low_light_frames = [frame for frame in num if is_low_light(frame)] # If the light is low and there's something right next to us, #we're probably either on the phone or it's in the pocket. pocket = [frame for frame in low_light_frames if is_close(frame)] # Extract all frames which were above the conversation threshhold noisy = [frame for frame in pocket if is_audible(frame)] print("There are " + str(len(num)) + " frames of data in total, each frame is 0.5s") print("There are " + str(len(low_light_frames)) + " frames with low light") print("Of those, it was probably in my pocket " + str(len(pocket)) + " frames") print("The average light level overall was " + str(sum(util.column(num, util.LUX_INDEX)) / len(num)) + ".") # Just get the total time from the first and last frames quickly. total_time = (num[-1][util.TIME_INDEX] - num[0][util.TIME_INDEX]) / 1000.0 # Pull all frames during which we were active (above a linear acceleration threshhold.) active_time = [frame for frame in num if is_active(frame)] print( "Of those frames when it was probably in a pocket, we probably were able to pick " + "up on conversation for " + str(len(noisy)) + " of them.") print("The total amount of time spent recording was " + str(total_time) + " S") # Each frame is 500 milliseconds. active_time = (500 * len(active_time)) / 1000.0 print("Which means there was an active percentage of " + str((active_time / total_time) * 100) + ".") show_plots(num, time)
def dirichletPrior(self,counts,alpha): if isinstance( counts[0],list): prior=[[0 for i in counts[0]] for j in counts] for j in range(len(counts[0])): denom = sum(column(counts, j))+alpha*len(counts) for i in range(len(counts)): prior[i][j]=(float(counts[i][j])+alpha)/denom else: total = sum(counts)+alpha*len(counts) prior = [(float(a+alpha))/total for a in counts] return prior
def transform_training_data(self, training_data): """ Transforms n*m feature matrix into a list of a tuples representing each item with its features and class :param training_data: The data pulled from the observed dataset :return: a list of a tuples representing each item with its features and class """ training_data_transformed = [] for cls in ['class_1', 'class_2']: for i in range(len(training_data[cls][0])): training_data_transformed.append((util.column(training_data[cls], i), cls)) return training_data_transformed
def show_plots(num, time): """Display the data to be plotted""" # Plot various relevant metrics. plot.plot(time, util.column(num, util.LUX_INDEX)) plot.title("Lux (light level) vs time.") plot.show() plot.plot(time, util.column(num, util.DECIBEL_INDEX)) plot.title("Decibels (sound level) vs time.") plot.show() # Take every frame and sum the X, Y, and Z acceleration magnitudes in those frames. movement_sums = [] for sensor_frame in num: movement_sums.append((abs(sensor_frame[util.LAT_X_INDEX]) + abs(sensor_frame[util.LAT_Y_INDEX]) + abs(sensor_frame[util.LAT_Z_INDEX]))) plot.plot(time, movement_sums) plot.title("Total movement vs time.") plot.show() # Just show a binary chart: either the user is active or the user is not, # as determined by our threshhold that we decided on before. active = [] for sensor_frame in num: if (abs(sensor_frame[util.LAT_X_INDEX]) + abs(sensor_frame[util.LAT_Y_INDEX]) + abs(sensor_frame[util.LAT_Z_INDEX])) > 1: active.append(1) else: active.append(0) plot.bar(time, active) plot.title("Blocks of active time.") plot.show()
################################################################################ # Write to file filename = 'dataset/stats.txt' file_exists = os.path.exists(filename) append_write = 'a' if (file_exists) else 'w' f = open(filename, append_write) f.write("Date: " + str(dt.datetime.now().strftime("%m-%d-%Y")) + '\n') # Write dataset dir_array = ['badeer-r', 'benson-r', 'corman-s', 'hain-m'] dataset = load_feat_data(dir_array) f.write("Data Set 1: " + str(len(dataset)) + "\n") for i in range(0, len(dataset[0])): f.write("Feature[" + str(i) + "]: " + str(np.mean(column(dataset, i))) + "\n") f.write( "---------------------------------------------------------------------\n") # Write dataset2 dir_array2 = ['cash-m', 'blair-l'] dataset2 = load_feat_data(dir_array2) f.write("Data Set 2: " + str(len(dataset2)) + "\n") for i in range(0, len(dataset2[0])): f.write("Feature[" + str(i) + "]: " + str(np.mean(column(dataset2, i))) + "\n") f.write( "---------------------------------------------------------------------\n")
tree = Gtk.TreeView() renderer = Gtk.CellRendererToggle() renderer.props.activatable = True def on_toggled(renderer, path): tree.get_model()[path][MessageModel.SELECTED] ^= True renderer.connect('toggled', on_toggled) col = Gtk.TreeViewColumn('', renderer, active=MessageModel.SELECTED) tree.append_column(col) tree.append_column(util.column('ID', util.textrenderer(), MessageModel.ID)) tree.append_column( util.column('Folder', util.textrenderer(0), MessageModel.FOLDER)) activitycol = util.column('Last activity', util.textrenderer(), MessageModel.LAST) tree.append_column(activitycol) tree.append_column(util.column('Date', util.textrenderer(), MessageModel.DATE)) tree.append_column( util.column('From', util.textrenderer(16), MessageModel.FROM)) tree.append_column( util.column('Size', util.textrenderer(align=1), MessageModel.SIZESTR, MessageModel.SIZE)) subjrenderer = util.textrenderer(80) subjcol = util.column('Subject', subjrenderer, MessageModel.CONTENT) tree.append_column(subjcol) tree.set_expander_column(subjcol)
for m in list(messages): add_row(None, m) msgmodel.set_sort_column_id(msgmodel.DATE, Gtk.SortType.DESCENDING) print('Took %ims' % ((time.time() - start) * 1000)) return msgmodel tree = Gtk.TreeView() renderer = Gtk.CellRendererToggle() renderer.props.activatable = True def on_toggled(renderer, path): tree.get_model()[path][MessageModel.SELECTED] ^= True renderer.connect('toggled', on_toggled) col = Gtk.TreeViewColumn('', renderer, active=MessageModel.SELECTED) tree.append_column(col) tree.append_column(util.column('ID', util.textrenderer(), MessageModel.ID)) tree.append_column(util.column('Folder', util.textrenderer(0), MessageModel.FOLDER)) activitycol = util.column('Last activity', util.textrenderer(), MessageModel.LAST) tree.append_column(activitycol) tree.append_column(util.column('Date', util.textrenderer(), MessageModel.DATE)) tree.append_column(util.column('From', util.textrenderer(16), MessageModel.FROM)) tree.append_column(util.column('Size', util.textrenderer(align=1), MessageModel.SIZESTR, MessageModel.SIZE)) subjrenderer = util.textrenderer(80) subjcol = util.column('Subject', subjrenderer, MessageModel.CONTENT) tree.append_column(subjcol) tree.set_expander_column(subjcol) emailview = emailview.EmailView() def on_select_mail(view): path, col = view.get_cursor()