def main(): if clean_dir: clean_outdir(outdir) x0 = generate_vf_landmarks(magnification, ecc0, ecc1, n_prototypes, vf='full', filename=full_filename('vf', outdir)) b0 = generate_V2_boundary_retinotopy_for_DM(boundary_len, map_h, filename=full_filename( 'boundary', outdir)) y = initialize_map(map_h, map_w, x0, filename=full_filename('init', outdir), random_seed=random_seed) optimize(x0, b0, b1, b2, map_h, map_w, y, k0=k0, kr=kr, eta0=eta0, outdir=outdir, save_interval=save_interval, n=n_iterations)
def save_map(sess, y, b1, b2, i, outdir="", save_interval=0, quiet=False, suffix=''): if (outdir != "") and save_interval > 0: if i % save_interval == 0: filename = "y-{b1:4.3f}-{b2:4.3f}-{i}".format(b1=b1, b2=b2, i=str(i).zfill(5)) zz = sess.run(y) if (not quiet): print("saving {filename}".format(filename=filename)) np.savetxt(full_filename(filename, outdir, ext=".data", suffix=suffix), np.array(zz), fmt="%f", delimiter=",")
def main(rseed, outputdir): if clean_dir: clean_outdir(outputdir) x0 = generate_vf_landmarks(magnification, ecc0, ecc1, n_prototypes, vf='full', filename=full_filename('vf', outputdir)) b0 = generate_V2_boundary_retinotopy(boundary_len, map_h, branch='vd', filename=full_filename( 'boundary', outputdir), tilt=10.0) y = initialize_map(map_h, map_w, x0, filename=full_filename('init', outdir), random_seed=rseed) # loop through b1 and b2 b1s = [0.03 * 1.6**i for i in range(0, 8)] b2s = [0.03 * 1.6**i for i in range(0, 8)] print("b1:", b1s) print("b2:", b2s) for b1 in b1s: for b2 in b2s: print("b1 = %10.4f \t b2 = %10.4f" % (b1, b2)) optimize( x0, b0, b1, b2, map_h, map_w, y, k0=k0, kr=kr, eta0=eta0, outdir=outputdir, save_interval=0, # disable saving intermediate maps n=n_iterations, report_iterations=False, log_iterations=False)
def train(opt, total_cost, partial_costs, tf_placeholders, y, b1, b2, outdir="", save_interval=0, n=1000, k0=30.0, kr=0.005, quiet_save=False, report_iterations=True, log_iterations=True, logfile='log', suffix='', yx_gauss=None): """ b1: weights for the smoothness term b2: weights for the congruency term n: number of iterations k0: initial annealing parameter kr: reduction of the annealing parameter at each iteration outdir: where to save the results. save_intervals: save map every several iterations. if set to 0, saving is disabled """ yx_cost = partial_costs[0] reg1 = partial_costs[1] reg2 = partial_costs[2] beta1 = tf_placeholders[0] beta2 = tf_placeholders[1] kappa = tf_placeholders[2] sess = tf.Session() sess.run(tf.global_variables_initializer()) # save initial map # always save the initial map (by setting save_interval to 1) save_map(sess, y, b1, b2, 0, outdir, save_interval=1, quiet=quiet_save, suffix=suffix) k = k0 for i in range(1, n + 1): # itertaively optimize the total cost function sess.run(opt, {kappa: k, beta1: b1, beta2: b2}) report_and_log(partial_costs, tf_placeholders, i, k, b1, b2, sess, reportP=report_iterations, logP=log_iterations, logfile=full_filename(logfile, outdir, suffix=suffix)) if i > 0: save_map(sess, y, b1, b2, i, outdir, save_interval, quiet=quiet_save, suffix=suffix) k = k - k * kr # save the final result # set save_interval to 1, so that the final result is saved even if intermediate saving is disabled by save_interval=0 save_map(sess, y, b1, b2, i, outdir, save_interval=1, quiet=quiet_save, suffix=suffix) report_and_log(partial_costs, tf_placeholders, i, k, b1, b2, sess, reportP=False, logP=True, logfile=full_filename(logfile, outdir, suffix=suffix))