def main(): """Parse args and run simulated annealing""" opts = settings.parse_args() print(opts) # set up seeds if opts.seed != None: np.random.seed(opts.seed) random.seed(opts.seed) tf.random.set_seed(opts.seed) generator, discriminator, iterator, parameters = process_opts(opts) # grid search if opts.grid: print("Grid search not supported right now") sys.exit() #posterior, loss_lst = grid_search(discriminator, samples, simulator, \ # iterator, parameters, opts.seed) # simulated annealing else: posterior, loss_lst = simulated_annealing(generator, discriminator,\ iterator, parameters, opts.seed, toy=opts.toy) print(posterior) print(loss_lst)
def main(): arg_parser = gen_arg_parser() args = arg_parser.parse_args() conf_path = args.conf_path action = args.action project_name = args.project_name conf_path = find_conf_path(conf_path) #print(conf_path) conf = None if conf_path is not None: conf = parse_conf(conf_path) if conf is None and action in ['setup', 'snapshot', None]: return "didn't find conf. can't run command..exiting" if action == 'init': #dispatch_init(conf, conf_path, project_name) dispatch_init(conf, default_conf_path, project_name) elif action == 'setup': dispatch_snapshot_setup(conf, conf_path, project_name, is_setup=True) elif action in 'snapshot': dispatch_snapshot_setup(conf, conf_path, project_name) elif action == 'status': dispatch_status(conf, conf_path, project_name) return "done" to_track_lst = None if not file_exists(conf_path): err_str = "can't find %s. " % (conf_path, ) print("doesn't look like .vivie folder:", err_str) sys.exit(1) else: to_track_str = read_file(conf_path) to_track_lst = to_track_str.split('\n')[:-1] if not file_exists(data_dir): sh.mkdir(data_dir) cmd = parse_args() if cmd == 'help': print_help() elif cmd == 'setup': run_setup(to_track_lst) elif cmd == 'snapshot': take_snapshot(to_track_lst) elif cmd == 'status': pass
from torch.autograd import Variable from lib import network import lib.datasets as datasets import lib.utils.general_utils as utils import models as models from models.HDN_v2.utils import interpret_relationships import warnings from settings import parse_args, testImageLoader from PIL import Image from sort.sort import Sort, iou import interpret import os.path as osp import vis from keyframe_extracion import keyframe_checker args = parse_args() # Set the random seed random.seed(args.seed) torch.manual_seed(args.seed + 1) torch.cuda.manual_seed(args.seed + 2) colorlist = [(random.randint(0, 230), random.randint(0, 230), random.randint(0, 230)) for i in range(10000)] # Set options options = { 'data': { 'dataset_option': args.dataset_option, 'batch_size': args.batch_size, },
def main(): input_file = sys.argv[1] output_file = sys.argv[2] print("input file", input_file) print("output file", output_file) # need to remove these from the list of args or else argparser will not # handle unspecified positionals. sys.argv.remove(input_file) sys.argv.remove(output_file) opts = settings.parse_args() generator, iterator, parameters = process_opts(opts) values = ss_helpers.parse_output(input_file) print("VALUES", values) print("made it through params") # use the parameters we inferred! fsc=False generator.update_params(values) if opts.model == 'fsc': print("\nALERT you are running FSC sim!\n") print("FSC PARAMS!", FSC_PARAMS) generator.update_params(FSC_PARAMS) # make sure to check the order! fsc=True # real real_matrices = iterator.real_batch(NUM_TRIAL, neg1=False) real_matrices_region = iterator.real_batch(NUM_TRIAL, neg1=False, region_len=True) print("got through real data") # sim sim_matrices = generator.simulate_batch(NUM_TRIAL, neg1=False) generator.num_snps = None # this activates region_len mode sim_matrices_region = generator.simulate_batch(NUM_TRIAL, neg1=False) # one pop models if opts.model in ['exp', 'const']: real_sfs, real_dist, real_ld, real_stats = ss_helpers.stats_all(real_matrices, real_matrices_region, L) sim_sfs, sim_dist, sim_ld, sim_stats = ss_helpers.stats_all(sim_matrices, sim_matrices_region, L) plot_all_stats(real_stats, real_dist, real_sfs, real_ld, sim_stats, sim_dist, sim_sfs, sim_ld, output_file) # two pop models elif opts.model in ['im', 'ooa2', 'post_ooa', 'msmc', 'fsc']: half = real_matrices.shape[1]//2 # real split real_matrices1 = real_matrices[:,:half,:,:] real_matrices2 = real_matrices[:,half:,:,:] real_matrices_region1 = [] real_matrices_region2 = [] for item in real_matrices_region: real_matrices_region1.append(item[:half,:,:]) real_matrices_region2.append(item[half:,:,:]) # sim split sim_matrices1 = sim_matrices[:,:half,:,:] sim_matrices2 = sim_matrices[:,half:,:,:] sim_matrices_region1 = [] sim_matrices_region2 = [] for item in sim_matrices_region: sim_matrices_region1.append(item[:half,:,:]) sim_matrices_region2.append(item[half:,:,:]) # stats for pop 1 real_sfs1, real_dist1, real_ld1, real_stats1 = ss_helpers.stats_all(real_matrices1, real_matrices_region1, L) sim_sfs1, sim_dist1, sim_ld1, sim_stats1 = ss_helpers.stats_all(sim_matrices1, sim_matrices_region1, L) # stats for pop 2 real_sfs2, real_dist2, real_ld2, real_stats2 = ss_helpers.stats_all(real_matrices2, real_matrices_region2, L) sim_sfs2, sim_dist2, sim_ld2, sim_stats2 = ss_helpers.stats_all(sim_matrices2, sim_matrices_region2, L) # two pop stats real_fst = ss_helpers.fst_all(real_matrices) sim_fst = ss_helpers.fst_all(sim_matrices) plot_stats_twopop(real_stats1, real_dist1, real_sfs1, real_ld1, real_stats2, real_dist2, real_sfs2, real_ld2, real_fst, \ sim_stats1, sim_dist1, sim_sfs1, sim_ld1, sim_stats2, sim_dist2, sim_sfs2, sim_ld2, sim_fst, output_file, fsc=fsc) # OOA3 elif opts.model in ['ooa3']: third = real_matrices.shape[1]//3 # real split real_matrices1 = real_matrices[:,:third,:,:] real_matrices2 = real_matrices[:,third:third*2,:,:] real_matrices3 = real_matrices[:,third*2:,:,:] real_matrices_region1 = [] real_matrices_region2 = [] real_matrices_region3 = [] for item in real_matrices_region: real_matrices_region1.append(item[:third,:,:]) real_matrices_region2.append(item[third:third*2,:,:]) real_matrices_region3.append(item[third*2:,:,:]) # sim split sim_matrices1 = sim_matrices[:,:third,:,:] sim_matrices2 = sim_matrices[:,third:third*2,:,:] sim_matrices3 = sim_matrices[:,third*2:,:,:] sim_matrices_region1 = [] sim_matrices_region2 = [] sim_matrices_region3 = [] for item in sim_matrices_region: sim_matrices_region1.append(item[:third,:,:]) sim_matrices_region2.append(item[third:third*2,:,:]) sim_matrices_region3.append(item[third*2:,:,:]) # stats for pop 1 real_sfs1, real_dist1, real_ld1, real_stats1 = ss_helpers.stats_all(real_matrices1, real_matrices_region1, L) sim_sfs1, sim_dist1, sim_ld1, sim_stats1 = ss_helpers.stats_all(sim_matrices1, sim_matrices_region1, L) # stats for pop 2 real_sfs2, real_dist2, real_ld2, real_stats2 = ss_helpers.stats_all(real_matrices2, real_matrices_region2, L) sim_sfs2, sim_dist2, sim_ld2, sim_stats2 = ss_helpers.stats_all(sim_matrices2, sim_matrices_region2, L) # stats for pop 3 real_sfs3, real_dist3, real_ld3, real_stats3 = ss_helpers.stats_all(real_matrices3, real_matrices_region3, L) sim_sfs3, sim_dist3, sim_ld3, sim_stats3 = ss_helpers.stats_all(sim_matrices3, sim_matrices_region3, L) # two pop stats real_matrices12 = np.concatenate((np.array(real_matrices1), np.array(real_matrices2)), axis=1) real_matrices13 = np.concatenate((np.array(real_matrices1), np.array(real_matrices3)), axis=1) real_matrices23 = np.concatenate((np.array(real_matrices2), np.array(real_matrices3)), axis=1) sim_matrices12 = np.concatenate((np.array(sim_matrices1), np.array(sim_matrices2)), axis=1) sim_matrices13 = np.concatenate((np.array(sim_matrices1), np.array(sim_matrices3)), axis=1) sim_matrices23 = np.concatenate((np.array(sim_matrices2), np.array(sim_matrices3)), axis=1) print("fst shape", real_matrices12.shape) real_fst12 = ss_helpers.fst_all(real_matrices12) sim_fst12 = ss_helpers.fst_all(sim_matrices12) real_fst13 = ss_helpers.fst_all(real_matrices13) sim_fst13 = ss_helpers.fst_all(sim_matrices13) real_fst23 = ss_helpers.fst_all(real_matrices23) sim_fst23 = ss_helpers.fst_all(sim_matrices23) plot_stats_threepop( real_stats1, real_dist1, real_sfs1, real_ld1, real_stats2, real_dist2, real_sfs2, real_ld2, real_stats3, real_dist3, real_sfs3, real_ld3, sim_stats1, sim_dist1, sim_sfs1, sim_ld1, sim_stats2, sim_dist2, sim_sfs2, sim_ld2, sim_stats3, sim_dist3, sim_sfs3, sim_ld3, real_fst12, real_fst13, real_fst23, sim_fst12, sim_fst13, sim_fst23, output_file) else: print("unsupported", opts.model)