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):

    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, 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"