def run_experiments_hepmass(): n_hiddens = 512 n_layers = 5 n_comps = 10 act_fun = 'relu' mode = 'sequential' ex.load_data('hepmass') ex.train_made([n_hiddens] * 1, act_fun, mode) ex.train_made([n_hiddens] * 2, act_fun, mode) ex.train_mog_made([n_hiddens] * 1, act_fun, n_comps, mode) ex.train_mog_made([n_hiddens] * 2, act_fun, n_comps, mode) ex.train_realnvp([n_hiddens] * 1, 'tanh', 'relu', n_layers * 1) ex.train_realnvp([n_hiddens] * 2, 'tanh', 'relu', n_layers * 1) ex.train_realnvp([n_hiddens] * 1, 'tanh', 'relu', n_layers * 2) ex.train_realnvp([n_hiddens] * 2, 'tanh', 'relu', n_layers * 2) ex.train_maf([n_hiddens] * 1, act_fun, n_layers * 1, mode) ex.train_maf([n_hiddens] * 2, act_fun, n_layers * 1, mode) ex.train_maf([n_hiddens] * 1, act_fun, n_layers * 2, mode) ex.train_maf([n_hiddens] * 2, act_fun, n_layers * 2, mode) ex.train_maf_on_made([n_hiddens] * 1, act_fun, n_layers, n_comps, mode) ex.train_maf_on_made([n_hiddens] * 2, act_fun, n_layers, n_comps, mode)
def run_experiments_mnist(): n_hiddens = 1024 n_layers = 5 n_comps = 10 act_fun = 'relu' mode = 'sequential' ex.load_data('mnist') # ex.train_made([n_hiddens]*2, act_fun, mode) # ex.train_made_cond([n_hiddens]*2, act_fun, mode) # ex.train_mog_made([n_hiddens]*2, act_fun, n_comps, mode) # ex.train_mog_made_cond([n_hiddens]*2, act_fun, n_comps, mode) for i in [1]: #, 2 # ex.train_realnvp([n_hiddens]*2, 'tanh', 'relu', n_layers*i) # ex.train_realnvp_cond([n_hiddens]*2, 'tanh', 'relu', n_layers*i) # ex.train_maf([n_hiddens]*2, act_fun, n_layers*i, mode) ex.train_maf_cond([n_hiddens] * 2, act_fun, n_layers * i, mode) ex.train_maf_on_made([n_hiddens] * 2, act_fun, n_layers, n_comps, mode) ex.train_maf_on_made_cond([n_hiddens] * 2, act_fun, n_layers, n_comps, mode)
def run_experiments_bsds300(): n_layers = 5 n_comps = 10 act_fun = 'relu' mode = 'sequential' ex.load_data('bsds300') for n_hiddens in [512, 1024]: ex.train_made([n_hiddens] * 1, act_fun, mode) ex.train_made([n_hiddens] * 2, act_fun, mode) ex.train_mog_made([n_hiddens] * 1, act_fun, n_comps, mode) ex.train_mog_made([n_hiddens] * 2, act_fun, n_comps, mode) ex.train_realnvp([n_hiddens] * 1, 'tanh', 'relu', n_layers * 1) ex.train_realnvp([n_hiddens] * 2, 'tanh', 'relu', n_layers * 1) ex.train_realnvp([n_hiddens] * 1, 'tanh', 'relu', n_layers * 2) ex.train_realnvp([n_hiddens] * 2, 'tanh', 'relu', n_layers * 2) ex.train_maf([n_hiddens] * 1, act_fun, n_layers * 1, mode) ex.train_maf([n_hiddens] * 2, act_fun, n_layers * 1, mode) ex.train_maf([n_hiddens] * 1, act_fun, n_layers * 2, mode) ex.train_maf([n_hiddens] * 2, act_fun, n_layers * 2, mode) ex.train_maf_on_made([n_hiddens] * 1, act_fun, n_layers, n_comps, mode) ex.train_maf_on_made([n_hiddens] * 2, act_fun, n_layers, n_comps, mode)
def run_experiments_custom(data_trn, data_val, labels_trn, labels_val): n_hiddens = int(data_trn.shape[1] * 1.2) n_layers = 5 n_comps = 10 act_fun = 'relu' mode = 'sequential' ex.load_data('custom', data_trn, data_val, labels_trn, labels_val) model = ex.train_maf_cond_custom([n_hiddens] * 2, act_fun, n_layers, mode) # ex.train_maf_on_made_cond([n_hiddens]*2, act_fun, n_layers, n_comps, mode) return model
def run_experiments_cifar10(): n_layers = 5 n_comps = 10 act_fun = 'relu' mode = 'random' ex.load_data('cifar10') for n_hiddens in [1024, 2048]: ex.train_made([n_hiddens] * 1, act_fun, mode) ex.train_made([n_hiddens] * 2, act_fun, mode) ex.train_made_cond([n_hiddens] * 1, act_fun, mode) ex.train_made_cond([n_hiddens] * 2, act_fun, mode) ex.train_mog_made([n_hiddens] * 1, act_fun, n_comps, mode) ex.train_mog_made([n_hiddens] * 2, act_fun, n_comps, mode) ex.train_mog_made_cond([n_hiddens] * 1, act_fun, n_comps, mode) ex.train_mog_made_cond([n_hiddens] * 2, act_fun, n_comps, mode) for i in [1, 2]: ex.train_realnvp([n_hiddens] * 1, 'tanh', 'relu', n_layers * i) ex.train_realnvp([n_hiddens] * 2, 'tanh', 'relu', n_layers * i) ex.train_realnvp_cond([n_hiddens] * 1, 'tanh', 'relu', n_layers * i) ex.train_realnvp_cond([n_hiddens] * 2, 'tanh', 'relu', n_layers * i) ex.train_maf([n_hiddens] * 1, act_fun, n_layers * i, mode) ex.train_maf([n_hiddens] * 2, act_fun, n_layers * i, mode) ex.train_maf_cond([n_hiddens] * 1, act_fun, n_layers * i, mode) ex.train_maf_cond([n_hiddens] * 2, act_fun, n_layers * i, mode) ex.train_maf_on_made([n_hiddens] * 1, act_fun, n_layers, n_comps, mode) ex.train_maf_on_made([n_hiddens] * 2, act_fun, n_layers, n_comps, mode) ex.train_maf_on_made_cond([n_hiddens] * 1, act_fun, n_layers, n_comps, mode) ex.train_maf_on_made_cond([n_hiddens] * 2, act_fun, n_layers, n_comps, mode)
def collect_results(data, n_hiddens, n_layers, n_comps, n_layers_comps, act_funs, modes, has_cond): print('collecting for {0}...'.format(data)) ex.load_data(data) # create file to write to filename = ('{0}_{1}_bpp.txt' if bits_per_pixel else '{0}_{1}.txt').format(data, split) util.make_folder(root_results) f = open(root_results + filename, 'w') f.write('Results for {0}\n'.format(data)) f.write('\n') for act, mode in itertools.product(act_funs, modes): f.write('actf: {0}\n'.format(act)) f.write('mode: {0}\n'.format(mode)) f.write('\n') # gaussian f.write('Gaussian\n') res, err = ex.fit_and_evaluate_gaussian(split, cond=False, use_image_space=bits_per_pixel) if bits_per_pixel: res, err = calc_bits_per_pixel(res, err) f.write(' {0:.2f} +/- {1:.2f}\n'.format(res, n_err * err)) if has_cond: f.write('conditional\n') res, err = ex.fit_and_evaluate_gaussian(split, cond=True, use_image_space=bits_per_pixel) if bits_per_pixel: res, err = calc_bits_per_pixel(res, err) f.write(' {0:.2f} +/- {1:.2f}\n'.format(res, n_err * err)) f.write('\n') # made f.write('MADE 1 comp\n') for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('made', mode, [nh]*1, act))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('made', mode, [nh]*2, act))) if has_cond: f.write('conditional\n') for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('made_cond', mode, [nh]*1, act))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('made_cond', mode, [nh]*2, act))) f.write('\n') # mog made for nc in n_comps: f.write('MADE {0} comp\n'.format(nc)) for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('made', mode, [nh]*1, act, nc))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('made', mode, [nh]*2, act, nc))) if has_cond: f.write('conditional\n') for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('made_cond', mode, [nh]*1, act, nc))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('made_cond', mode, [nh]*2, act, nc))) f.write('\n') # real nvp for nl in n_layers: f.write('RealNVP {0} layers\n'.format(nl)) for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('realnvp', None, [nh]*1, 'tanhrelu', nl, True))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('realnvp', None, [nh]*2, 'tanhrelu', nl, True))) if has_cond: f.write('conditional\n') for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('realnvp_cond', None, [nh]*1, 'tanhrelu', nl, True))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('realnvp_cond', None, [nh]*2, 'tanhrelu', nl, True))) f.write('\n') # maf for nl in n_layers: f.write('MAF {0} layers\n'.format(nl)) for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('maf', mode, [nh]*1, act, nl, True))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('maf', mode, [nh]*2, act, nl, True))) if has_cond: f.write('conditional\n') for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('maf_cond', mode, [nh]*1, act, nl, True))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('maf_cond', mode, [nh]*2, act, nl, True))) f.write('\n') # maf on made for nl, nc in n_layers_comps: f.write('MAF {0} layers on MADE {1} comp\n'.format(nl, nc)) for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('maf_on_made', mode, [nh]*1, act, [nl, nc], True))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('maf_on_made', mode, [nh]*2, act, [nl, nc], True))) if has_cond: f.write('conditional\n') for nh in n_hiddens: f.write(' [1 x {0}]: {1}\n'.format(nh, result('maf_on_made_cond', mode, [nh]*1, act, [nl, nc], True))) f.write(' [2 x {0}]: {1}\n'.format(nh, result('maf_on_made_cond', mode, [nh]*2, act, [nl, nc], True))) f.write('\n') # close file f.close()