tf = np.arange(1200 * (1 + n_frames * n0), (nmax + 1) * 1200 * n_frames + 1, step=1200) print(f"Loading data took f{time.time() - loadingtimestart:.2f}s. ") # ---------- # NEWMA RP OPU startingtime = time.time() # Pararameters for the NEWMA algorithm B = 250 # window size d = n_feat # Forget factors chosen with heuristic in the paper big_Lambda, small_lambda = algos.select_optimal_parameters(B) thres_ff = small_lambda # Number of random features is set automatically with this criterion m = int((1 / 4) / (small_lambda + big_Lambda)**2) m_OPU = 10 * m print(f'{m_OPU} random features.') if pyramid: # Pyramid sketch nc = 60000 # Opening the OPU opu_mapping = OPUMap(n_components=nc) # First encoding encoder = BinaryThresholdEncoder(threshold_enc=10) minX, maxX = np.min(traj), np.max(traj)
# parameters of gmm k = 10 std_mean = 0.11 # the bigger, the more change in means wishart = 5 # the bigger, the less change in diagonal variances X, ground_truth = gd.stream_GMM(d=d, n=n, nb_change=nb_change, std_mean=std_mean, concentration_wishart=wishart, k=k) # common config choice_sigma = 'median' numel = 100 data_sigma_estimate = X[:numel] # data for median trick to estimate sigma B = args.B # window size # Newma config big_Lambda, small_lambda = algos.select_optimal_parameters(B) # forget factors chosen with heuristic in the paper print('Chose Lambda = {:.4f} and lambda = {:.4f}'.format(big_Lambda, small_lambda)) thres_ff = small_lambda # number of random features is set automatically with this criterion m = int((1 / 4) / (small_lambda + big_Lambda) ** 2) print('Number of RFs: {}'.format(m)) W, sigmasq = feat.generate_frequencies(m, d, data=data_sigma_estimate, choice_sigma=choice_sigma) print('Start algo ', algo, ' with fixed threshold') def feat_func(x): return feat.fourier_feat(x, W) detector95 = algos.NEWMA(X[0], forget_factor=big_Lambda, forget_factor2=small_lambda, feat_func=feat_func, adapt_forget_factor=thres_ff) detector95.apply_to_data(X)
k=k) # parameters for algorithms m = 2000 save_res = True window_size_list = np.linspace(100, 500, num_tests) N = 3 running_times = [] for i, window_size in enumerate(window_size_list): window_size = int(window_size) print('Performing test ', i + 1, ' over ', num_tests, ' window size = ', window_size) ff, ff2 = algos.select_optimal_parameters(window_size) thresh_ff = ff2 if algo == 'ScanB': print('Scan-B') ocpobj = algos.ScanB( X[0], kernel_func=lambda x, y: feat.gauss_kernel(x, y, np.sqrt(sigmasq)), window_size=window_size, nbr_windows=N, adapt_forget_factor=thresh_ff, store_values=False) t = time.time() ocpobj.apply_to_data(X) # actual computations time_method = time.time() - t print('time:', time_method)