def fourpeaks(savedir=None): # With early stopping t, r, timings = A2.fourpeaks(max_iter=np.inf, early_stop=2000, mimic_early_stop=50, n_runs=10, savedir=savedir)
def main(): print('\n***** Running Part B Question 1 *****') A1.main() print('\n***** Running Part B Question 3 *****') A3a.main() print('\n***** Running Part B Question 4 *****') A3b.main() print('\n***** Running Part B Question 5 *****') A3c.main() print('\n***** Running Part B Question 6 *****') A3d.main() print('\n***** Running Part B Question 2 *****') A2.main() print('\n\n***** ALL GRAPHS GENERATED ******')
def run(Ex): if Ex == "1": A1.a() elif Ex == "2": A2.b() elif Ex == "3": A3.c() elif Ex == "4": A4.d() elif Ex == "5": A5.e() elif Ex == "6": A6.f() elif Ex == "7": A7.g() elif Ex == "8": A8.h() elif Ex == "9": A9.i() elif Ex == "10": A10.j() elif Ex == "intro": Aintro.A() else: print "Invalid Exercise"
# ====================================================================================================================== # Task A1 model_A1 = A1.Model(settings.DATASET_CELEBRA_IMG, settings.DATASET_CELEBRA_CSV) # if settings.TUNE_MODELS: # model_A1.tune_model() # else: # model_A1.model = SVC(C=1) # acc_A1_train = model_A1.train() acc_A1_train = model_A1.train_cnn() acc_A1_test = model_A1.test(settings.DATASET_CELEBRA_TEST_IMG, settings.DATASET_CELEBRA_TEST_CSV) model_A1.cleanup() # ====================================================================================================================== # Task A2 model_A2 = A2.Model(settings.DATASET_CELEBRA_IMG, settings.DATASET_CELEBRA_CSV) if settings.TUNE_MODELS: model_A2.tune_model() else: model_A2.model = SVC(C=10000, gamma=2.6826957952797274e-06) acc_A2_train = model_A2.train() acc_A2_test = model_A2.test(settings.DATASET_CELEBRA_TEST_IMG, settings.DATASET_CELEBRA_TEST_CSV) model_A2.cleanup() # ====================================================================================================================== # Task B1 model_B1 = B1.Model(settings.DATASET_CARTOON_IMG, settings.DATASET_CARTOON_CSV) if settings.TUNE_MODELS: model_B1.tune_model() else: model_B1.model = SVC(C=10, kernel='poly')
def B2(command, subject, player_input): global success if command == 1 or command == 2 or command == 4: print delay("A wall blocks your way.") print success = False elif command == 3: history.append('visited') A2.A2_text(A2.history) elif command == 5: if subject.lower() in B2_inventory: overall.main_character.inventory[subject] = B2_inventory[subject] del B2_inventory[subject] print delay('%s has been added to inventory' % (subject)) elif subject.lower() in overall.main_character.inventory: print delay('%s already in inventory' % (subject)) else: print delay("Can not pick up %s" % (subject)) print success = False elif command == 6: print if subject.lower() in overall.main_character.inventory: B2_inventory[subject] = overall.main_character.inventory[subject] del overall.main_character.inventory[subject] delay('%s has been removed from inventory' % (subject)) else: delay('%s not in inventory' % (subject)) print success = False elif command == 7: if subject.lower() == 'chest' and overall.if_empty( B2_inventory) == False: print delay("The chest contains a: ") print for item in B2_inventory: print delay(item) print if overall.if_empty(B2_inventory) == True: print delay("This chest is empty") print print if 'searched' not in history: delay( "TUTORIAL: To use an item, type 'use' and the name of the item you want to use." ) print print delay( "TUTORIAL: To view the description of an object in your inventory type 'analyze' and the name of the object." ) print print history.append('searched') elif subject.lower() == 'chest' and overall.if_empty( B2_inventory) == True: print delay("This chest is empty") print else: print delay("Can not search %s" % (subject)) print success = False elif command == 8: print if subject.lower() in overall.main_character.inventory: overall.main_character.inventory[subject].use() if overall.main_character.inventory[ subject.lower()].form == 'food': del overall.main_character.inventory[subject.lower()] else: delay('No %s in inventory' % (subject)) print success = False elif command == 9: for item in overall.main_character.inventory: print delay(item) print if overall.if_empty(overall.main_character.inventory) == True: print delay("You have nothing in your inventory!") print success = False elif command == 10: print if subject.lower() in overall.main_character.inventory: overall.main_character.inventory[subject].describe() else: delay('%s not in inventory' % (subject)) print success = False elif command == 11: print overall.main_character.death() success = False else: success = False if success == False: B2_reit(nothing)
import os import platform import A2 """ @Author: Siddarth Krishnan @Date: 10/14/2016 This function takes a filepath that is entered by the user and opens the file to be played """ def openFile(musicFilePath): if platform.system() == 'Windows': os.startfile(musicFilePath) else: os.system("open" + " " + musicFilePath) input1 = input("Enter a path: ") openFile(input1) A2.run()
import sys import A2 from PyQt5.QtWidgets import QApplication, QMainWindow if __name__ == '_main_': app = QApplication(sys.argv) mainWindow = QMainWindow() ui = A2.ui_MainWindow() ui.setupUi(mainWindow) mainWindow.show() sys.exit(app.exec_())
import A2 from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split # Random Forest for A2 A2 = A2.A2() newX, newY = A2.preprocess('../Datasets/celeba/img', '../Datasets/celeba/labels.csv') X_train, X_test, y_train, y_test = train_test_split(newX, newY, test_size=0.2, random_state=45) rf = RandomForestClassifier(n_estimators=10) rf.fit(X_train, y_train) train_acc = rf.score(X_train, y_train) test_acc = rf.score(X_test, y_test) print('Random Forest accuracy:{:.4}', train_acc) print('Random Forest validation accuracy:{:.4}', test_acc)
printHelp("Invalid argument '{0}'.".format(args[i + 1])) elif (args[i] == '-s'): s = args[i + 1].upper() if (s == "BFS" or s == "DFS" or s == "UCS" or s == "GBF" or s == "A*1" or s == "A*2"): search = s else: printHelp("Invalid argument '{0}'.".format(s)) i += 1 # Runs the appropriate program with the appropriate starting state # based on set variables if (search == "BFS"): print("\n=== {0} BREADTH FIRST SEARCH ===".format(difficulty[0])) BFS.search(difficulty[1], goal) elif (search == "DFS"): print("\n=== {0} DEPTH FIRST SEARCH ===".format(difficulty[0])) DFS.search(difficulty[1], goal) elif (search == "UCS"): print("\n=== {0} UNIFORM COST SEARCH ===".format(difficulty[0])) UCS.search(difficulty[1], goal) elif (search == "GBF"): print("\n=== {0} GREEDY BEST-FIRST ===".format(difficulty[0])) GBF.search(difficulty[1], goal) elif (search == "A*1"): print("\n=== {0} A*1 ===".format(difficulty[0])) A1.search(difficulty[1], goal) elif (search == "A*2"): print("\n=== {0} A*2 ===".format(difficulty[0])) A2.search(difficulty[1], goal)
import tools import sys homographDatabase = tools.loadDatabase("Database/homograph_database.txt") sourceCode = tools.preprocessing(sys.argv[1]) result = A1.evaluate(sourceCode) if result: print("A1 Suspicious") for line in result: print(line) else: print("A1 Benign") result = A2.evaluate(sourceCode) if result: print("A2 Suspicious") for line in result: print(line) else: print("A2 Benign") result = A3.evaluate(sourceCode) if result: print("A3 Suspicious") for line in result: print(line) else: print("A3 Benign")
def A3(command, subject, player_input): global success if command == 1 or command == 3: print delay("A wall blocks your way.") print success = False elif command == 2: history.append('visited') B3.B3_text(B3.history) success = True elif command == 4: history.append('visited') A2.A2_text(A2.history) elif command == 5: if subject.lower() in A3_inventory: overall.main_character.inventory[subject] = A3_inventory[subject] del A3_inventory[subject] print delay("%s has been added to inventory" %(subject)) elif subject.lower() in overall.enemy1.inventory: overall.main_character.inventory[subject] = overall.enemy1.inventory[subject] del overall.enemy1.inventory[subject] print delay('%s has been added to inventory' %(subject)) elif subject.lower() in overall.main_character.inventory: print delay('%s already in inventory' %(subject)) else: print delay("Can not pick up %s" %(subject)) print success = False elif command == 6: print if subject.lower() in overall.main_character.inventory: A3_inventory[subject] = overall.main_character.inventory[subject] del overall.main_character.inventory[subject] delay('%s has been removed from inventory' %(subject)) else: delay('%s not in inventory' %(subject)) print success = False elif command == 7: if subject.lower() == 'enemy' and overall.if_empty(overall.enemy1.inventory) == False: print delay("The body of the enemy contains a: ") print for item in overall.enemy1.inventory: print delay(item) print print elif subject.lower() == 'enemy' and overall.if_empty(overall.enemy1.inventory) == True: print delay("This body carries nothing on it") print else: print delay("Cannot search %s" %(subject)) print print success = False elif command == 8: print if subject.lower() in overall.main_character.inventory: overall.main_character.inventory[subject.lower()].use() if overall.main_character.inventory[subject.lower()].form == 'food': del overall.main_character.inventory[subject.lower()] else: delay('No %s in inventory' %(subject)) print success = False elif command == 9: for item in overall.main_character.inventory: print delay(item) print if overall.if_empty(overall.main_character.inventory) == True: print delay("You have nothing in your inventory!") print success = False elif command == 10: print if subject.lower() in overall.main_character.inventory: overall.main_character.inventory[subject].describe() else: delay('%s not in inventory' %(subject)) print success = False elif command == 11: print overall.main_character.death() success = False else: success = False if success == False: A3_reit(nothing)
def onemax(savedir=None): t, r, timings = A2.onemax(max_iter=np.inf, early_stop=1000, mimic_early_stop=10, n_runs=5, savedir=savedir)
def flipflop(savedir=None): t, r, timings = A2.flipflop(max_iter=np.inf, early_stop=200, mimic_early_stop=20, n_runs=1, savedir=savedir)
def tsp(savedir=None): t, r, timings = A2.tsp(max_iter=np.inf, early_stop=1000, mimic_early_stop=50, n_runs=5, savedir=savedir)
def A1(command, subject, player_input): global success if command == 1: history.append("visited") A2.A2_text(A2.history) success = True elif command == 2 or command == 3: print delay("A wall blocks your way") print success = False elif command == 4: print delay("This door is closed and sealed.") print success = False elif command == 5: if subject.lower() in A1_inventory: overall.main_character.inventory[subject] = A1_inventory[subject] del A1_inventory[subject] print delay("%s has been added to inventory" % (subject)) elif subject.lower() in overall.main_character.inventory: print delay('%s already in inventory' % (subject)) else: print delay("Can not pick up %s" % (subject)) print success = False elif command == 6: print if subject.lower() in overall.main_character.inventory: A1_inventory[subject] = overall.main_character.inventory[subject] del overall.main_character.inventory[subject] delay('%s has been removed from inventory' % (subject)) else: delay('%s not in inventory' % (subject)) print success = False elif command == 7: print delay("Nothing here to search") print success = False elif command == 8: print if subject.lower() in overall.main_character.inventory: overall.main_character.inventory[subject].use() if overall.main_character.inventory[ subject.lower()].form == 'food': del overall.main_character.inventory[subject.lower()] else: delay("No %s in inventory" % (subject)) print success = False elif command == 9: for item in overall.main_character.inventory: print delay(item) print if overall.if_empty(overall.main_character.inventory) == True: print delay("You have nothing in your inventory!") print success = False elif command == 10: print if subject.lower() in overall.main_character.inventory: overall.main_character.inventory[subject].describe() else: delay("%s not in inventory" % (subject)) print success = False elif command == 11: print overall.main_character.death() success = False else: success = False if success == False: A1_reit(nothing)