def xTrain(labels, values=None, k=10, rand=True): # Split data into k partitions partitions = split(labels, values, k, rand) best_model = None best_acc = -1 avg_acc = 0 count = 0 if isinstance(labels, dict): values = [j for i in labels.itervalues() for j in i.itervalues()] labels = [i + 1 for i in range(len(labels.values())) for j in range(len(labels[labels.keys()[i]]))] if values != None: optParam = Param() print "Searching for optimal parameters..." optParam.c, optParam.g = getOptCG(labels, values) print "c: " + str(optParam.c) + " g: " + str(optParam.g) print " " # For each partition, train a model and check the accuracy of the partition's test data against # the model. The highest accuracy model will be the model returned. The accuracy returned is the # average accuracy of all the partitions for i in partitions.iter: print "Training iteration " + str(count + 1) + ".." # Train the model using the partition training data model = svmtrain(i.train.labels, i.train.values, optParam.c, optParam.g) # Get a list of predictions for the testing data pred = svmtest(i.test.values, model) # Find the accuracy of the test data predicted by the model acc, x1, x2 = evaluations(i.test.labels, pred) # Store the model with the best accuracy if acc > best_acc: best_acc = acc best_model = model print "Iteration " + str(count + 1) + " accuracy: " + str(acc) avg_acc += acc count += 1 # Get the avg accuracy avg_acc /= count print " " print "xTrain completed." return model, avg_acc
def getOptCG(labels, values): # Format data for subsequent methods # Set up cross-validation settings param = Param() param.cset = range(-5, 15, 2) param.gset = range(3, -15, -2) param.nfold = 10 prob = svm_problem(labels, values) rVal = [[0 for col in range(len(param.cset))] for row in range(len(param.gset))]; # Cross-validation to get optimal parameters for i in range(len(param.gset)): param.g = 2 ** param.gset[i] for j in range(len(param.cset)): param.c = 2 ** param.cset[j] testParam = svm_parameter(param.libsvm) # Train on learning data with x-validation and store result rVal[i][j] = svm_train(prob, param.libsvm + " -v " + str(param.nfold)) # Select the parameters with highest accuracy min_val, loc = getMax(rVal) g = 2 ** param.gset[loc[0]] c = 2 ** param.cset[loc[1]] return c, g
def maximization(data, update_gamma): update_param = Param.Param(len(data)) update_param.pi[0] = update_gamma.sum(axis=0)[0] / len(data) update_param.pi[1] = 1 - update_param.pi[0] update_param.mu_1 = get_mean(data, update_gamma, 0) update_param.mu_2 = get_mean(data, update_gamma, 1) update_param.sigma_1 = get_var(data, update_gamma, 0, update_param.mu_1) update_param.sigma_2 = get_var(data, update_gamma, 1, update_param.mu_2) return update_param
def svmtrain(labels, values=None, c=None, g=None): # If Dictionary if isinstance(labels, dict): values = [j for i in labels.itervalues() for j in i.itervalues()] labels = [i + 1 for i in range(len(labels.values())) for j in range(len(labels[labels.keys()[i]]))] if values != None: optParam = Param() optParam.c = c optParam.g = g if c == None or g == None: # Retrieve optimal c and g optParam.c, optParam.g = getOptCG(labels, values) # Train model with optimal c and g prob = svm_problem(labels, values) m = svm_train(prob, optParam.libsvm) # Return model return m else: raise TypeError("Values not provided for the arguments")
def __init__(self, capacity, env, eps_sche): self.memory = Memory.Memory(capacity) self.eps_scheduler = eps_sche screen = Param.get_screen(env) _, h, w = screen.shape self.num_act = env.action_space.n # self.policy = Net.FCN(h, w, self.num_act).to(Param.device) # self.target = Net.FCN(h, w, self.num_act).to(Param.device) # self.state_based = False self.policy = Net.FullyConnected(env.observation_space.shape[0], self.num_act).to(Param.device) self.target = Net.FullyConnected(env.observation_space.shape[0], self.num_act).to(Param.device) self.state_based = True self.target.load_state_dict(self.policy.state_dict()) self.target.train(False) self.optimizer = torch.optim.Adam(self.policy.parameters(), lr=Param.LEARNING_RATE, weight_decay=0.001, amsgrad=True) self.step = 0
from skimage.transform import pyramid_gaussian import cv2 as cv from helper import sliding_window import os import csv from crater_cnn import Network as CNN from crater_nn import Network as NN import Param import argparse # This script will go through all image tiles and detects crater area using sliding window method. # Then, write results as a csv file to the results folder. The results of this script is the input to the remove_duplicates.py script. # you need to provide the tile image name as argument after --tileimg command. For instance tile1_24 param = Param.Param() cwd = os.getcwd() # setup CNN cnn = CNN(img_shape=(50, 50, 1)) cnn.add_convolutional_layer(5, 16) cnn.add_convolutional_layer(5, 36) cnn.add_flat_layer() cnn.add_fc_layer(size=64, use_relu=True) cnn.add_fc_layer(size=16, use_relu=True) cnn.add_fc_layer(size=2, use_relu=False) cnn.finish_setup() # model.set_data(data) # restore previously trained CNN model cnn_model_path = os.path.join(cwd, 'models/cnn/crater_model_cnn.ckpt') cnn.restore(cnn_model_path)
def command(self, c): c = c.strip() if c == "help": print("""Welcome to the Key Server Admin! ** [Verb] [Type] [Optional Param] ** Verbs: - List = List out all the specified TYPE ex. list app - Create = Create a new TYPE ex. create user - Update = Update a TYPE, the item to modify is specified as an additional parameter ex. update app test - Delete = Delete a TYPE, the item to delete is specified as an additional parameter ex. delete param url Types: - app = Applications - Act like folders for Parameters - key = API Key - used by clients to fetch params - param = Parameter, requires an app to be selected - user = Admin User ** select [App_Name] ** Select allows you to select an application to work with. This is required when you want to modify parameters. ** exit ** If an app is currently selected, goes back to home. If no app is currently selected, quits the admin CLI ** help ** Lists this help info""") elif c.lower().__contains__("select"): try: target_app = c.split(" ")[1] except IndexError: print( "Invalid select condition - please specify which app you want to select" ) return if target_app in App.list_apps(self.username, self.password): CLI.current_app = target_app else: print( "That is not a valid app name, type 'list apps' to see all the current apps." ) elif c.lower().__contains__("list"): try: list_item = c.lower().split(" ")[1] except IndexError: print( "Invalid list condition - please specify what you want to list" ) return if list_item.__contains__("-h") or list_item.__contains__("help"): print( """List allows you to list out different applications, keys, users, and parameters. ** list [type] ** type `help` to list out all the types and their roles In order to list parameters, an application needs to be selected.""") elif list_item.__contains__("users"): for u in User.list_users(self.username, self.password): print("\t%s (%s)" % (u['username'], u['email'])) elif list_item.__contains__("apps"): for a in App.list_apps(self.username, self.password): print("\t" + a) elif list_item.__contains__("key"): for k in Key.list_keys(self.username, self.password): print("\t%s (%s)\n" "\t\t Permissions: %s" % (k["application_name"], k["application_key"], k["permissions"])) elif list_item.__contains__("param"): if CLI.current_app == "": print("Cannot list params when no app is selected") else: for p in Param.list_params(self.username, self.password, CLI.current_app): print("\t%s = %s" % (p['name'], p['value'])) else: print( "Unknown List Command - type `list -h` or `list help` for help." ) elif c.lower().__contains__("create"): try: create_item = c.lower().split(" ")[1] except IndexError: print( "Invalid create condition - please specify what you want to create" ) return if create_item.__contains__("-h") or create_item.__contains__( "help"): print( """Create allows you to create new applications, keys, users, and parameters ** create [type] ** type `help` to list out all the types and their roles In order to create parameters, an application needs to be selected.""") elif create_item.__contains__("user"): while True: username = raw_input("\tUsername: "******"\tPassword: "******"\tConfirm Password: "******"Passwords do not match. Try Again.") email = raw_input("\tEmail: ").strip() conf = raw_input( "\n\tUsername: %s\n\tPassword: %s\n\tEmail: %s\n\tIs this correct [Y/n]" % (username, password, email)).strip() if conf.lower() == "y" or conf == "": user = User.create_new(self.username, self.password, username, password, email) print("Created New User: %s" % user["username"]) break elif create_item.__contains__("app"): while True: app_name = raw_input("\tApplication Name: ").strip() conf = raw_input( "\n\tApplication Name: %s\n\tIs this correct [Y/n]" % app_name).strip() if conf.lower() == "y" or conf == "": app = App.create_app(self.username, self.password, app_name) print("Created New App: %s" % app["name"]) break elif create_item.__contains__("key"): while True: application_name = raw_input( "\tApplication Name: ").strip() print( "\tIn case you need a refresher... Application permissions are as follows:\n" "\t\t* use +app_name to whitelist the key for that app\n" "\t\t* use -app_name to blacklist the key for that app\n" "\t\t* use NO to revoke the key\n" "\t\t* or use ALL to grant the key access to all apps") permissions = raw_input( "\tApplication Permissions: ").strip() if permissions == "": permissions = "ALL" conf = raw_input( "\n\tName: %s\n\tPermissions: %s\n\tIs this correct [Y/n]" % (application_name, permissions)).strip() if conf.lower() == "y" or conf == "": key = Key.create_key(self.username, self.password, application_name, permissions) print("Created New Key: %s" % key["application_key"]) break elif create_item.__contains__("param"): if CLI.current_app == "": print("Cannot create param when no app is selected") else: while True: param_name = raw_input("\tParameter Name: ").strip() param_value = raw_input("\tParameter Value: ").strip() conf = raw_input( "\n\tParameter Name: %s\n\tParameter Value: %s\n\tIs this correct [Y/n]" % (param_name, param_value)) \ .strip() if conf.lower() == "y" or conf == "": param = Param.create_param(self.username, self.password, CLI.current_app, param_name, param_value) print("Created New Parameter: %s" % param["name"]) break else: print( "Unknown Create Command - type `create -h` or `create help` for help." ) elif c.lower().__contains__("update"): try: update_item = c.lower().split(" ")[1] except IndexError: print( "Invalid update condition - please specify what you want to update" ) return try: update_item_name = c.split(" ")[2] except IndexError: print( "Invalid update condition - please specify which %s you want to update." % update_item) return if update_item.__contains__("-h") or update_item.__contains__( "help"): print( """Update allows you to update existing applications, keys, users, and parameters ** update [type] [username/applicationName/applicationKey/parameterName]** type `help` to list out all the types and their roles In order to create parameters, an application needs to be selected.""") elif update_item.__contains__("user"): user_info = User.list_users(self.username, self.password) for u in user_info: if u['username'] == update_item_name: user_info = u break while True: password = None while True: password = getpass.getpass( "\tNew Password [Leave blank to keep]: ") password_conf = getpass.getpass( "\tConfirm New Password: "******"Passwords do not match. Try Again.") email = raw_input("\tEmail [%s]: " % user_info['email']).strip() email = email if email != "" else user_info['email'] conf = raw_input( "\n\tUsername: %s\n\tPassword: %s\n\tEmail: %s\n\tIs this correct [Y/n]" % (update_item_name, password, email)).strip() if conf.lower() == "y" or conf == "": user = User.update_user(self.username, self.password, update_item_name, password=password, email=email) # Updating the current user's password, so let's update the one we are using to login to the API if update_item_name == self.username: self.password = password print("Updated User: %s" % user["username"]) break elif update_item.__contains__("key"): key_info = Key.list_keys(self.username, self.password) for k in key_info: if k['application_key'] == update_item_name: key_info = k break while True: application_name = raw_input("\tApplication Name [%s]: " % key_info['application_name']) permissions = raw_input("\tPermissions [%s]: " % key_info['permissions']) conf = raw_input( "\n\tName: %s\n\tPermissions: %s\n\tIs this correct [Y/n]" % (application_name, permissions)).strip() if conf.lower() == "y" or conf == "": key = Key.update_key(self.username, self.password, update_item_name, application_name=application_name, permissions=permissions) print("Updated Key: %s" % key['application_key']) break elif update_item.__contains__("param"): if CLI.current_app == "": print("Cannot update param when no app is selected") else: while True: param_value = raw_input("\tNew Value Value: ").strip() conf = raw_input( "\n\tParameter Value: %s\n\tIs this correct [Y/n]" % param_value).strip() if conf.lower() == "y" or conf == "": param = Param.update_param(self.username, self.password, CLI.current_app, update_item_name, param_value) print("Updated Parameter: %s" % param["name"]) break else: print( "Unknown Update Command - type `update -h` or `update help` for help." ) elif c.lower().__contains__("delete"): try: delete_item = c.lower().split(" ")[1] except IndexError: print( "Invalid delete condition - please specify what you want to delete" ) return try: delete_item_name = c.split(" ")[2] except IndexError: print( "Invalid delete condition - please specify which %s you want to delete." % delete_item) return if delete_item.__contains__("-h") or delete_item.__contains__( "help"): print( """Delete allows you to remove applications, users, and parameters. Delete revokes keys, which is the only delete action that can be undone; to reactivate a revoked key, update the permissions of the key. ** update [type] [username/applicationName/applicationKey/parameterName]** type `help` to list out all the types and their roles In order to create parameters, an application needs to be selected.""") elif delete_item.__contains__("user"): conf = raw_input( "\n\tUsername to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = User.delete_user(self.username, self.password, delete_item_name) if status: print("User was deleted Successfully") else: print( "Problem deleting user, check server logs for details" ) elif delete_item.__contains__("app"): conf = raw_input( "\n\tApplication to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = App.delete_app(self.username, self.password, delete_item_name) if status: print("App was deleted Successfully") else: print( "Problem deleting app, check server logs for details" ) elif delete_item.__contains__("key"): conf = raw_input( "\n\tKey to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = Key.delete_key(self.username, self.password, delete_item_name) if status: print( "Key was Revoked Successfully - to reactivate the Key, update its permissions" ) else: print( "Problem revoking key, check server logs for details" ) elif delete_item.__contains__("param"): if CLI.current_app == "": print("Cannot delete param when no app is selected") else: conf = raw_input( "\n\tParam to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = Param.delete_param(self.username, self.password, CLI.current_app, delete_item_name) if status: print("Param was deleted Successfully") else: print( "Problem deleting param, check server logs for details" ) else: print( "Unknown Delete Command - type `delete -h` or `delete help` for help." ) elif c.lower().__contains__("exit"): if CLI.current_app == "": exit(0) else: CLI.current_app = "" else: print("Command not recognized")
def ppparams(): p = Param() p.processParam() l = p.getAll() for pp in sorted(l): print(pp + " : " + str(l[pp]))
def ppanalyze(datafile, formatfile, output, timegroupby, timeformat, decimal, highresponsetime, buckets, autofocusmean, autofocuscount, ymax, xstats, ppregex, timeregex, start, end, steps, ppregexclude, workdir, type, verbose, quick, tocsvs, nobuckets, nodescribe, nographs): p = Param() p.set('datafile', datafile) p.set('output', output) p.set('formatfile', formatfile) p.set('workdir', workdir) p.set('verbose', verbose) p.set('nographs', nographs) p.set('quick', quick) p.set('nodescribe', nodescribe) p.set('highResponseTime', highresponsetime) p.set('steps', steps) p.set('buckets', buckets) p.set('timeFormat', timeformat) p.set('decimal', decimal) p.set('ymax', ymax) p.set('xstats', xstats) p.set('tocsvs', tocsvs) p.set('ppregex', ppregex) p.set('start', start) p.set('end', end) p.set('timeregex', timeregex) p.set('ppregexclude', ppregexclude) p.set('type', type) p.set('timeGroupby', timegroupby) p.set('autofocusmean', autofocusmean) p.set('autofocuscount', autofocuscount) p.processParam() l = p.getAll() pp = PPAnalyzeProcessor(p) pp.setBehavior() pp.go() l = p.getAll() l['out'].close()
def ppcompare( file1, file2, output, highresponsetime, autofocusmean, autofocuscount, ymax, xstats, ppregex, ppregexclude, verbose, ): p = Param() p.set('file1', file1) p.set('file2', file2) p.set('verbose', verbose) p.set('output', output) p.set('highResponseTime', highresponsetime) p.set('ppregex', ppregex) p.set('ymax', ymax) p.set('xstats', xstats) p.set('ppregexclude', ppregexclude) p.set('autofocuscount', autofocuscount) p.set('autofocusmean', autofocusmean) p.processParam() l = p.getAll() pp = PPCompareProcessor(p) pp.setBehavior() pp.go() l = p.getAll() l['out'].close()
def sqlcompare( file1, file2, output, highresponsetime, autofocusmean, autofocuscount, sqlregex, sqlregexclude, verbose, ): p = Param() p.set('file1', file1) p.set('file2', file2) p.set('verbose', verbose) p.set('output', output) p.set('highResponseTime', highresponsetime) p.set('sqlregex', sqlregex) p.set('sqlregexclude', sqlregexclude) p.set('autofocuscount', autofocuscount) p.set('autofocusmean', autofocusmean) p.processParam() l = p.getAll() pp = SQLCompareProcessor(p) pp.setBehavior() pp.go() l = p.getAll() l['out'].close()
audittrail(L_audit, "text", "open default processing parameters") L_p_in = {} else: audittrail(L_audit, "phase", "Loading parameters") L_p_in = dict_load( L_paramfilename ) # load p_in as a regular dict, will be copied to the NPKParam when building default values audittrail(L_audit, "text", "open processing parameters", "parameter file", L_paramfilename) # gather additionnal parameters on the calling line, in the form key=value while L_argv: L_k = L_argv.pop(0) try: (L_dkey, L_fval) = Param.parse(L_k) except: raise L_k + ': error in parameter syntax, should be key=value' print("Additional property :", L_dkey, "=", L_fval) try: # check key existence L_val = L_p_in[L_dkey] except: pass else: print("WARNING, key -", L_dkey, "- defined twice") print(" previous value :", L_val) L_p_in[L_dkey] = L_fval audittrail(L_audit, "text", "additional parameter", L_dkey, L_fval) audittrail(L_audit, "text", "open input file parameters")
def command(self, c): c = c.strip() if c == "help": print("""Welcome to the Key Server Admin! ** [Verb] [Type] [Optional Param] ** Verbs: - List = List out all the specified TYPE ex. list app - Create = Create a new TYPE ex. create user - Update = Update a TYPE, the item to modify is specified as an additional parameter ex. update app test - Delete = Delete a TYPE, the item to delete is specified as an additional parameter ex. delete param url Types: - app = Applications - Act like folders for Parameters - key = API Key - used by clients to fetch params - param = Parameter, requires an app to be selected - user = Admin User ** select [App_Name] ** Select allows you to select an application to work with. This is required when you want to modify parameters. ** exit ** If an app is currently selected, goes back to home. If no app is currently selected, quits the admin CLI ** help ** Lists this help info""") elif c.lower().__contains__("select"): try: target_app = c.split(" ")[1] except IndexError: print("Invalid select condition - please specify which app you want to select") return if target_app in App.list_apps(self.username, self.password): CLI.current_app = target_app else: print("That is not a valid app name, type 'list apps' to see all the current apps.") elif c.lower().__contains__("list"): try: list_item = c.lower().split(" ")[1] except IndexError: print("Invalid list condition - please specify what you want to list") return if list_item.__contains__("-h") or list_item.__contains__("help"): print("""List allows you to list out different applications, keys, users, and parameters. ** list [type] ** type `help` to list out all the types and their roles In order to list parameters, an application needs to be selected.""") elif list_item.__contains__("users"): for u in User.list_users(self.username, self.password): print("\t%s (%s)" % (u['username'], u['email'])) elif list_item.__contains__("apps"): for a in App.list_apps(self.username, self.password): print("\t" + a) elif list_item.__contains__("key"): for k in Key.list_keys(self.username, self.password): print ("\t%s (%s)\n" "\t\t Permissions: %s" % (k["application_name"], k["application_key"], k["permissions"])) elif list_item.__contains__("param"): if CLI.current_app == "": print("Cannot list params when no app is selected") else: for p in Param.list_params(self.username, self.password, CLI.current_app): print("\t%s = %s" % (p['name'], p['value'])) else: print("Unknown List Command - type `list -h` or `list help` for help.") elif c.lower().__contains__("create"): try: create_item = c.lower().split(" ")[1] except IndexError: print("Invalid create condition - please specify what you want to create") return if create_item.__contains__("-h") or create_item.__contains__("help"): print("""Create allows you to create new applications, keys, users, and parameters ** create [type] ** type `help` to list out all the types and their roles In order to create parameters, an application needs to be selected.""") elif create_item.__contains__("user"): while True: username = raw_input("\tUsername: "******"\tPassword: "******"\tConfirm Password: "******"Passwords do not match. Try Again.") email = raw_input("\tEmail: ").strip() conf = raw_input("\n\tUsername: %s\n\tPassword: %s\n\tEmail: %s\n\tIs this correct [Y/n]" % (username, password, email)).strip() if conf.lower() == "y" or conf == "": user = User.create_new(self.username, self.password, username, password, email) print("Created New User: %s" % user["username"]) break elif create_item.__contains__("app"): while True: app_name = raw_input("\tApplication Name: ").strip() conf = raw_input("\n\tApplication Name: %s\n\tIs this correct [Y/n]" % app_name).strip() if conf.lower() == "y" or conf == "": app = App.create_app(self.username, self.password, app_name) print("Created New App: %s" % app["name"]) break elif create_item.__contains__("key"): while True: application_name = raw_input("\tApplication Name: ").strip() print("\tIn case you need a refresher... Application permissions are as follows:\n" "\t\t* use +app_name to whitelist the key for that app\n" "\t\t* use -app_name to blacklist the key for that app\n" "\t\t* use NO to revoke the key\n" "\t\t* or use ALL to grant the key access to all apps") permissions = raw_input("\tApplication Permissions: ").strip() if permissions == "": permissions = "ALL" conf = raw_input("\n\tName: %s\n\tPermissions: %s\n\tIs this correct [Y/n]" % ( application_name, permissions)).strip() if conf.lower() == "y" or conf == "": key = Key.create_key(self.username, self.password, application_name, permissions) print("Created New Key: %s" % key["application_key"]) break elif create_item.__contains__("param"): if CLI.current_app == "": print("Cannot create param when no app is selected") else: while True: param_name = raw_input("\tParameter Name: ").strip() param_value = raw_input("\tParameter Value: ").strip() conf = raw_input( "\n\tParameter Name: %s\n\tParameter Value: %s\n\tIs this correct [Y/n]" % (param_name, param_value)) \ .strip() if conf.lower() == "y" or conf == "": param = Param.create_param(self.username, self.password, CLI.current_app, param_name, param_value) print("Created New Parameter: %s" % param["name"]) break else: print("Unknown Create Command - type `create -h` or `create help` for help.") elif c.lower().__contains__("update"): try: update_item = c.lower().split(" ")[1] except IndexError: print("Invalid update condition - please specify what you want to update") return try: update_item_name = c.split(" ")[2] except IndexError: print("Invalid update condition - please specify which %s you want to update." % update_item) return if update_item.__contains__("-h") or update_item.__contains__("help"): print("""Update allows you to update existing applications, keys, users, and parameters ** update [type] [username/applicationName/applicationKey/parameterName]** type `help` to list out all the types and their roles In order to create parameters, an application needs to be selected.""") elif update_item.__contains__("user"): user_info = User.list_users(self.username, self.password) for u in user_info: if u['username'] == update_item_name: user_info = u break while True: password = None while True: password = getpass.getpass("\tNew Password [Leave blank to keep]: ") password_conf = getpass.getpass("\tConfirm New Password: "******"Passwords do not match. Try Again.") email = raw_input("\tEmail [%s]: " % user_info['email']).strip() email = email if email != "" else user_info['email'] conf = raw_input("\n\tUsername: %s\n\tPassword: %s\n\tEmail: %s\n\tIs this correct [Y/n]" % (update_item_name, password, email)).strip() if conf.lower() == "y" or conf == "": user = User.update_user(self.username, self.password, update_item_name, password=password, email=email) # Updating the current user's password, so let's update the one we are using to login to the API if update_item_name == self.username: self.password = password print("Updated User: %s" % user["username"]) break elif update_item.__contains__("key"): key_info = Key.list_keys(self.username, self.password) for k in key_info: if k['application_key'] == update_item_name: key_info = k break while True: application_name = raw_input("\tApplication Name [%s]: " % key_info['application_name']) permissions = raw_input("\tPermissions [%s]: " % key_info['permissions']) conf = raw_input("\n\tName: %s\n\tPermissions: %s\n\tIs this correct [Y/n]" % ( application_name, permissions)).strip() if conf.lower() == "y" or conf == "": key = Key.update_key(self.username, self.password, update_item_name, application_name=application_name, permissions=permissions) print("Updated Key: %s" % key['application_key']) break elif update_item.__contains__("param"): if CLI.current_app == "": print("Cannot update param when no app is selected") else: while True: param_value = raw_input("\tNew Value Value: ").strip() conf = raw_input("\n\tParameter Value: %s\n\tIs this correct [Y/n]" % param_value).strip() if conf.lower() == "y" or conf == "": param = Param.update_param(self.username, self.password, CLI.current_app, update_item_name, param_value) print("Updated Parameter: %s" % param["name"]) break else: print("Unknown Update Command - type `update -h` or `update help` for help.") elif c.lower().__contains__("delete"): try: delete_item = c.lower().split(" ")[1] except IndexError: print("Invalid delete condition - please specify what you want to delete") return try: delete_item_name = c.split(" ")[2] except IndexError: print("Invalid delete condition - please specify which %s you want to delete." % delete_item) return if delete_item.__contains__("-h") or delete_item.__contains__("help"): print("""Delete allows you to remove applications, users, and parameters. Delete revokes keys, which is the only delete action that can be undone; to reactivate a revoked key, update the permissions of the key. ** update [type] [username/applicationName/applicationKey/parameterName]** type `help` to list out all the types and their roles In order to create parameters, an application needs to be selected.""") elif delete_item.__contains__("user"): conf = raw_input("\n\tUsername to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = User.delete_user(self.username, self.password, delete_item_name) if status: print("User was deleted Successfully") else: print("Problem deleting user, check server logs for details") elif delete_item.__contains__("app"): conf = raw_input("\n\tApplication to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = App.delete_app(self.username, self.password, delete_item_name) if status: print("App was deleted Successfully") else: print("Problem deleting app, check server logs for details") elif delete_item.__contains__("key"): conf = raw_input("\n\tKey to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = Key.delete_key(self.username, self.password, delete_item_name) if status: print("Key was Revoked Successfully - to reactivate the Key, update its permissions") else: print("Problem revoking key, check server logs for details") elif delete_item.__contains__("param"): if CLI.current_app == "": print("Cannot delete param when no app is selected") else: conf = raw_input("\n\tParam to remove: %s\n\tIs this correct [Y/n]" % delete_item_name).strip() if conf.lower() == "y" or conf == "": status = Param.delete_param(self.username, self.password, CLI.current_app, delete_item_name) if status: print("Param was deleted Successfully") else: print("Problem deleting param, check server logs for details") else: print("Unknown Delete Command - type `delete -h` or `delete help` for help.") elif c.lower().__contains__("exit"): if CLI.current_app == "": exit(0) else: CLI.current_app = "" else: print("Command not recognized")
import DQN import Param import EpsScheduler import gym from gym import logger, wrappers import torch import numpy as np from tensorboardX import SummaryWriter if __name__ == '__main__': env = Param.get_env() logger.set_level(logger.INFO) env = wrappers.Monitor(env, directory='/tmp/DQN', force=True) writer = SummaryWriter('./Result') eps_sche = EpsScheduler.EpsScheduler(1., 'Linear', lower_bound=0.1, target_steps=100000) dqn = DQN.DQN(Param.MEMORY_SIZE, env, eps_sche) avgloss = 0. cnt = 0 i = 0 loop = 0 episode_step = 0 eps_to_win = 100 while i < Param.NUM_EPISODE: state = env.reset() if dqn.state_based: state[0] /= 4.8 state[1] /= 4.8 state[2] /= 0.418
def launch(): p = Param() p.set('datafile', datafile) p.set('output', output) p.set('formatfile', formatfile) p.set('pandas', pandas) p.set('verbose', verbose) p.processParams()
import numpy as np from utils import * import Param import em import matplotlib.pyplot as plt if __name__ == "__main__": # define hyperparameters num_cluster_1 = 200 num_cluster_2 = 300 mu_1 = np.array([3, 3]) mu_2 = np.array([-3, -3]) sigma_1 = np.array([[2, 0], [0, 4.5]]) sigma_2 = np.array([[1, 0], [0, 8]]) data = generate_data(num_cluster_1, num_cluster_2, mu_1, mu_2, sigma_1, sigma_2) savefig(data, mu_1, mu_2, "ground_truth") # set a dataset with randomly assigned labels data_exp = np.copy(data) data_exp[:, 2] = np.random.randint(2, size=num_cluster_1 + num_cluster_2) # start with a randomly guess param = Param.Param(num_cluster_1 + num_cluster_2) data, param = em.EM(data_exp, param)
def vetoWorkerName(self, paramChangeEvent): if not self.checkWorkerName(paramChangeEvent.param.worker, paramChangeEvent.newValue): raise Param.VetoParamChange(paramChangeEvent)