Beispiel #1
0
# build hyperparameter optimizer
farho = far.HyperOptimizer()
run = farho.minimize(val_loss,
                     oo_optim,
                     tr_loss,
                     io_optim,
                     init_dynamics_dict={
                         v: h
                         for v, h in zip(tf.model_variables(),
                                         far.utils.hyperparameters()[:4])
                     })

print(
    'Variables (or tensors) that will store the values of the hypergradients')
print(*far.hypergradients(), sep='\n')

# run hyperparameter optimization
T = 80  # performs 80 iteraitons of gradient descent on the training error (rise this values for better performances)
# get data suppliers (could also be stochastic for SGD)

acc = []

train = [train1, train2, train3, train4, train5]

count = [1, 1, 1, 1, 1]

for i in range(5):

    train_next = em.Dataset(train[i].data[0:batch], train[0].target[0:batch])
Beispiel #2
0
io_lip = 1. + lmbd

farho = far.HyperOptimizer(far.ReverseHg())
if run_gd:
    inner_obj = inner_obj([w, b])
    if right_step:
        gd = far.GradientDescentOptimizer(2 * kappa / io_lip)
    else:
        gd = far.GradientDescentOptimizer(1.)
else:
    gd = far.BackTrackingGradientDescentOptimizer(tf.constant(1.))

run = farho.minimize(outer_obj,
                     tf.train.GradientDescentOptimizer(0.01),
                     inner_obj,
                     gd,
                     var_list=[w, b],
                     hyper_list=[lmbd])

tf.global_variables_initializer().run()

rs = []
for t in range(10, 30):
    run(t)
    #     print(farho.hypergradient._history)
    #     print()
    rs.append(ss.run(far.hypergradients())[0])

print(rs)