def test_bird(): """ test bird calls """ N = 1024 scales = [32, 64, 128, 256] # Size of the Shift-Invariant dictionary M = np.sum(np.array(scales) / 2) * N n_runs = 30 verbose = False # tolerated probability of appearance under noise hypothesis # A good first choice for p_above is arguably 1/M p_above = 1.0 / M # creating noisy mix using classic doppler signal rng = np.random.RandomState(42) target_snr = 5 X = _make_doppler(N) X = X / linalg.norm(X) truth = X.copy() noise = rng.randn(*truth.shape) noise = 0.3 * np.exp(-float(target_snr) / 10.0) * noise / linalg.norm(noise) data = X + noise X_denoised = bird(data, scales, n_runs, p_above=p_above, random_state=42, n_jobs=1, verbose=verbose) # test denoised estimate is close to original assert_array_almost_equal(X_denoised, truth, decimal=2) # test second call produce same result X_denoised_again = bird(data, scales, n_runs, p_above=p_above, random_state=42, n_jobs=1, verbose=verbose) assert_array_almost_equal(X_denoised, X_denoised_again, decimal=8)
def main(tunnel, mode = 'normal', name = 'std.pkl', animate=True): pygame.init() #Load the into CUDA readable format tunnel_upr, tunnel_lwr = create_tunnel(tunnel) boxes = pygame.sprite.RenderUpdates() draw_tunnel(tunnel_upr, tunnel_lwr, boxes) #Initialize, create and store, or load the bird if (mode == 'normal' or mode == 'create'): b = bird(mpf, gpf, vPPF,pixels_per_vert_meter, pixels_per_horiz_meter, HEIGHT, tunnel_upr, tunnel_lwr) if (mode == 'create'): b.store(name) sys.exit() elif(mode == 'load'): b = p_bird(vPPF, pixels_per_horiz_meter, HEIGHT, name) if (animate==False): sys.exit() birds = pygame.sprite.RenderUpdates() birds.add(b) #Initialize the screen to a white background white = [255,255,255] screen = pygame.display.set_mode([WIDTH,HEIGHT]) screen.fill(white) background = pygame.Surface([WIDTH,HEIGHT]) background.fill(pygame.Color('white')) pygame.display.update() #Start the game loop, the game will continue #until the user presses any key start = 0 while pygame.event.poll().type != KEYDOWN: time = pygame.time.get_ticks() collision = False #Test for a collision between the bird and blocks if (len(pygame.sprite.spritecollide(b,boxes,False)) > 0): collision = True #Update the locations of the boxes and bird boxes.update(hPPF, time) birds.update(time, collision) #Draw everythin on the screen rectlist = boxes.draw(screen) birdlist = birds.draw(screen) #Update the tunnel, and birds pygame.display.update(rectlist) pygame.display.update(birdlist) if (collision): birds.update(time,collision) pygame.display.update(birds.draw(screen)) while pygame.event.poll().type != KEYDOWN: True break #Clearn the screen birds.clear(screen, background) boxes.clear(screen,background)
def __init__(self): self.left = 60 # 系统测量 self.top = 20 # 系统测量 self.right = 460 # 系统测量 self.buttom = 420 # 系统测量 self.bird_line_y = self.top + 300 # 系统测量 self.pipe_width = 80 # 系统测量 self.pipe_v = 225.0 # 系统测量 self.pipe_queue = [] self.bird = bird() self.detect_screen(frame) self.detect_bird(frame) self.pipe_line_y = self.top + self.pipe_width + 10 self.pipe_line_on = False self.start_t = time.time() self.last_calc_t = self.start_t self.last_calc_bird_x = self.bird.x self.calc_t_interv = self.bird.jump_t
x = np.linspace(0, 1, N) doppler = np.sqrt(x * (1 - x)) * np.sin((2.1 * np.pi) / (x + .05)) X = doppler.reshape((1, N)) X /= linalg.norm(X) truth = X.copy() noise = rng.randn(*truth.shape) noise *= .3 / linalg.norm(noise) snr = 20. * np.log10(linalg.norm(X) / linalg.norm(noise)) data = X + noise memory = Memory(None) print("SNR = %s." % snr) print("Dictionary of {0} atoms with {1} runs: chose " "p_above={2}".format(M, n_runs, p_above)) X_denoised = bird(data, scales, n_runs, p_above=p_above, random_state=42, n_jobs=-1, verbose=verbose, memory=memory) residual = X_denoised - truth print("Noisy Signal at %1.3f dB gave a RMSE of " "%1.3f" % (snr, linalg.norm(residual))) import matplotlib.pyplot as plt plt.close('all') plt.figure() plt.plot(data.T, 'k', alpha=0.5) plt.plot(truth.T, 'r:', linewidth=2.0) plt.plot(X_denoised.T, 'b', linewidth=2.0) plt.legend(('Noisy', 'Clean', 'BIRD Estimate')) plt.title('Noisy at %d dB' % snr) plt.show()
def test_init(self): tv = testvisualizer() s = swarm.swarm(0,tv) testvogel = bird.bird(s,tv) self.assertTrue(testvogel.getLocation() != None)
def addBird(self): self.__vv.append(bird.bird(self,self.__ifv))
pygame.init() width = 1440 height = 800 black = (0,0,0) bird_x = 300 bird_y = 400 clock = pygame.time.Clock() #make the pygame window display_surface = pygame.display.set_mode((width, height)) birdy = bird(bird_x, bird_y) pipeManager = pipeManager(width, height) # def collision(bird, pipe): # for p in pipe.pipeList: # if bird.bird_x == (p.position[0] - pipe.pipew): # if p.direction == "bottom" and bird.bird_y >= p.position[1]: # if p.direction == "top" and bird.bird_y <= p.grow: # return True # return False while (True): display_surface.fill(black)
def mainGame(): from bird import bird global birds #Initial Population birds = [0] * settings.POPULATION for i in range(settings.POPULATION): birds[i] = bird() birds[i].initialize() while True: # get 2 new pipes to add to upperPipes lowerPipes list newPipe1 = getRandomPipe() newPipe2 = getRandomPipe() # list of upper pipes upperPipes = [ {'x': settings.SCREENWIDTH + 200, 'y': newPipe1[0]['y']}, {'x': settings.SCREENWIDTH + 200 + (settings.SCREENWIDTH / 2), 'y': newPipe2[0]['y']}, ] # list of lowerpipe lowerPipes = [ {'x': settings.SCREENWIDTH + 200, 'y': newPipe1[1]['y']}, {'x': settings.SCREENWIDTH + 200 + (settings.SCREENWIDTH / 2), 'y': newPipe2[1]['y']}, ] pipeVelX = -4 num_crashed_birds = 0 refresh = False while True and not refresh: # move pipes to left for uPipe, lPipe in zip(upperPipes, lowerPipes): uPipe['x'] += pipeVelX lPipe['x'] += pipeVelX # add new pipe when first pipe is about to touch left of screen if 0 < upperPipes[0]['x'] < 5: newPipe = getRandomPipe() upperPipes.append(newPipe[0]) lowerPipes.append(newPipe[1]) # remove first pipe if its out of the screen if upperPipes[0]['x'] < -settings.pipeW: upperPipes.pop(0) lowerPipes.pop(0) # draw sprites settings.SCREEN.blit(settings.IMAGES['background'], (0, 0)) for uPipe, lPipe in zip(upperPipes, lowerPipes): rand_pipe_int = random.randint(0,len(settings.PIPES_LIST)-1) settings.SCREEN.blit(settings.IMAGES['pipe'][rand_pipe_int][0], (uPipe['x'], uPipe['y'])) settings.SCREEN.blit(settings.IMAGES['pipe'][rand_pipe_int][1], (lPipe['x'], lPipe['y'])) for bird_instance in birds: if not bird_instance.crashed and num_crashed_birds<len(birds): # check for crash here crashTest = bird_instance.checkcrash(upperpipes=upperPipes,lowerpipes=lowerPipes) if crashTest[0]: bird_instance.crashed = True num_crashed_birds += 1 bird_instance.update_score(upperPipes) bird_instance.think(upperPipes,lowerPipes) settings.SCREEN.blit(settings.IMAGES['base'], (bird_instance.basex, settings.BASEY)) # print score so player overlaps the score showScore(bird_instance.score) bird_instance.update_surface() settings.SCREEN.blit(bird_instance.playerSurface, (bird_instance.playerx, bird_instance.playery)) if num_crashed_birds == len(birds): num_crashed_birds = 0 birds = nextGeneration() refresh = True break pygame.display.update() settings.FPSCLOCK.tick(settings.FPS)
pygame.init() screen_info = pygame.display.Info() size = (width, height) = (int(screen_info.current_w), int(screen_info.current_h)) scoreCount = 0 background = pygame.image.load('background.png.png') background = pygame.transform.smoothscale(background, (width, height)) startPos = (width / 8, height / 2) pipes = pygame.sprite.Group() touch = False player = bird(startPos) gapSize = random.randint(150, 250) loopCount = 0 color = (0, 0, 0) screen = pygame.display.set_mode(size) score = pygame.sprite.Group() def lose(): font = pygame.font.SysFont(None, 70) text = font.render("You Failed", True, (0, 0, 255)) text_rect = text.get_rect() text_rect.center = (width / 2, height / 2) while True: screen.fill(color) screen.blit(text, text_rect)
random_state = 42 # Reference true data seed = 42 evoked_no_noise = simu_meg(snr=200, white=True, seed=seed) single_no_noise = evoked_no_noise.data[:n_channels, :] # noisy simulation evoked_noise = simu_meg(snr=SNR, white=white, seed=seed) single_noise = evoked_noise.data[:n_channels, :] n_jobs = 1 # set to -1 to run in parellel memory = Memory(None) p_above = 1e-8 bird_estimate = bird(single_noise, scales, n_runs, p_above=p_above, random_state=random_state, n_jobs=n_jobs, memory=memory) sbird_estimate = s_bird(single_noise, scales, n_runs, p_above=p_above, p_active=p_active, random_state=random_state, n_jobs=n_jobs, memory=memory) print("RMSE BIRD : %s" % linalg.norm(bird_estimate - single_noise)) print("RMSE S-BIRD : %s" % linalg.norm(sbird_estimate - single_noise)) subset = range(1, n_channels, 2) start = 100 # make time start at 0 import matplotlib.pyplot as plt plt.figure(figsize=(7, 5)) p1 = plt.plot(1e3 * evoked_no_noise.times[start:], single_noise[subset, start:].T, 'k:', alpha=0.5)
X /= linalg.norm(X) truth = X.copy() noise = rng.randn(*truth.shape) noise *= .3 / linalg.norm(noise) snr = 20. * np.log10(linalg.norm(X) / linalg.norm(noise)) data = X + noise memory = Memory(None) print("SNR = %s." % snr) print("Dictionary of {0} atoms with {1} runs: chose " "p_above={2}".format(M, n_runs, p_above)) X_denoised = bird(data, scales, n_runs, p_above=p_above, random_state=42, n_jobs=-1, verbose=verbose, memory=memory) residual = X_denoised - truth print("Noisy Signal at %1.3f dB gave a RMSE of " "%1.3f" % (snr, linalg.norm(residual))) import matplotlib.pyplot as plt plt.close('all') plt.figure() plt.plot(data.T, 'k', alpha=0.5) plt.plot(truth.T, 'r:', linewidth=2.0) plt.plot(X_denoised.T, 'b', linewidth=2.0) plt.legend(('Noisy', 'Clean', 'BIRD Estimate'))
# Reference true data seed = 42 evoked_no_noise = simu_meg(snr=200, white=True, seed=seed) single_no_noise = evoked_no_noise.data[:n_channels, :] # noisy simulation evoked_noise = simu_meg(snr=SNR, white=white, seed=seed) single_noise = evoked_noise.data[:n_channels, :] n_jobs = 1 # set to -1 to run in parellel memory = Memory(None) p_above = 1e-8 bird_estimate = bird(single_noise, scales, n_runs, p_above=p_above, random_state=random_state, n_jobs=n_jobs, memory=memory) sbird_estimate = s_bird(single_noise, scales, n_runs, p_above=p_above, p_active=p_active, random_state=random_state, n_jobs=n_jobs, memory=memory) print("RMSE BIRD : %s" % linalg.norm(bird_estimate - single_noise)) print("RMSE S-BIRD : %s" % linalg.norm(sbird_estimate - single_noise))
light1_Position = [0.0, 0.0, 0.0, 0.0] light1_Intensity = [0.25, 0.25, 0.25, 0.25] matAmbient = [1.0, 1.0, 1.0, 1.0] matDiffuse = [0.5, 0.5, 0.5, 1.0] matSpecular = [0.5, 0.5, 0.5, 1.0] matShininess = 100.0 #mouse control direction variable mvx = 0.0 mvy = 0.0 mvz = 0.0 oldy = 0.0 oldx = 0.0 Abird = bird.bird(-10, -10) lightSet = lightSetting.lightSetting() #--------------------------------------developing scene--------------- class Scene: axisColor = (0.5, 0.5, 0.5, 0.5) axisLength = 50 # Extends to positive and negative on all axes landColor = (.47, .53, .6, 0.5) #Light Slate Grey landLength = land # Extends to positive and negative on x and y axis landW = 1.0 landH = 0.0 cont = gameEnlarge def draw(self): self.drawAxis()