def run_learning_and_mapping(args, fixed_params, task_param, seeds, slurm_args=None): logging.info('Running final tests with...') import copy task_params = [copy.copy(task_param) for s in seeds] param_ids = range(len(task_params)) for param, seed, param_id in zip(task_params, seeds, param_ids): param.param_id = param_id param.seed = seed ensure_dir_exists("run_parameters") common_params = SimpleNamespace( **fixed_params.__dict__, priv_cancertype_pairs=[], pub_cancertypes=sum(cancer_type_pairs, []), task_type='learn_and_map', ) args.wait = True batch2.run_tasks(args, common_params, task_params, slurm_args=slurm_args, params_file=("run_parameters/batch-%s.pkl" % (fixed_params.test_name)))
def run_optimization_batch(args, fixed_params, task_params, seeds, slurm_args=None): ensure_dir_exists("run_parameters") param_ids = range(len(task_params)) for param, seed, param_id in zip(task_params, seeds, param_ids): param.param_id = param_id param.seed = seed assert len(task_params) == gpyopt_batch_size nonpriv_cancertype_pairs = [ ctp for ctp in cancer_type_pairs if ctp != fixed_params.priv_cancertype_pair ] assert len(nonpriv_cancertype_pairs) == len(cancer_type_pairs) - 1 res = np.zeros((len(task_params), fixed_params.param_opt_folds)) for fold in range(fixed_params.param_opt_folds): val_cancertype_pairs = [ ctp for (i, ctp) in enumerate(nonpriv_cancertype_pairs) if i % fixed_params.param_opt_folds == fold ] learn_cancertype_pairs = [ ctp for (i, ctp) in enumerate(nonpriv_cancertype_pairs) if i % fixed_params.param_opt_folds != fold ] assert (len(val_cancertype_pairs) + len(learn_cancertype_pairs) == len(nonpriv_cancertype_pairs)) common_params = SimpleNamespace( **fixed_params.__dict__, priv_cancertype_pairs=val_cancertype_pairs, pub_cancertypes=sum(learn_cancertype_pairs, []), task_type='paramopt', ) args.wait = True batch2.run_tasks(args, common_params, task_params, slurm_args=slurm_args, params_file=("run_parameters/batch-%s.pkl" % (fixed_params.test_name))) # get results for param_id in param_ids: full_model_id = "%s-%s" % (fixed_params.test_name, param_id) filename = "param_opt/opt_result-%s.txt" % (full_model_id) try: res[param_id, fold] = np.loadtxt(filename) import os os.remove(filename) except: res[param_id, fold] = gpyopt_fail_res + np.random.randn( ) * gpyopt_fail_res_std logging.info('Warning, could not load "%s"' % filename) return np.mean(res, axis=1, keepdims=True)
def run_test(args, fixed_params, task_param, seeds, slurm_args=None): logging.info('Running final tests with...') import copy task_params = [copy.copy(task_param) for s in seeds] param_ids = range(len(task_params)) for param, seed, param_id in zip(task_params, seeds, param_ids): param.param_id = param_id param.seed = seed ensure_dir_exists("run_parameters") nonpriv_cancertype_pairs = [ ctp for ctp in cancer_type_pairs if ctp != fixed_params.priv_cancertype_pair ] assert len(nonpriv_cancertype_pairs) == len(cancer_type_pairs) - 1 common_params = SimpleNamespace( **fixed_params.__dict__, priv_cancertype_pairs=[fixed_params.priv_cancertype_pair], pub_cancertypes=sum(nonpriv_cancertype_pairs, []), task_type='test', ) args.wait = True batch2.run_tasks(args, common_params, task_params, slurm_args=slurm_args, params_file=("run_parameters/batch-%s.pkl" % (fixed_params.test_name))) # res = np.zeros((len(task_params), 1)) for param_id in param_ids: full_model_id = "%s-%s" % (fixed_params.test_name, param_id) filename = "param_opt/opt_result-%s.txt" % (full_model_id) try: res[param_id] = np.loadtxt(filename) import os os.remove(filename) except: res[param_id] = np.nan #gpyopt_fail_res logging.info('Warning, could not load "%s"' % filename) filename = "res/test_results-%s.txt" % (fixed_params.test_name) logging.info("Writing final results to '%s'" % filename) np.savetxt(filename, res)
def run_optimization_batch(args, fixed_params, task_params, seeds, slurm_args=None): ensure_dir_exists("run_parameters") param_ids = range(len(task_params)) for param, seed, param_id in zip(task_params, seeds, param_ids): param.param_id = param_id #param.priv_cancertypes = val_cancertypes #param.skip_cancertypes = priv_cancertypes param.seed = seed #np.save("run_parameters/params-%s.npy" % (test_name), params) assert len(task_params) == gpyopt_batch_size common_params = SimpleNamespace( **fixed_params.__dict__, pred_cancertypes=fixed_params.val_cancertypes, skip_cancertypes=fixed_params.priv_cancertypes, task_type='paramopt', ) args.wait = True batch2.run_tasks(args, common_params, task_params, slurm_args=slurm_args, params_file=("run_parameters/batch-%s.pkl" % (fixed_params.test_name))) # get results #return np.random.randn(gpyopt_batch_size, 1) res = np.zeros((len(task_params), 1)) for param_id in param_ids: full_model_id = "%s-%s" % (fixed_params.test_name, param_id) filename = "param_opt/opt_result-%s.txt" % (full_model_id) try: res[param_id] = np.loadtxt(filename) import os os.remove(filename) except: res[param_id] = gpyopt_fail_res + np.random.randn( ) * gpyopt_fail_res_std logging.info('Warning, could not load "%s"' % filename) return res
def run_test(args, fixed_params, task_param, seeds, slurm_args=None): logging.info('Running tests...') task_params = [[ SimpleNamespace( pred_cancertypes=priv_cancertypes, seed=seed, ) for seed in seeds ] for priv_cancertypes in cancer_type_pairs] task_params = sum(task_params, []) param_ids = range(len(task_params)) for param, param_id in zip(task_params, param_ids): param.param_id = param_id ensure_dir_exists("run_parameters") #np.save("run_parameters/params-%s.npy" % (test_name), params) common_params = SimpleNamespace(**fixed_params.__dict__, ) args.wait = True batch2.run_tasks(args, common_params, task_params, slurm_args=slurm_args, params_file=("run_parameters/batch-%s.pkl" % (fixed_params.test_name))) # res = np.zeros((len(task_params), 1)) for param_id in param_ids: full_model_id = "%s-%s" % (fixed_params.test_name, param_id) filename = "param_opt/opt_result-%s.txt" % (full_model_id) try: res[param_id] = np.loadtxt(filename) import os os.remove(filename) except: res[param_id] = np.nan logging.info('Warning, could not load "%s"' % filename) res = np.reshape(res, (len(cancer_type_pairs), len(seeds))) filename = "res/test_results-%s.txt" % (fixed_params.test_name) logging.info("Writing final results to '%s'" % filename) np.savetxt(filename, res)