Beispiel #1
0
 def run_simulation(
     self,
     width=20,
     height=20,
     frames=50,
     visualization=True,
     evaluate=False,
     save=True,
     file_name="saved_sim.txt",
     frame_length=0.5,
 ):
     if not visualization and not evaluate and not save:
         print(
             "ERROR: visualization, evaluate, and save flags are all false. Exiting..."
         )
         return
     self.simulation_instance = touchscreenSimulator(width=width,
                                                     height=height,
                                                     frames=frames)
     print("Running simulation.")
     self.simulation_instance.run_simulation()
     if save:
         print("Saving simulation to " + file_name)
         f = open(file_name, "a")
         f.truncate(0)
         f.write("%d %d %d\n" % (width, height, frames))
         temp_frame = self.simulation_instance.get_frame(
             actual_position=True)
         while temp_frame is not None:
             noisy_loc = np.asarray(
                 np.where(temp_frame[0] == 1)).T.tolist()[0]
             actual_loc = np.asarray(
                 np.where(temp_frame[1] == 1)).T.tolist()[0]
             to_print = noisy_loc + actual_loc
             np.savetxt(f, to_print, fmt="%i", newline=" ")
             f.write("\n")
             temp_frame = self.simulation_instance.get_frame(
                 actual_position=True)
         f.close()
         # print("Simulation saved to saved_sim.txt")
         self.simulation_instance.timestamp = 0
     if evaluate:
         student_hmm = touchscreenHMM(width, height)
         if visualization:
             self.simulation_instance.visualize_results(
                 student_hmm=student_hmm, frame_length=frame_length)
         evaluator = touchscreenEvaluator()
         score = evaluator.evaluate_touchscreen_hmm(
             student_hmm, self.simulation_instance)
         print("Score: ", score)
     else:
         if visualization:
             self.simulation_instance.visualize_simulation(
                 frame_length=frame_length)
Beispiel #2
0
    def run_saved_simulation(
        self,
        file_name="saved_sim.txt",
        visualization=True,
        evaluate=False,
        student_hmm=None,
        frame_length=0.5,
    ):
        if not visualization and not evaluate:
            # both false, whats the point
            print(
                "ERROR: visualization and evaluate flags are both false. Exiting..."
            )
            return

        print("Reading saved simulation from " + file_name)
        f = open(file_name, "r")
        first_line = [int(x) for x in f.readline().strip().split(" ")]
        width, height, frames = first_line[0], first_line[1], first_line[2]
        # print(width,height,frames)
        data = np.loadtxt(f, dtype="int", skiprows=0)
        # print(data)
        f.close()

        self.simulation_instance = touchscreenSimulator(width=width,
                                                        height=height,
                                                        frames=frames)
        self.simulation_instance.load_simulation(data)
        if evaluate:
            student_hmm = touchscreenHMM(width, height)
            if visualization:
                self.simulation_instance.visualize_results(
                    student_hmm=student_hmm, frame_length=frame_length)
            evaluator = touchscreenEvaluator()
            score = evaluator.evaluate_touchscreen_hmm(
                student_hmm, self.simulation_instance)
            print("Score: ", score)
        else:
            if visualization:
                self.simulation_instance.visualize_simulation(
                    frame_length=frame_length)
Beispiel #3
0
from simulation_testing_manager import SimulationTestingManager
from touchscreen import touchscreenHMM

# You can test with any size (smaller size will be easier to see and follow)
# However, we will be running all graded tests using 20x20 screens
student_solution = touchscreenHMM(20, 20)

testing_manager = SimulationTestingManager()
"""
SimulationTestingManager's run_simulation:

FORMAT: name of flag - (type) description. Default = value

width - (int) specify the width of the simluation. Default = 20
height - (int) specify the height of the simluation. Default = 20
frames - (int) specify number of frames to run for simulation. Default = 50
visualization - (bool) specify whether to visualize simulation. Default = True
evaluate - (bool) specify whether to evaluate student solution. Default = False
           If True, the student's touchscreenHMM will automatically be intialized within this testing manager
save (bool) - specify whether to save the current run. Default = True
file_name (string) - specify a filename to save the simulation run to. Default = 'saved_sim.txt'
                     Only used when save flag is true.
frame_length (float) - specify the number of seconds each frame is shown for (lower for faster simulation). Default = 0.5
"""

# Basic simulation run, same functionality as run_visual_simulation.py
testing_manager.run_simulation(width=20,
                               height=20,
                               frames=100,
                               visualization=True,
                               evaluate=False)