def __init__(self): self.background = Background() self.shot = Fire() self.senary = Senary() self.trilha = pygame.mixer.Sound("sound\\trilha.wav") self.tiro = pygame.mixer.Sound('sound\\tiro.wav') self.porrada = pygame.mixer.Sound('sound\\porrada.wav') self.morreu = pygame.mixer.Sound('sound\\morreu.wav') self.trilha.play(-1) self.img = pygame.Surface((80,120)) self.img = pygame.image.load('img\\joao1.png') self.imgS = pygame.image.load('img\\joao2.png') self.imgC = pygame.image.load('img\\joao1c.png') self.imgSC = pygame.image.load('img\\joao2c.png') self.img.set_colorkey((10,255,0),0) self.img.set_alpha(255,0) self.img2 = pygame.Surface((80,120)) self.img2.set_colorkey((10,255,0),0) self.img2.set_alpha(255,0) self.pos = pygame.Rect((120,320,80,120)) self.jump = 0 self.jump_h = 11 self.life = 5 self.face = 1 self.x = 0 self.contx = 0 self.step = 1 self.score = 0 self.moveActivedJump = 1 draw(self.img,(self.pos.left,self.pos.top)) self.background.sky() self.drawLife()
def __init__(self): self.background = Background() self.shot = Fire() self.senary = Senary() self.trilha = pygame.mixer.Sound(os.path.join("sound","trilha.wav")) self.tiro = pygame.mixer.Sound(os.path.join("sound",'tiro.wav')) self.porrada = pygame.mixer.Sound(os.path.join("sound",'porrada.wav')) self.morreu = pygame.mixer.Sound(os.path.join("sound",'morreu.wav')) self.trilha.play(-1) self.img = pygame.Surface((80,120)) self.img = pygame.image.load(os.path.join("img",'joao1.png')) self.imgS = pygame.image.load(os.path.join("img",'joao2.png')) self.imgC = pygame.image.load(os.path.join("img",'joao1c.png')) self.imgSC = pygame.image.load(os.path.join("img",'joao2c.png')) self.img.set_colorkey((10,255,0),0) self.img.set_alpha(255,0) self.img2 = pygame.Surface((80,120)) self.img2.set_colorkey((10,255,0),0) self.img2.set_alpha(255,0) self.pos = pygame.Rect((120,320,80,120)) self.jump = 0 self.jump_h = 11 self.life = 5 self.face = 1 self.x = 0 self.contx = 0 self.step = 1 self.score = 0 self.moveActivedJump = 1 draw(self.img,(self.pos.left,self.pos.top)) self.background.sky() self.drawLife()
def __init__(self): self.img = pygame.image.load(os.path.join("img","fundo.jpg")) self.imgSky = pygame.image.load(os.path.join("img",'ceu.jpg')) self.imgRapadura = pygame.image.load(os.path.join("img",'rapadura.png')) self.font = pygame.font.Font(pygame.font.match_font(pygame.font.get_default_font()),25) self.pos = pygame.Rect((0,140,6400,340)) self.score = self.font.render("",1,(0,0,0)) self.actived = 0 draw(self.img,(self.pos.left,self.pos.top))
def __init__(self): self.img = pygame.image.load("img\\fundo.jpg") self.imgSky = pygame.image.load('img\\ceu.jpg') self.imgRapadura = pygame.image.load('img\\rapadura.png') self.font = pygame.font.Font( pygame.font.match_font(pygame.font.get_default_font()), 25) self.pos = pygame.Rect((0, 140, 6400, 340)) self.score = self.font.render("", 1, (0, 0, 0)) self.actived = 0 draw(self.img, (self.pos.left, self.pos.top))
def mouse(event, x, y, flags, param): global p0, p1 if event == cv.EVENT_LBUTTONDOWN: img0[:] = img p0 = x, y elif event == cv.EVENT_MOUSEMOVE and flags == 1: p1 = x, y elif event == cv.EVENT_LBUTTONUP: p1 = x, y draw(0)
def test_linear(data, linear): eprint("Start test") eprint.enter() # for p in data: # eprint("%8s %8s : %8s %8s" % tuple(("%.2f %.2f %.2f %.2f" % (p[0], p[1], p[2], linear(p[0], p[1]))).split())) xs, ys, zs = zip(*data) draw(xs, ys, zs, linear) # while ask('Do you want to test some point?'): # eprint("Enter area and number of rooms:", end=' ') # area, rooms = map(float, input().strip().split()) # eprint("Expected price of such flat is %.2f" % linear(area, rooms)) eprint.exit()
def main(): pygame.init() pygame.display.set_mode(screen[2:], DOUBLEBUF | OPENGL) gluOrtho2D(world[0], world[2], world[3], world[1]) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() handle_input() draw() pygame.time.wait(50)
def draw(self): for i in range(len(self.stone)-1): draw(self.imgStone,(self.stone[i].left,self.stone[i].top)) for i in range(len(self.inimigo)-1): if self.inimigoStep[i] == 1: draw(self.imgInimigo,(self.inimigo[i].left,self.inimigo[i].top)) else: draw(self.imgInimigo2,(self.inimigo[i].left,self.inimigo[i].top)) for i in range(len(self.life)-1): draw(self.imgLife,(self.life[i].left,self.life[i].top))
def redraw(*args): surface = draw(*args) buf = surface.get_data() screen = pygame.display.get_surface() image = pygame.image.frombuffer(buf, (width, height), "RGBA") screen.fill((255, 255, 255)) screen.blit(image, (0, 0)) pygame.display.flip()
def read_infile(): global myCircuit runButton.pack_forget() if myCircuit is not None: myCircuit.delete() filename = file.get() f = open(dir + filename, "r") # gets closed inside simAnneal object myCircuit = draw(root, f) runButton.pack(side='left', padx=20, pady=10)
def mover(draw, grid, origGrid, start, end): i, j = start.get_pos() I, J = end.get_pos() if islastmove(i, j, I, J): print("This is the last move") start = end end.make_start() end = None return 0, start, end else: print("This is not the last move") for neigh in start.neighbors: if (neigh.color == PURPLE): start = neigh start.make_start() break reset_path(grid, origGrid) draw() return 1, start, end
def move(self): i=-1 while i != len(self.dir)-1: i+=1 if self.origem[i]: draw(self.img,(self.pos[i].left,self.pos[i].top)) else: draw(self.img2,(self.pos[i].left,self.pos[i].top)) if self.dir[i]: self.pos[i].move_ip(15,0) if self.pos[i].left == 640: self.dir.pop(i) self.pos.pop(i) self.origem.pop(ini) i-=1 else: self.pos[i].move_ip(-15,0) if not self.pos[i].left: self.dir.pop(i) self.pos.pop(i) self.origem.pop(ini) i-=1
def move(self): i = -1 while i != len(self.dir) - 1: i += 1 if self.origem[i]: draw(self.img, (self.pos[i].left, self.pos[i].top)) else: draw(self.img2, (self.pos[i].left, self.pos[i].top)) if self.dir[i]: self.pos[i].move_ip(15, 0) if self.pos[i].left == 640: self.dir.pop(i) self.pos.pop(i) self.origem.pop(ini) i -= 1 else: self.pos[i].move_ip(-15, 0) if not self.pos[i].left: self.dir.pop(i) self.pos.pop(i) self.origem.pop(ini) i -= 1
def drawing(file_name): """ 引数:画面で指定したファイル名 戻り値: 正常終了時はなし。 file_nameがinputフォルダに存在しなかった場合はエラーメッセージ(message) をindex.htmlへ返す。 """ file_name = file_name.split("\\")[-1] cwd = os.getcwd() input_file = os.path.join(cwd, "input", file_name) if os.path.isfile(input_file): print("変換処理を開始します。") n = 10 # グレースケール量子化次数 period = 5 # 線(ストローク)幅 # drawing draw(file_name, n, period) print("変換処理が正常終了しました。") else: message = "ファイルが存在しません。" print(message) return message
def watermark(sourceImagePath, targetImagePath): temp_path = 'temp.png' if targetImagePath == "": mask_path = draw(sourceImagePath) command = 'python test.py --image ' + sourceImagePath + ' --mask ' + mask_path + ' --output ' + temp_path + ' --checkpoint_dir model_logs/release_places2_256' #os.system( # 'python test.py --image examples/places2/case1_input.png --mask examples/places2/case1_mask.png --output examples/places2/case1_output.png --checkpoint_dir model_logs/release_places2_256') os.system(command) image = Image.open(temp_path) if targetImagePath != "": image.save(targetImagePath) else: return image
# obs_batch = [] # for _ in range(N_BATCH): # tr = exp_acti.sample() # lab_batch.append(tr.S) # obs_batch.append(tr.Os) # b_obs = inv_batch_obs(lab_batch, obs_batch) # invnet.train(sess, b_obs) if i % 1000 == 0: print "testing it on random trace . . ." rand_tr = gen_rand_trace(test=True) print rand_tr.S, np.argmax(rand_tr.S) invv = invnet.invert(sess, rand_tr.Os) print invv, np.argmax(invv) draw_obs(rand_tr.Os, "drawings/inv_rand_obs.png") print "testing it on active trace . . ." qry = mk_query(rand_tr.Img) act_inv = impnet.get_active_trace(sess, qry, epi=0.0) act_tr = full_output_to_trace(act_inv, rand_tr.Img, rand_tr.S) print act_tr.S, np.argmax(act_tr.S) invv = invnet.invert(sess, act_tr.Os) print invv, np.argmax(invv) draw_obs(act_tr.Os, "drawings/inv_acti_obs.png") draw(np.reshape(rand_tr.Img, [L,L,1]), "drawings/inv_orig.png") invnet.save(sess, "model_invert.ckpt")
def main(win, width): if (flag == 0): Map, pad = getDetails() ROWS = pad grid = make_grid(ROWS, width) original_grid = make_grid(ROWS, width) for numr, r in enumerate(Map): for numc, c in enumerate(r): if (Map[numr][numc] == '@'): grid[numc][numr].make_barrier() original_grid[numc][numr].make_barrier() if (Map[numr][numc] == 'T'): grid[numc][numr].make_tree() original_grid[numc][numr].make_tree() else: #ROWS = 50 ROWS = int( input("\n Enter the number of rows you want in the blank map. : ")) grid = make_grid(ROWS, width) original_grid = make_grid(ROWS, width) start = None end = None run = True # If True, Pygame engine would work. while run: draw(win, grid, ROWS, width) # Showing Colour of each node at every iteration. # Getting event type output from Pygame engine for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if pygame.mouse.get_pressed()[0]: # LEFT pos = pygame.mouse.get_pos() row, col = get_clicked_pos(pos, ROWS, width) spot = grid[row][col] if not start and spot != end: start = spot start.make_start() rs = row cs = col elif not end and spot != start: end = spot end.make_end() re = row ce = col elif spot != end and spot != start: spot.make_tree() elif pygame.mouse.get_pressed()[2]: # RIGHT pos = pygame.mouse.get_pos() row, col = get_clicked_pos(pos, ROWS, width) spot = grid[row][col] spot.reset() if spot == start: start = None elif spot == end: end = None if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE and start and end: finish = 1 cnt = 0 # For saving fig in form of phases. while (finish): cnt = cnt + 1 # Now we ensure that the view point of the robot is just of 3 unit radius. for row in grid: for spot in row: p1 = spot.get_pos() p2 = start.get_pos() if (h(p1, p2) <= 5 and spot.ngh_update == 0): spot.update_neighbors(grid) else: if (spot.ngh_update == 0): spot.all_neighbors(grid) (rows, cols) = start.get_pos() start_pos.append((rows, cols)) rowe, cole = end.get_pos() plot(ROWS, start_pos, rowe, cole, grid, cnt) # This is the step where we actually apply the algorithm. algorithm(lambda: draw(win, grid, ROWS, width), grid, start, end) finish, start, end = mover( lambda: draw(win, grid, ROWS, width), grid, original_grid, start, end) time.sleep(3) if event.key == pygame.K_r: start = None end = None grid = make_grid(ROWS, width) if event.key == pygame.K_s: showImg() pygame.quit() start_pos.append((re, ce))
def redraw(self): draw(self.img,(self.pos.left,self.pos.top)) if self.actived: draw(self.background2.img,(self.background2.pos.left,self.background2.pos.top)) draw(self.score,(500,140))
def drawLife(self): for i in range(self.life): draw(self.background.imgRapadura,(50*i+20,40))
experience.add_balanced(tr) all_blue += 1 experience_pain.add_balanced(pain_tr) batch = experience.n_sample(50) bug.learn(batch, "move") pain_batch = experience_pain.n_sample(50) bug.learn(pain_batch, "pain") if i % 200 == 0: path = bugzero.trace_to_path(tr) pain_path = bugzero.trace_to_path(pain_tr) print "iteration ", i print path action_path = bugzero.trace_to_action_path(tr) pain_action_path = bugzero.trace_to_action_path(pain_tr) print action_path draw(maze, "maze.png", path, action_path) draw(maze, "maze_pain.png", pain_path, pain_action_path) print "whatev mishandle beautiful hopeless" print blue_ok_pink_ok, blue_ok_pink_bad, blue_bad_pink_ok, blue_bad_pink_bad, all_blue if i % 2000 == 1999: print "accuracy ", get_accuracy(bug, bugzero, 1000) bug.save_model("models/bug_bug_model.ckpt") print "finished training, measuring accuracy " print "accuracy ", get_accuracy(bug, bugzero, 1000)
batchsize=8, resolution=2, spec='cqt', phase=False, epochs=100, size=256, lr=1e-4) ''' The code below draws the loss verses time of the first experiment run for 100 epochs. It also prints all the experiments run for 100 epochs. ''' plt.style.use('bmh') filtered = find(epochs=100) fig, ax1 = plt.subplots(figsize=(4.5, 3)) plt.ylim((0.000, 0.015)) path = ('valid', 'gnr', 'loss') plt.legend() draw(ax1, filtered[0], ('valid', 'gnr', 'loss'), True, label='example', color='red') plt.legend() plt.ylabel(r'validation loss') plt.xlabel('minutes') plt.savefig('plots/example.svg') plt.show() show(filtered, by=['gnr-loss'])
""" Directly draw all graphs from original log file """ from parse_log import * from draw import * if __name__ == '__main__': file_name = sys.argv[1] # out.log(.train)/out.log(.test) pic_path = "./" # . train_dict_list, test_dict_list = parse_log(file_name) save_csv_files(file_name, pic_path, train_dict_list, test_dict_list, delimiter=",") draw(file_name, pic_path)
def user_turn(player_list, player, wall_list, available_positions, curscr): (x, y) = player['location'] loc = (x, y) #print available_positions[loc] neighbors = [] for location in available_positions[loc]: neighbors.append(location) p = w2p(wall_list) #(X, Y) = wall['location'] command_list = [] command_dict = {} directions = [] for neighbor in neighbors: (a, b) = neighbor directions.append((a - x, b - y)) directions = vector_sort(directions) neighbors = [] for direction in directions: (a, b) = direction neighbors.append((x + a, y + b)) for i in range(len(neighbors)): char = str(i + 1) command_list.append(char) command_dict[char] = i quit = False ready = False new_wall = False second_stage = False while not ready: while not ready and not second_stage: draw(player_list, wall_list, curscr, neighbors) if enable_curses: curses.noecho() k = curscr.getch() command = curses.keyname(k) else: command = raw_input() if command in command_list: (x, y) = neighbors[command_dict[command]] player['location'] = (x, y) ready = True elif command == 'q': quit = True ready = True elif command == 'n': new_wall = True ready = False second_stage = True elif command == 'u': __builtin__.rollback = True ready = True else: ready = False second_stage = False if player['amount_of_walls'] == 0: second_stage = False walls_installed = 0 while not ready and second_stage: if enable_curses: curses.noecho() k = curscr.getch() command = curses.keyname(k) else: k = 0 command = raw_input() if command == 'n': new_wall = False if walls_installed == 0 and player['amount_of_walls'] != 0: wall = None for i in range(1, width): for j in range(height - 1, 0, -1): for wall_type in p[(i, j)]: wall = {'type': wall_type, 'location': (i, j), 'player_id': player['id']} break if wall != None: wall_list.append(wall) walls_installed +=1 (X, Y) = wall['location'] elif command == 'i' or k == KEY_UP: if walls_installed != 0: wall = wall_list[len(wall_list) - 1] Y -= 1 Y = max(1, Y) if wall['type'] == 'vertical' and Y <= 1: wall['type'] = 'horizontal' wall['location'] = (X, Y) elif command == 'j' or k == KEY_LEFT: if walls_installed != 0: wall = wall_list[len(wall_list) - 1] X -= 1 X = max(1, X) if wall['type'] == 'horizontal' and X <= 1: wall['type'] = 'vertical' wall['location'] = (X, Y) elif command == 'k' or k == KEY_DOWN: if walls_installed != 0: wall = wall_list[len(wall_list) - 1] Y += 1 Y = min(height - wall_length + 1, Y) if wall['type'] == 'vertical' and Y > (height - wall_length): wall['type'] = 'horizontal' wall['location'] = (X, Y) elif command == 'l' or k == KEY_RIGHT: if walls_installed != 0: wall = wall_list[len(wall_list) - 1] X += 1 X = min(width - wall_length + 1, X) if wall['type'] == 'horizontal' and X > (width - wall_length): wall['type'] = 'vertical' wall['location'] = (X, Y) elif command == 'r': if walls_installed != 0: wall = wall_list[len(wall_list) - 1] if wall['type'] == 'horizontal': wall['type'] = 'vertical' elif wall['type'] == 'vertical': wall['type'] = 'horizontal' elif command == 'b': if walls_installed != 0: if wall['type'] in p[(X, Y)]: player['amount_of_walls'] -= walls_installed ready = True else: ready = False elif command == 's': if walls_installed != 0: removed_wall = wall_list.pop() (X, Y) = removed_wall['location'] walls_installed -=1 ready = False second_stage = False elif command == 'q': quit = True ready = True else: pass draw(player_list, wall_list, curscr) return quit
maze = bugzero.gen_s() tr = bugzero.get_trace(bug, maze) action_path = bugzero.trace_to_action_path(tr) experience.add_balanced(tr) batch = experience.n_sample(50) bug.learn(batch, "move") if i % 200 == 0: path = bugzero.trace_to_path(tr) print "iteration ", i print path action_path = bugzero.trace_to_action_path(tr) print action_path draw(maze, "maze.png", path, action_path) if i % 200 == 100: maze = bugzero_test.gen_s() tr = bugzero_test.get_trace(bug, maze) path = bugzero.trace_to_path(tr) print "iteration ", i print path action_path = bugzero.trace_to_action_path(tr) print action_path draw(maze, "maze_test.png", path, action_path) if i % 2000 == 1999: print "accuracy ", get_accuracy(bug, bugzero_test, 1000) bug.save_model("models/bug_bug_model.ckpt")
#print(type(t[i])) for num1, j in enumerate(t[i]): #print('num1 ' + str(num1)) #print (j) #print(t[i][j]) if j == value: inner[value] = t[i][j] out[i] = copy.deepcopy(inner) inner = {} #print(t[i][j]) return out max_error_dict = filter_dict('max_error', copy.deepcopy(t_dict)) #print(max_error_dict) draw(max_error_dict, 'max_error') explained_variance_score_dict = filter_dict('explained_variance_score', copy.deepcopy(t_dict)) #print(explained_variance_score_dict) draw(explained_variance_score_dict, 'explained_variance_score') mean_absolute_error_dict = filter_dict('mean_absolute_error', copy.deepcopy(t_dict)) #print(mean_absolute_error_dict) draw(mean_absolute_error_dict, 'mean_absolute_error') mean_squared_error_dict = filter_dict('mean_squared_error', copy.deepcopy(t_dict)) print(mean_squared_error_dict) draw(mean_squared_error_dict, 'mean_squared_error')
#!/usr/bin/env python from draw import * if __name__ == '__main__': board = [[X, O, E], [E, E, X], [E, E, E]] draw(board, raw=False)
def mouse(event, x, y, flags, param): if event == cv.EVENT_LBUTTONDOWN: pts.append((x, y)) draw(0)
import numpy as np from draw import * pts = [] def draw(x): d = cv.getTrackbarPos('thickness', 'window') d = -1 if d == 0 else d i = cv.getTrackbarPos('color', 'window') color = colors[i] img[:] = img0 cv.polylines(img, np.array([pts]), True, color, d) cv.imshow('window', img) text = f'color={color}, thickness={d}' cv.displayOverlay('window', text) def mouse(event, x, y, flags, param): if event == cv.EVENT_LBUTTONDOWN: pts.append((x, y)) draw(0) cv.setMouseCallback('window', mouse) cv.createTrackbar('color', 'window', 0, 6, draw) cv.createTrackbar('thickness', 'window', 2, 10, draw) draw(0) cv.waitKey(0) cv.destroyAllWindows()
# Read train dataset train = pd.read_csv(train_file) # Extract features for pda and lda train_feature_values = train[feature_columns].values # Extract target values (Class values) for pda and lda target_values = train['Class'].values # lda without pca lda1, lda_without_pca_df = analysis.lda(train_feature_values, target_values) print lda1.score(train_feature_values, target_values) # draw result draw(lda_without_pca_df, 'Wine Classification - LDA without PCA') # apply pca principal_components = analysis.pca(train_feature_values) # after pca apply lda lda2, lda_df = analysis.lda(principal_components, target_values) print lda2.score(principal_components, target_values) # draw result draw(lda_df, 'Wine Classification - LDA with PCA') exit(0)
def run_random(): screen.fill(BACKGROUNDCOLOR) image_array = [] mouse_text = pygame.image.load('python/wave/image/mouse.png') random_text = pygame.image.load('python/wave/image/random.png') for i in range(10): image_array.append(draw()) image = pygame.image.load('python/wave/image/circle3.png') while True: clock.tick(30) screen.blit(mouse_text, (800, 800)) screen.blit(random_text, (800, 900)) for event in pygame.event.get(): if event.type == QUIT: exit() elif event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() if (951 > x > 800) and (876 > y > 800): print('mouse') run_mouse() flag = random.randint(0, 100) if (flag % 10 == 0): x = random.randint(0, 1000) y = random.randint(0, 1000) for index, object in enumerate(image_array): if (object.life == 0): object.set_position(x, y) break for index, object in enumerate(image_array): if (object.y < 500): if object.life > 130: object.tscale(3) screen.blit(object.image, (object.x, object.y)) object.life -= 1 continue elif object.life > 120: object.tscale(2) screen.blit(object.image, (object.x, object.y)) object.life -= 1 continue elif object.life > 95: object.tscale(1) object.tscale2(3) screen.blit(object.image, (object.x, object.y)) screen.blit(object.image2, (object.x2, object.y2)) object.life -= 1 continue elif object.life > 90: object.tscale(1) object.tscale2(2) object.tscale3(3) screen.blit(object.image, (object.x, object.y)) screen.blit(object.image2, (object.x2, object.y2)) screen.blit(object.image3, (object.x3, object.y3)) object.life -= 1 continue elif object.life > 1: object.tscale(1) object.tscale3(2) object.tscale2(1) screen.blit(object.image, (object.x, object.y)) screen.blit(object.image2, (object.x2, object.y2)) screen.blit(object.image3, (object.x3, object.y3)) object.life -= 1 continue if object.life == 1: object.reset() else: if object.life > 130: object.tscale(3) screen.blit(object.image, (object.x, object.y)) object.life -= 1 continue elif object.life > 120: object.tscale(2) screen.blit(object.image, (object.x, object.y)) object.life -= 1 continue elif object.life > 95: object.tscale(1) object.tscale2(3) screen.blit(object.image, (object.x, object.y)) # screen.blit(object.image2, (object.x2, object.y2)) object.life -= 1 continue elif object.life > 90: object.tscale(1) object.tscale2(2) object.tscale3(3) screen.blit(object.image, (object.x, object.y)) # screen.blit(object.image2, (object.x2, object.y2)) # screen.blit(object.image3, (object.x3, object.y3)) object.life -= 1 continue elif object.life > 1: object.tscale(1) object.tscale3(2) object.tscale2(1) screen.blit(object.image, (object.x, object.y)) # screen.blit(object.image2, (object.x2, object.y2)) # screen.blit(object.image3, (object.x3, object.y3)) object.life -= 1 continue if object.life == 1: object.reset() pygame.display.update() screen.fill(BACKGROUNDCOLOR)
# evaluate every 2 epochs training_accuracy, training_around1_accuracy, training_around2_accuracy = evaluate( 'training/') testing_accuracy, testing_around1_accuracy, testing_around2_accuracy = evaluate( 'testing/') print("\ntraining_accuracy: ", training_accuracy) print("\naround1_accuracy: ", training_around1_accuracy) print("\naround2_accuracy: ", training_around2_accuracy) print("\ntesting_accuracy: ", testing_accuracy) print("\naround1_accuracy: ", testing_around1_accuracy) print("\naround2_accuracy: ", testing_around2_accuracy) #draw accuracies[0].append(training_accuracy) accuracies[1].append(testing_accuracy) accuracies[2].append(training_around1_accuracy) accuracies[3].append(testing_around1_accuracy) accuracies[4].append(training_around2_accuracy) accuracies[5].append(testing_around2_accuracy) draw(accuracies) torch.save(nnn.policy_value_net, 'model.pth') # print(labelmatrix) # np.savetxt('labels.txt', labelmatrix,'%5.0f', delimiter=',') # np.savetxt('predict.txt', predictmatrix, delimiter=',')
import xml.dom.minidom import sys import getopt from model_generator import * from draw import * if __name__ == "__main__": ''' dom = xml.dom.minidom.parse('document1.xml') root = dom.documentElement myList = root.getElementsByTagName('datacenter') for node in myList: alist = node.getElementsByTagName('ID') print(int(alist[0].childNodes[0].nodeValue)) alist = node.getElementsByTagName('failure') print(float(alist[0].childNodes[0].nodeValue)) ''' m = ModelGenerator('document1.xml') draw(m.topology.node[30000000001]['DATACENTER'].topology, "RACK")
def move(self,key): self.background.redraw() if key == 273 and (self.jump_h == 11 or not self.moveActivedJump): self.jump = 1 if self.moveActivedJump: self.jump_h = 0 else: self.jump_h = 4 elif key == 275: self.moveActived = 1 self.step *= -1 for i in range(len(self.senary.stone)-1): if self.pos.collidepoint(self.senary.stone[i].left-10,self.senary.stone[i].top): self.moveActived = 0 if self.moveActived: if self.pos.left >= 200: self.background.move(key) self.senary.move(-1) else: self.pos.move_ip(10,0) self.face = 1 elif key == 276: self.moveActived = 1 self.step *= -1 for i in range(len(self.senary.stone)-1): if self.pos.collidepoint(self.senary.stone[i].right,self.senary.stone[i].top): self.moveActived = 0 if self.moveActived: if self.pos.left == 100: self.background.move(key) self.senary.move(1) else: self.pos.move_ip(-10,0) self.face = 0 if self.jump: self.pos.move_ip(0,-20) if self.jump_h < 10: self.jump_h +=1 self.moveActivedJump = 1 for i in range(len(self.senary.stone)-1): if self.pos.collidepoint(self.senary.stone[i].right,self.senary.stone[i].top-10) or self.pos.collidepoint(self.senary.stone[i].left,self.senary.stone[i].top-10): self.moveActivedJump = 0 if self.jump_h == 10 and self.moveActivedJump: if self.pos.top < 320: self.pos.move_ip(0,20) else : self.jump_h += 1 self.jump = 0 if key == 32: self.tiro.play() self.shot.fire(self.pos.center,self.face,1) self.ia() if len(self.shot.dir): self.shot.move() i=-1 while i != len(self.shot.dir)-1: i+=1 for j in range(len(self.senary.stone)-1): if self.shot.pos[i].colliderect(self.senary.stone[j]): self.shot.dir.pop(i) self.shot.pos.pop(i) self.shot.origem.pop(i) i-=1 break i=-1 while i != len(self.shot.dir)-1: i+=1 for j in range(len(self.senary.inimigo)-1): if self.shot.pos[i].colliderect(self.senary.inimigo[j]) and self.shot.origem[i]: self.senary.inimigoLife[j] -=1 self.score += 50 if not self.senary.inimigoLife[j]: self.senary.inimigo.pop(j) self.senary.inimigoLife.pop(j) self.senary.inimigoDir.pop(j) self.senary.inimigoStep.pop(j) self.score += 300 self.shot.dir.pop(i) self.shot.pos.pop(i) self.shot.origem.pop(i) self.background.score = self.background.font.render(str(self.score),1,(0,0,0)) i-=1 break i=-1 while i != len(self.shot.dir)-1: i+=1 if self.shot.pos[i].colliderect(self.pos): self.shot.dir.pop(i) self.shot.pos.pop(i) self.shot.origem.pop(i) self.lifes() i-=1 break if len(self.senary.life): for i in range(len(self.senary.life)-1): if self.senary.life[i].colliderect(self.pos): self.senary.life.pop(i) self.life+=5 self.lifes() break if self.face: if self.step == 1: draw(self.img,(self.pos.left,self.pos.top)) else: draw(self.imgS,(self.pos.left,self.pos.top)) else: if self.step == 1: draw(self.imgC,(self.pos.left,self.pos.top)) else: draw(self.imgSC,(self.pos.left,self.pos.top)) rand = random.randint(0,80) if rand > 76 and rand < 79: self.senary.constructorAdd(0) elif rand == 80: self.senary.constructorAdd(1) self.senary.draw() if self.senary.stone[0].left == -2700: self.senary.move(350)
from variables import * from draw import * from ERROR import * import sys ##Main## try: draw() finally: raise SystemExit(0)
# The layer of the service we are focusing on # There are two types of layers, i.e., data center and rack # If we assign "RACK" to typeService, we will go into a given data # center. # If we assign "DATACENTER" to typeService, we will focus on # a given cloud with many data centers typeService = "RACK" app = App(1, 3, typeService, cloudList_for_job1) appList = [] appList.append(app) # 4 cloudList = [] cloudList.append(c1) # Since CRA has different types of algorithms: # "MC" means we are using Monte Carlo algorithm # The numbers of trials are set in the configuration.py file # The variable of trials is "TRIALS" # crr = CRR(cloudList, appList) algorithm = "Minimal" crr.build_fault_tree_for_app(algorithm) end = time.clock() print(end - start) # 6 draw(crr.faultTree, typeService)
return np.array(targets), np.array(input_states) oracle = Oracle(L, xform, bugzero.ACTIONS) # oracle.restore_model("models/bug_oracle_model.ckpt") for i in range(50000): maze = bugzero.gen_s() r_actor = bugzero.gen_a_star_actor(maze) trace = bugzero.get_trace(r_actor, maze) experience.add(trace) batch = gen_batch(experience, 50) oracle.train_model(batch) if i % 200 == 0: print "iteration ", i oracle.save_model("models/bug_oracle_model.ckpt") trace_oracle = bugzero.get_trace(oracle, maze) path = trace_to_path(trace_oracle) print path draw(maze, "maze.png", path) if i % 2000 == 0: print "accuracy ", get_accuracy(oracle, bugzero, 1000) print "finished training, measuring accuracy " print "accuracy ", get_accuracy(oracle, bugzero, 1000)
# whether we want to generate cloud service with common dependencies typeCloud = "CORRELATION" # generate cloud service c1 = Cloud("CORRELATION", 3, 4, 4, 4, 4, 4, 4, 4) # 2 cloudList_for_job1 = [] cloudList_for_job1.append(c1) # 3 typeService = "RACK" app = App(2, 2, typeService, cloudList_for_job1) appList = [] appList.append(app) # 4 cloudList = [] cloudList.append(c1) # 5 crr = CRR(cloudList, appList) algorithm = "Min" crr.build_fault_tree_for_app(algorithm) end = time.clock() print(end - start) # 6 draw(crr.faultTree, typeService)
def dim_reduce(img, times): def _dim_r(img_in): return skimage.measure.block_reduce(img_in, (2, 2), np.max) for t in range(times): img = _dim_r(img) return img def enhance(img, x, y): return img[x * 8:(x + 1) * 8, y * 8:(y + 1) * 8] def get_pyramid(img): return [dim_reduce(img, i) for i in range(4)] if __name__ == "__main__": sas = sample_planner_sa(1) for i, s_a in enumerate(sas): s, a = s_a # print s[0] pyramid = get_pyramid(s[0]) for j, p in enumerate(pyramid): draw(p, "drawings/ha{}_{}.png".format(i, j)) for x in range(10): for y in range(10): enh = enhance(s[0], x, y) draw(enh, "drawings/enh_{}_{}_{}.png".format(i, x, y))
def sky(self): draw(self.imgSky,(0,0))