print(train_size) train_set = np.random.randn(train_size,dim) for loop in range(7): if loop != 0: #append new data new_pts = np.random.randn(train_size,dim) train_set = np.vstack((train_set,new_pts)) print('training data size',train_set.shape) #train active subspace f_data = toy_f(train_set) print('data size', f_data.shape) #don't normalize sub_sp.compute(X=train_set,f=f_data,sstype='QPHD') #usual threshold adim = find_active(sub_sp.eigenvals,sub_sp.eigenvecs) print('Subspace Distance',subspace_dist(true_as,sub_sp.eigenvecs[:,0:adim])) test = Stars_sim(toy_f, init_pt, L1 = 2.0, var = 1E-4, verbose = False, maxit = train_size*3) test.STARS_only = True test.get_mu_star() test.get_h() # do 100 steps while test.iter < test.maxit: test.step() if test.iter > (dim+2)*(dim+1)//4: #compute active subspace train_x = np.hstack((test.xhist[:,0:test.iter+1],test.yhist[:,0:test.iter])) train_f = np.hstack((test.fhist[0:test.iter+1],test.ghist[0:test.iter])) train_x = train_x.T sub_sp.compute(X=train_x,f=train_f,sstype='QPHD')
init_pt, L1=our_L1, var=our_var, verbose=False, maxit=maxit) #test.STARS_only = True test.update_L1 = True test.get_mu_star() test.get_h() # adapt every 10 timesteps using quadratic(after inital burn) test.train_method = 'GQ' test.adapt = 20 # Sets number of sub-cylcing steps # do 100 steps while test.iter < test.maxit: test.step() if test.iter % 20 == 0 and test.active is not None: print('Step', test.iter, 'Active dimension', test.active.shape[1]) print('Subspace Distance', subspace_dist(true_as, test.active)) f2_avr += test.fhist print('ASTARS trial', trial, ' minval', test.fhist[-1]) f_avr /= ntrials f2_avr /= ntrials plt.semilogy(f_avr, label='Stars') plt.semilogy(f2_avr, label='Astars') plt.legend() plt.show()
test2.get_mu_star() test2.get_h() test2.train_method = 'GQ' test2.adapt = 2*f.dim test2.regul = test2.var test2.pad_train = 2.0 test2.explore_weight = 2.0 #test2.regul = None dist = None L1_hist = None while test.iter < test.maxit: test.step() test2.step() if test2.active is not None: temp = np.array(subspace_dist(test2.active,f.active)) if dist is None: dist = np.copy(temp) L1_hist = np.copy(np.array(test2.L1)) else: dist = np.append(dist,temp) L1_hist = np.append(L1_hist,test2.L1) #update average of f f_avr += test.fhist f2_avr += test2.fhist trial_final += [email protected]@test2.x #final answer #project test2 solution
# adapt every f.adapt timesteps using quadratic(after inital burn) test.train_method = 'GQ' test.adapt = f.adapt # Sets retraining steps #test.subcycle = True # turn on subcycling test.threshadapt = True #test.debug = True test.regul = f.regul test.threshold = f.threshold # do 100 steps while test.iter < test.maxit: test.step() if test.active is not None and test.iter // test.adapt: print('distance', subspace_dist(test.active, f.active)) f2_avr += test.fhist if maxit > test.tr_stop: FAASTARS_adim_sto = np.zeros((maxit - test.tr_stop - 1, 1)) FAASTARS_sub_dist_sto = np.zeros((maxit - test.tr_stop - 1, 1)) # data dump FAASTARS_f_sto = np.hstack( (FAASTARS_f_sto, np.transpose([test.fhist]))) FAASTARS_x_sto = np.vstack((FAASTARS_x_sto, np.transpose(test.xhist))) if maxit > test.tr_stop: FAASTARS_adim_sto = np.hstack( (FAASTARS_adim_sto, np.transpose([test.adim_hist])))