def return_grad(test_params, input_x, truth_y): tmp = get_params(model_ft.models_stack[-1]) set_params(model_ft.models_stack[-1], test_params) result = numpy.concatenate( [numpy.array(i).flatten() for i in fun_grad(input_x, truth_y)]) set_params(model_ft.models_stack[-1], tmp) return result
def return_grad(test_params, input_x, truth_y): tmp = get_params(model_ft.models_stack[-1]) set_params(model_ft.models_stack[-1], test_params) result = numpy.concatenate([numpy.array(i).flatten() for i in fun_grad(input_x, truth_y)]) set_params(model_ft.models_stack[-1], tmp) return result
def return_cost(test_params, input_x, truth_y): tmp = get_params(model_ft.models_stack[-1]) set_params(model_ft.models_stack[-1], test_params) result = fun_cost(input_x, truth_y) set_params(model_ft.models_stack[-1], tmp) return result
fun_grad = theano.function( [model_ft.varin, model_ft.models_stack[-1].vartruth], T.grad(model_ft.models_stack[-1].cost() + model_ft.models_stack[-1].weightdecay(weightdecay), model_ft.models_stack[-1].params) ) def return_grad(test_params, input_x, truth_y): tmp = get_params(model_ft.models_stack[-1]) set_params(model_ft.models_stack[-1], test_params) result = numpy.concatenate([numpy.array(i).flatten() for i in fun_grad(input_x, truth_y)]) set_params(model_ft.models_stack[-1], tmp) return result p, g, numlinesearches = minimize( get_params(model_ft.models_stack[-1]), return_cost, return_grad, (train_x.get_value(), train_y.get_value()), logreg_epc, verbose=False ) set_params(model_ft.models_stack[-1], p) save_params(model_ft, 'ZLIN_4000_1000_4000_1000_4000_1000_4000_10_normhid_nolinb_cae1_dropout.npy') print "***error rate: train: %f, test: %f" % ( train_set_error_rate(), test_set_error_rate() ) ############# # FINE-TUNE # ############# """ print "\n\n... fine-tuning the whole network" truth = T.lmatrix('truth') trainer = GraddescentMinibatch( varin=model_ft.varin, data=train_x, truth=model_ft.models_stack[-1].vartruth, truth_data=train_y,
def return_grad(test_params, input_x, truth_y): tmp = get_params(model_ft.models_stack[-1]) set_params(model_ft.models_stack[-1], test_params) result = numpy.concatenate( [numpy.array(i).flatten() for i in fun_grad(input_x, truth_y)]) set_params(model_ft.models_stack[-1], tmp) return result p, g, numlinesearches = minimize(get_params(model_ft.models_stack[-1]), return_cost, return_grad, (train_x.get_value(), train_y.get_value()), logreg_epc, verbose=False) set_params(model_ft.models_stack[-1], p) save_params( model_ft, 'ZLIN_4000_1000_4000_1000_4000_1000_4000_10_normhid_nolinb_cae1_dropout.npy' ) print "***error rate: train: %f, test: %f" % (train_set_error_rate(), test_set_error_rate()) ############# # FINE-TUNE # ############# """ print "\n\n... fine-tuning the whole network" truth = T.lmatrix('truth') trainer = GraddescentMinibatch( varin=model_ft.varin, data=train_x,
from copy import deepcopy from master_file import regret_dgrind, regret_exp3 from params import set_params import math num_repetitions = 30 dgrind = [] exp3 = [] min_num_rounds = 0 max_num_rounds = 1000 step = 5 rounds = [T for T in range(min_num_rounds, max_num_rounds)] #size: 5000 bytes T = max_num_rounds (num_agents, dim, x_real, calA, agent_types, true_labels, delta, noise, p) = set_params(T) cp_xreal = deepcopy(x_real) for delta in [0.05, 0.10, 0.15, 0.3, 0.5]: print("Current delta = %.5f" % delta) agents_dgrind = [Agent(t, agent_types, cp_xreal, delta) for t in range(T)] oracle_dgrind = Oracle(deepcopy(agents_dgrind), calA, T) resp_lst_dgrind = oracle_dgrind.compute_responses(dim) print("Independence Number") # computes approximate independence number in order to tune \eta for GRINDER correctly a_G = oracle_dgrind.compute_independence_number(dim, resp_lst_dgrind) print a_G principal_dgrind = [ Principal(T, calA, num_repetitions, p, a_G) for _ in range(0, num_repetitions)
from copy import deepcopy from master_file import regret_grind, regret_exp3 from params import set_params import math num_repetitions = 30 dgrind = [] exp3 = [] min_num_rounds = 0 max_num_rounds = 1000 step = 5 rounds = [T for T in range(min_num_rounds, max_num_rounds)] T = max_num_rounds (num_agents, dim, x_real, calA_exp3, calA_grind, agent_types, true_labels, delta, noise, prob) = set_params(T, 0.2) cp_xreal = deepcopy(x_real) for delta in [0.05, 0.1, 0.15, 0.3, 0.5]: print("Current delta = %.5f" % delta) agents_grind = [Agent(t, agent_types, cp_xreal, delta) for t in range(T)] oracle_grind = Oracle(deepcopy(agents_grind), T) principal_grind = [ Principal_Grind(T, calA_grind, num_repetitions) for _ in range(0, num_repetitions) ] principal_exp3 = [ Principal_Exp3(T, calA_exp3, num_repetitions, 0) for _ in range(0, num_repetitions) ]