def __init__( self, q, shape=(8, 16), transform_fn=None, rwo_kwargs=None, alpha=0.9, noise=0.05, ): self.transform_fn = transform_fn or (lambda x: x ) # default to identity self.shape = shape self.state = np.zeros(shape) self.q = q # keyboard input self.keys = np.zeros(128, dtype=np.float32) self.block_size = 24 self.status = "OK" self.use_rwo = rwo_kwargs is not None if self.use_rwo: self.rwo = RWO(128, **rwo_kwargs) np.random.seed(35325) random_permutation = np.eye(128)[np.random.permutation(128)] self.corrupter = Corrupter([random_permutation], sensor_noise=np.full((128, ), noise), obs_alpha=alpha) self.corrupt_keys = np.zeros_like(self.keys) self.canvas = TKanvas( draw_fn=self.draw, tick_fn=self.tick, w=self.block_size * (self.shape[1] + 1), h=self.block_size * (self.shape[0] + 2), ) self.canvas.title("Ctrl-ESC-ESC-ESC to quit") self.matrix_display = TKMatrix(self.canvas, self.shape, self.block_size) self.text = self.canvas.text( self.block_size / 2, self.canvas.h - self.block_size / 2, text=str(self.status), fill="white", anchor="w", font=("Arial", 16), )
def __init__(self, boxes, args): self.boxes = boxes self.screen_size = 1000 self.slider_height = 150 self.canvas = TKanvas(draw_fn=self.draw, event_fn=self.event, quit_fn=self.quit, w=self.screen_size, h=self.slider_height) self.n_particles = 200 self.particles = slider_filter.prior(self.n_particles) #self.canvas.root.config(cursor='none') self.show_particles = args.particles self.last_x = None self.last_t = time.time() self.dx = 0 self.x = 0
def __init__(self, pfilter, gestures): self.screen_size = 500 c = TKanvas(draw_fn=self.draw, event_fn=self.event, quit_fn=self.quit, w=self.screen_size, h=self.screen_size) self.mouse = [0, 0] # position of the mouse self.pfilter = pfilter self.pfilter.init_filter() self.toast_state = 50 self.toast = "Start!" self.gestures = gestures self.complete_threshold = 0.9 # point at which gesture is considered complete self.entropy_threshold = 0.65 # point at which we will classify a gesture
def __init__(self, **kwargs): self.cursor = NoiseCursor(**kwargs) self.screen_size = 800 self.target_size = 20 self.hits = 0 self.misses = 0 self.last_filter = (0, 0) self.start_time = time.time() self.new_target() c = TKanvas(draw_fn=self.draw, event_fn=self.event, quit_fn=self.quit, w=self.screen_size, h=self.screen_size)
def __init__(self, boxes, args): self.boxes = boxes self.screen_size = 1000 self.slider_height = 150 self.canvas = TKanvas( draw_fn=self.draw, event_fn=self.event, quit_fn=self.quit, w=self.screen_size, h=self.slider_height, ) self.logger = SliderLogger(fields=[ "t", "true_x", "true_dx", "obs_x", "obs_speed", "est_x", "est_dx", "std_x", "std_dx", "mode", ]) self.gilbert = Gilbert(0.5, 0.3) self.n_particles = 200 self.particles = slider_filter.prior(self.n_particles) # self.canvas.root.config(cursor='none') self.show_particles = args.particles self.show_block = args.block self.sampling_intermittency = args.sampling self.last_x = None self.last_t = time.time() self.start_time = time.time() self.dx = 0 self.x = 0 self.position_noise = 0.03
class KeyDisplay(object): def __init__( self, q, shape=(8, 16), transform_fn=None, rwo_kwargs=None, alpha=0.9, noise=0.05, ): self.transform_fn = transform_fn or (lambda x: x ) # default to identity self.shape = shape self.state = np.zeros(shape) self.q = q # keyboard input self.keys = np.zeros(128, dtype=np.float32) self.block_size = 24 self.status = "OK" self.use_rwo = rwo_kwargs is not None if self.use_rwo: self.rwo = RWO(128, **rwo_kwargs) np.random.seed(35325) random_permutation = np.eye(128)[np.random.permutation(128)] self.corrupter = Corrupter([random_permutation], sensor_noise=np.full((128, ), noise), obs_alpha=alpha) self.corrupt_keys = np.zeros_like(self.keys) self.canvas = TKanvas( draw_fn=self.draw, tick_fn=self.tick, w=self.block_size * (self.shape[1] + 1), h=self.block_size * (self.shape[0] + 2), ) self.canvas.title("Ctrl-ESC-ESC-ESC to quit") self.matrix_display = TKMatrix(self.canvas, self.shape, self.block_size) self.text = self.canvas.text( self.block_size / 2, self.canvas.h - self.block_size / 2, text=str(self.status), fill="white", anchor="w", font=("Arial", 16), ) def tick(self, dt): try: result = self.q.get(block=False) if result: arr_bytes, t, _ = result self.keys[:] = np.frombuffer(arr_bytes, dtype=np.float32) else: self.canvas.quit(None) except queue.Empty: # no updates, do nothing pass self.corrupt_keys = self.corrupter.update(self.keys) if self.use_rwo: self.rwo.update(self.corrupt_keys, time.clock()) self.state = self.transform_fn(self.corrupt_keys).reshape(self.shape) def draw(self, src): # draw the blank squares for the outputs if self.use_rwo: src.canvas.itemconfig(self.text, text=str(self.rwo.n_vecs)) self.matrix_display.update(self.state)