def generate_new_data(): global trn_inputs, trn_shifts, trn_targets #print "Generating new data..." trn_inputs, trn_shifts, trn_targets = \ generate_data(cfg.x_len, cfg.s_len, cfg.n_batch) if use_id_data: trn_targets = trn_inputs.copy()
loss = T.mean((fsn.output(x,s) - t)**2) if profile: f_loss = function(inputs=[ps.flat,x,s,t], outputs=loss, mode=profmode, name='f_loss') f_dloss = function(inputs=[ps.flat,x,s,t], outputs=T.grad(loss, ps.flat), mode=profmode, name='f_dloss') else: f_loss = function(inputs=[ps.flat,x,s,t], outputs=loss) f_dloss = function(inputs=[ps.flat,x,s,t], outputs=T.grad(loss, ps.flat)) f_trn_loss = lambda p: f_loss(p, trn_inputs, trn_shifts, trn_targets) f_trn_dloss = lambda p: f_dloss(p, trn_inputs, trn_shifts, trn_targets) # generate data print "Generating data..." trn_inputs, trn_shifts, trn_targets = generate_data(cfg.x_len, cfg.s_len, cfg.n_samples) val_inputs, val_shifts, val_targets = generate_data(cfg.x_len, cfg.s_len, cfg.n_samples) tst_inputs, tst_shifts, tst_targets = generate_data(cfg.x_len, cfg.s_len, cfg.n_samples) print "Done." # optimizer if cfg.optimizer == 'lbfgs': opt = climin.Lbfgs(ps.data, f_trn_loss, f_trn_dloss) elif cfg.optimizer == 'rprop': opt = climin.Rprop(ps.data, f_trn_dloss) elif cfg.optimizer == 'rmsprop': opt = climin.RmsProp(ps.data, f_trn_dloss, steprate=cfg.steprate[0], momentum=cfg.momentum) elif cfg.optimizer == 'gradientdescent': opt = climin.GradientDescent(ps.data, f_trn_dloss,
def generate_data(n_samples): if use_base_data: inputs, shifts, targets = generate_base_data(n_samples) else: inputs, shifts, targets = generate_data(cfg.x_len, cfg.s_len, n_samples) return inputs, shifts, targets
def generate_base_data(n_samples): inputs, shifts, targets = generate_data(base_x_len, base_s_len, n_samples) inputs = gp.dot(doubling_matrix(base_x_len).T, inputs) targets = gp.dot(doubling_matrix(base_x_len).T, targets) shifts = gp.dot(shift_doubling_matrix(base_s_len).T, shifts) return inputs, shifts, targets
def generate_new_training_data(): global trn_inputs, trn_shifts, trn_targets print "Generating new data..." trn_inputs, trn_shifts, trn_targets = generate_data(cfg.n_batch)