def main(): config = configure() session = tf.Session() task = tasks.load(config) channel = channels.load(config) model = models.load(config) desc_model = models.desc_im.DescriptionImitationModel() translator = translators.load(config) rollout_ph = experience.RolloutPlaceholders(task, config) replay_ph = experience.ReplayPlaceholders(task, config) reconst_ph = experience.ReconstructionPlaceholders(task, config) channel.build(config) model.build(task, rollout_ph, replay_ph, channel, config) desc_model.build(task, rollout_ph, replay_ph, channel, config) translator.build(task, reconst_ph, channel, model, config) if config.task.train: trainer.run(task, rollout_ph, replay_ph, reconst_ph, model, desc_model, translator, session, config) else: trainer.load(session, config) if config.task.lexicon: lex = lexicographer.run(task, rollout_ph, reconst_ph, model, desc_model, translator, session, config) if config.task.visualize: visualizer.run(lex, task, config) if config.task.calibrate: calibrator.run(task, rollout_ph, model, desc_model, lexicographer, session, config) if config.task.evaluate: evaluator.run(task, rollout_ph, replay_ph, reconst_ph, model, desc_model, lex, session, config) sem_evaluator.run(task, rollout_ph, reconst_ph, model, desc_model, translator, lex, session, config) if config.task.turkify: turkifier.run(task, rollout_ph, model, lex, session, config)
class Following(Graph): def __init__(self): super().__init__() def set_path(self): for train in self.start_node.visited: train.path = self.all_path[0] graph = Following() graph.create_nodes('delhi-metro-stations') tmp = int(graph.trains) graph.trains = [] for x in range(tmp): tmp = Train(graph.start_line, graph.end_line, 'T' + str(x + 1)) graph.trains.append(tmp) graph.start_node.visited.append(tmp) all_path = graph.find_all_path() graph.set_path() output = "" while len(graph.end_node.visited) < len(graph.trains): graph.run_train() graph.train_position() output += graph.format_pos() + '\n' graph.print_pos() with open(runtime_file, 'w') as f: f.write(output.strip()) run('delhi-metro-stations')
if button == GLUT_LEFT_BUTTON: if state == GLUT_DOWN: self._dragging = True self._drag_x_previous = x elif state == GLUT_UP: self._dragging = False def _mouse_moved(self, x, y): if self._dragging: movement = x - self._drag_x_previous self._camera_rotation += movement self._drag_x_previous = x def _special_key_pressed(self, key, x, y): r = math.radians(self._camera_rotation) if key == GLUT_KEY_LEFT: self._camera_x += CAMERA_KEY_SPEED * math.cos(r) self._camera_z += CAMERA_KEY_SPEED * math.sin(r) elif key == GLUT_KEY_RIGHT: self._camera_x -= CAMERA_KEY_SPEED * math.cos(r) self._camera_z -= CAMERA_KEY_SPEED * math.sin(r) elif key == GLUT_KEY_UP: self._camera_x += CAMERA_KEY_SPEED * math.cos(r + math.pi/2) self._camera_z += CAMERA_KEY_SPEED * math.sin(r + math.pi/2) elif key == GLUT_KEY_DOWN: self._camera_x -= CAMERA_KEY_SPEED * math.cos(r + math.pi/2) self._camera_z -= CAMERA_KEY_SPEED * math.sin(r + math.pi/2) if __name__ == '__main__': visualizer.run(Stairs)
glBegin(GL_LINE_LOOP) glVertex2i(x1, y2) glVertex2i(x2, y2) glVertex2i(x2, y1) glVertex2i(x1, y1) glEnd() def upscale(self, x1, x2, actuality): unscaled_size = x2 - x1 desired_size = actuality * ARRIVAL_SIZE if desired_size > unscaled_size: mid = (x1 + x2) / 2 half_desired_size = int(desired_size/2) x1 = mid - half_desired_size x2 = mid + half_desired_size return (x1, x2) def filenum_to_y_coord(self, filenum): return self.y_ratio * (filenum - self.filenum_offset + 1) def update_y_scope(self): min_filenum = min(self.files.keys()) max_filenum = max(self.files.keys()) self._smoothed_min_filenum.smooth(float(min_filenum), self.time_increment) self._smoothed_max_filenum.smooth(float(max_filenum), self.time_increment) self.filenum_offset = self._smoothed_min_filenum.value() diff = self._smoothed_max_filenum.value() - self._smoothed_min_filenum.value() + 1 self.y_ratio = float(self.height) / (diff + 1) run(Puzzle)
from boid import Boid, PVector class Steering(Visualizer): def __init__(self, args): Visualizer.__init__(self, args) self.boids = [] boid = Boid(PVector(10, 10), 3.0, 3.0) boid.arrive(PVector(400, 200)) self.boids.append(boid) def render(self): for boid in self.boids: boid.update() self.draw_boid(boid) def draw_boid(self, boid): size = 5 x1 = boid.loc.x x2 = x1 + size y1 = boid.loc.y y2 = y1 + size glBegin(GL_POLYGON) glVertex2f(x1, y1) glVertex2f(x1, y2) glVertex2f(x2, y2) glVertex2f(x2, y1) glVertex2f(x1, y1) glEnd() run(Steering)
x2 = mid + half_desired_size return (x1, x2) def byte_to_coord(self, byte): return self.x_scope.map(byte) class Puzzle(visualizer.Visualizer): def __init__(self, args): visualizer.Visualizer.__init__(self, args, file_class=File) self.safe_width = int(self.width * (1 - APPEND_MARGIN - PREPEND_MARGIN)) self.prepend_margin_width = int(self.width * PREPEND_MARGIN) self.files = {} self.segments = {} self.y_scope = DynamicScope(padding=1) def render(self): if len(self.files) > 0: self.y_scope.update() for f in self.files.values(): f.update() f.render() def added_file(self, f): self.y_scope.put(f.filenum) def filenum_to_y_coord(self, filenum): return self.y_scope.map(filenum) * self.height if __name__ == '__main__': visualizer.run(Puzzle)
else: relative_age = age / DECAY_TIME active_color = colorsys.hsv_to_rgb(chunk.peer.hue, 0.35, 1) glColor3f(PASSIVE_COLOR[0] * relative_age + active_color[0] * (1-relative_age), PASSIVE_COLOR[1] * relative_age + active_color[1] * (1-relative_age), PASSIVE_COLOR[2] * relative_age + active_color[2] * (1-relative_age)) def draw_sounding_chunk(self, chunk, f): size = chunk.byte_size * SOUNDING_CHUNK_SIZE_FACTOR * self.width mid_byte = (chunk.begin + chunk.end) / 2 x, y = self.completion_position(chunk, mid_byte, f) chunk.peer.set_color(0.0) self.draw_point(x, y, size) def draw_point(self, x, y, size): size = min(size, MAX_CHUNK_SIZE * self.width) size = max(size, 1.0) glPointSize(size) glBegin(GL_POINTS) glVertex2f(x, y) glEnd() def completion_position(self, chunk, byte_position, f): angle = 2 * math.pi * byte_position / chunk.file_length x = f.x + f.radius * math.cos(angle) y = f.y + f.radius * math.sin(angle) return x, y run(Branches)
import evolutions as ev import qubit as q from numpy import pi, sqrt test = True sq2 = 1 / 2**.5 qubit = q.Qubit() qubit.init_psi(ev.StochasticMeasurement(spinor(sq2, sq2), q.identity, 1)) # qubit.init_psi(ev.Schrodinger(spinor(1 / 2, 1j * sqrt(3 / 4 - 4 / 25) + 2 / 5), q.sx)) qubit.add_tracker('traj', lambda q: [q.x(), q.y(), q.z()]) def convert(lis): return (str(lis)).replace('[', '{').replace(']', '}').replace( 'e', ' 10^').replace(' ', '') if test: from tester import individual dt = 1 / 2048.0 steps = int(pi / dt) q = individual(qubit, steps, dt=dt) print(convert(q.get_traj('traj'))) else: qubit.init_graphics([0, 0, 0], 10) from visualizer import run run(qubit)
for n in range(precision): r = float(n) / (precision - 1) x = x1 + (x2 - x1) * r y = y1 + (y2 - y1) * r h = h1 + (h2 - h1) * (math.cos((r - 0.5) / 5) - 0.995) / 0.005 glVertex3f(x, h, y) glEnd() def _render_land_points(self): self._render_grid_points(0) def _render_active_traces(self): for segment in self.playing_segments.values(): trace = self._traces[segment.peer.addr] self._render_trace(trace) def _render_trace(self, trace): glColor4f(1,1,1,1) glBegin(GL_LINE_STRIP) n = 1 for lx, ly in trace: #opacity = float(n) / (len(trace)-1) #glColor4f(1,1,1, opacity) x = lx * WORLD_WIDTH y = ly * WORLD_HEIGHT glVertex3f(x, 0, y) n += 1 glEnd() visualizer.run(Geography)
size, opacity) def draw_point(self, x, y, size, opacity): size = min(size, MAX_CHUNK_SIZE * self.width) size = max(size, 1.0) glColor3f(1-opacity, 1-opacity, 1-opacity) glPointSize(size) glBegin(GL_POINTS) glVertex2f(x, y) glEnd() def draw_completed_piece(self, piece, f): size = 3 opacity = 0.5 self.draw_point(piece.begin_position.x, piece.begin_position.y, size, opacity) self.draw_point(piece.end_position.x, piece.end_position.y, size, opacity) def draw_sounding_chunk(self, chunk, f): opacity = 1 size = chunk.byte_size * SOUNDING_CHUNK_SIZE_FACTOR * self.width self.draw_point(chunk.target_position.x, chunk.target_position.y, size, opacity) if __name__ == '__main__': visualizer.run(ForceDirectedForms)
try: f = self.files[chunk.filenum] except KeyError: f = File(chunk.file_length, self) self.files[chunk.filenum] = f chunk.file = f self.files[chunk.filenum].add_chunk(chunk) def stopped_playing(self, chunk_id, filenum): self.files[filenum].stopped_playing(chunk_id) def render(self): for f in self.files.values(): f.update() self.draw_gathered_chunks() self.draw_arriving_chunks() def draw_gathered_chunks(self): for f in self.files.values(): for chunk in f.gatherer.pieces(): chunk.draw() def draw_arriving_chunks(self): for f in self.files.values(): for chunk in f.arriving_chunks.values(): chunk.draw() if __name__ == "__main__": visualizer.run(Joints)
import visualizer if __name__ == '__main__': visualizer.run()
glVertex2i(x1, y2) glVertex2i(x2, y2) glVertex2i(x2, y1) glVertex2i(x1, y1) glEnd() def chunk_position(self, chunk): x1 = self.byte_to_px(chunk.begin) x2 = self.byte_to_px(chunk.end) x2 = max(x2, x1 + 1) return x1, x2 def byte_to_px(self, byte): return MARGIN + int( float((self.visualizer.max_file_length - self.length) / 2 + byte) / \ self.visualizer.max_file_length * (self.visualizer.width - 2*MARGIN)) class Simple(visualizer.Visualizer): def __init__(self, args): visualizer.Visualizer.__init__(self, args, file_class=File) def added_file(self, _f): self.max_file_length = max([f.length for f in self.files.values()]) def render(self): for f in self.files.values(): f.update() f.render() visualizer.run(Simple)
self.files[filenum].stopped_playing(chunk_id) def render(self): for f in self.files.values(): f.update() self.draw_arriving_chunks() def draw_arriving_chunks(self): for f in self.files.values(): for chunk in f.arriving_chunks.values(): self.draw_travelling_chunk(chunk, f) def draw_travelling_chunk(self, chunk, f): opacity = 0.3 size = chunk.byte_size * CHUNK_SIZE_FACTOR * self.width self.draw_point(chunk.position.x, chunk.position.y, size, opacity) def draw_point(self, x, y, size, opacity): size = min(size, MAX_CHUNK_SIZE * self.width) size = max(size, 1.0) glColor3f(1-opacity, 1-opacity, 1-opacity) glPointSize(size) glBegin(GL_POINTS) glVertex2f(x, y) glEnd() if __name__ == '__main__': visualizer.run(Particles)
def draw_completed_piece(self, chunk, f): opacity = 0.3 self.draw_sitting_piece(chunk, f, opacity) def draw_sounding_chunk(self, chunk, f): opacity = 1 size = chunk.byte_size * SOUNDING_CHUNK_SIZE_FACTOR * self.width mid_byte = (chunk.begin + chunk.end) / 2 x, y = self.completion_position(chunk, mid_byte, f) self.draw_point(x, y, size, opacity) def draw_sitting_piece(self, chunk, f, opacity): num_vertices = int(CIRCLE_PRECISION * float(chunk.end - chunk.begin) / chunk.byte_size) num_vertices = max(num_vertices, 2) glLineWidth(4) glColor3f(1-opacity, 1-opacity, 1-opacity) glBegin(GL_LINE_STRIP) for i in range(num_vertices): byte_position = chunk.begin + chunk.byte_size * float(i) / (num_vertices-1) x, y = self.completion_position(chunk, byte_position, f) glVertex2f(x, y) glEnd() def completion_position(self, chunk, byte_position, f): angle = 2 * math.pi * byte_position / chunk.file_length x = f.x + f.radius * math.cos(angle) y = f.y + f.radius * math.sin(angle) return x, y run(Circles)