def print_script(self, evaluation): """Print an R script that shows the movement of the lens in this particular simulation.""" assert evaluation in ("true positive", "false positive", "true negative", "false negative", "succeeded", "failed") print "# %s at %d, %s\n" % (self.scene.filename, self.visited_positions[0], evaluation) # Some R functions for plotting. rtools.print_set_window_division(1, 1) print "library(scales)" # for alpha blending rtools.print_plot_focus_measures(self.scene.fvalues, show_grid=True) xs = self.visited_positions ys = [ float(i) / max(10, len(self.visited_positions)) for i in range(0, len(self.visited_positions)) ] rtools.print_plot_point_pairs(xs, ys, 25, "blue", "blue", True) result = self.last_position() if result >= 0: print "segments(%d, 0.0, %d, 1.0)" % (result, result) print "\n# Plot me!\n"
def print_R_script(scene, tree, classifier, step_size): print "# " + scene.filename + "\n" # Some R functions for plotting. print "library(scales)" # for alpha blending rtools.print_plot_focus_measures(scene.fvalues) # The correct classifications. classes = [ "left" if classifier(scene, lens_pos) else "right" for lens_pos in range(2 * step_size, scene.step_count) ] # What we actually get. results = [] for lens_pos in range(2 * step_size, scene.step_count): initial_positions = featuresfirststep.first_three_lens_pos( lens_pos, step_size) first, second, third = scene.get_focus_values(initial_positions) norm_lens_pos = float(lens_pos) / (scene.step_count - 1) evaluator = featuresfirststep.firststep_feature_evaluator( first, second, third, norm_lens_pos) evaluation = evaluatetree.evaluate_tree(tree, evaluator) results.append(evaluation) rtools.print_classification_points(classes, results, ["left", "right"]) print "# Plot me!\n"
def print_R_script(scene): print "# " + scene.filename + "\n" # Some R functions for plotting. print "library(scales)" # for alpha blending rtools.print_plot_focus_measures(scene.fvalues) # Axis to indicate that the bottom points mean coarse and # the top points means fine. print "axis(2, at=0, labels=\"coarse\", padj=-2)" print "axis(2, at=1.0, labels=\"fine\", padj=-2)" # Points to plot results = simulate(scene) xs, ys = ([ a for a, _ in results ], [ b for _, b in results ]) # unzip # Indicate the correct classes (coarse or fine) and the predicted classes. # The predicted classes is slightly offset to avoid overlapping. rtools.print_plot_point_pairs(xs, ys, 22, "black", "blue", False, 0.3, 0.5) # In the title, indicate how many steps are used. print ("title(main=paste(\"coarse steps:\", %d, " "\"fine steps:\", %d, " "\"total steps:\", %d))" % (ys.count(0), ys.count(1), len(ys))) print "# Plot me!\n"
def print_R_script(scene, tree, step_size): print "# " + scene.filename + "\n" # Some R functions for plotting. print "library(scales)" # for alpha blending rtools.print_plot_focus_measures(scene.fvalues) classes = [] results = [] for lens_pos in range(2 * step_size, scene.step_count): # The correct classification. go_left = featuresfirststep.nearest_on_left(scene, lens_pos) initial_positions = featuresfirststep.first_three_lens_pos( lens_pos, step_size) if go_left: initial_positions.reverse() last_pos = initial_positions[-1] if scene.distance_to_closest_left_peak(last_pos) <= 15: classes.append("fine") else: classes.append("coarse") else: last_pos = initial_positions[-1] if scene.distance_to_closest_right_peak(last_pos) <= 15: classes.append("fine") else: classes.append("coarse") # The classification obtained by evaluating the decision tree. first, second, third = scene.get_focus_values(initial_positions) norm_lens_pos = float(lens_pos) / (scene.step_count - 1) evaluator = featuresfirststep.firststep_feature_evaluator( first, second, third, norm_lens_pos) evaluation = evaluatetree.evaluate_tree(tree, evaluator) results.append(evaluation) rtools.print_classification_points(classes, results, ["coarse", "fine"]) print "# Plot me!\n"
def print_R_script(scene, lens_positions, instances): assert len(lens_positions) == len(instances) print "# " + scene.filename + "\n" xs_continue = [] ys_continue = [] xs_turn_peak = [] ys_turn_peak = [] xs_backtrack = [] ys_backtrack = [] for lens_pos, (_, classif, weight) in zip(lens_positions, instances): if classif == Action.CONTINUE: xs_continue.append(lens_pos) ys_continue.append(weight) if classif == Action.TURN_PEAK: xs_turn_peak.append(lens_pos) ys_turn_peak.append(weight) if classif == Action.BACKTRACK: xs_backtrack.append(lens_pos) ys_backtrack.append(weight) # Some R functions for plotting. rtools.print_set_window_division(1, 1) print "library(scales)" # for alpha blending rtools.print_plot_focus_measures(scene.fvalues, (-0.1, 1)) rtools.print_plot_point_pairs(xs_continue, ys_continue, 25, "black", "black") rtools.print_plot_point_pairs(xs_turn_peak, ys_turn_peak, 25, "green", "green") rtools.print_plot_point_pairs(xs_backtrack, ys_backtrack, 25, "red", "red") print "\n# Plot me!\n"