def run_line_search_bs(self, g, x0, step_sizes, k_factors): """ runs the line search algorithm with brackets and sectioning """ print("--Line search with brackets and sectioning--") # check input - integer if isinstance(step_sizes, (int, float)): print("sorry list is requirde") return # check input - equal len if len(step_sizes) != len(k_factors): print("parameter length are not equal") return # print header print( "params:\t | s \t| k \t| f(a) \t\t| f(b) \t\t| f(b)-f(a) \t| a \t\t| b \t\t| b-a \t\t| f-calls \t| x_min \t|" ) # list for printing table_list = np.empty((0, 10)) # run over param list for s, k in zip(step_sizes, k_factors): # get the brackets a, b, f_calls_b, a_list, b_list = get_brackets( self.fx, g, x0, s, k) # sectioning xs, sec_list, f_calls_s = sectioning(a, b) # update list table_list = np.vstack( (table_list, (s, k, self.fx(a), self.fx(b), self.fx(b) - self.fx(a), str(a), str(b), str(b - a), f_calls_b, str(xs)))) # for printing of numpy arrays -> precision np.set_printoptions(precision=4) # print stuff print("results: | {:.2f}\t| {:d}\t".format(s, k) + "| {:.4f}\t| {:.4f}\t".format(float(self.fx(a)), float(self.fx(b))) + "| {:.4f}\t| {}\t| {} \t".format( float(self.fx(a) - self.fx(b)), a, b) + "| {}\t| {:d}\t\t| {}\t|".format(b - a, f_calls_b, xs)) header = [ 'step size s', 'mult. factor k', 'f(a)', 'f(b)', 'f(b)-f(a)', 'a', 'b', 'b-a', 'function calls', 'x min' ] # make table np_table(self.name, table_list, header=header)
def vary_param_dsr(input_filename, epsilon, filter_size): downsample_ratios = np.array([4, 8]) psnr = np.empty((0, 2), float) for downsample_ratio in downsample_ratios: # Prepare Images input_img, guidance_img, initial_img = prepare_imgs(input_filename, downsample_ratio) # approach (1): filtered_img_1 = guided_upsampling(resize(input_img, guidance_img.shape), guidance_img, filter_size, epsilon) # approach (2): filtered_img_2 = guided_upsampling(input_img, guidance_img, filter_size, epsilon) # Calculate PSNR psnr_filtered_1 = compute_psnr(filtered_img_1, initial_img) psnr_filtered_2 = compute_psnr(filtered_img_2, initial_img) psnr = np.vstack((psnr, np.array([psnr_filtered_1, psnr_filtered_2]))) psnr = np.transpose(psnr) # print table np_table('vary-dsr_eps-' + str(epsilon) + '_filter_size-' + str(filter_size), psnr, ('dsr', 'dsr'), downsample_ratios)
def vary_param_epsilon(input_img, guidance_img, filter_size): epsilons = np.array([0.1, 0.01, 0.001]) psnr = np.empty((0, 2), float) for epsilon in epsilons: # approach (1): filtered_img_1 = guided_upsampling(resize(input_img, guidance_img.shape), guidance_img, filter_size, epsilon) # approach (2): filtered_img_2 = guided_upsampling(input_img, guidance_img, filter_size, epsilon) # Calculate PSNR psnr_filtered_1 = compute_psnr(filtered_img_1, initial_img) psnr_filtered_2 = compute_psnr(filtered_img_2, initial_img) psnr = np.vstack((psnr, np.array([psnr_filtered_1, psnr_filtered_2]))) psnr = np.transpose(psnr) print(psnr) # print table np_table('psnr1', psnr, ('eps', 'eps', 'eps'), epsilons)
def vary_param_filter_size(input_img, guidance_img, epsilon, downsample_ratio): filter_sizes = np.array([9, 33, 129]) psnr = np.empty((0, 2), float) for filter_size in filter_sizes: # approach (1): filtered_img_1 = guided_upsampling(resize(input_img, guidance_img.shape), guidance_img, filter_size, epsilon) # approach (2): filtered_img_2 = guided_upsampling(input_img, guidance_img, filter_size, epsilon) # Calculate PSNR psnr_filtered_1 = compute_psnr(filtered_img_1, initial_img) psnr_filtered_2 = compute_psnr(filtered_img_2, initial_img) psnr = np.vstack((psnr, np.array([psnr_filtered_1, psnr_filtered_2]))) psnr = np.transpose(psnr) # print table np_table('vary-filter_size_eps-' + str(epsilon) + 'dsr-' + str(downsample_ratio), psnr, ('fsize', 'fsize', 'fsize'), filter_sizes)
print("---Performance Measure\n") print("Precision: [{:.2f}] | Recall: [{:.2f}] | F-measure: [{:.2f}]". format(score[0], score[1], score[2])) # list score_list = np.array(score) for p in range(len(part_times) - 1): # score measure score = score_onset_detection(onset_times, anno, tolerance=tolerance, time_interval=(part_times[p], part_times[p + 1])) score_list = np.vstack((score_list, np.array(score))) # print performance print( "Precision: [{:.2f}] | Recall: [{:.2f}] | F-measure: [{:.2f}]". format(score[0], score[1], score[2])) # table header header = ['Precision', 'Recall', 'F-measure'] # write results in table np_table('results', score_list, header=header) # -- # awesome plot #awesome_plot(x, fs, N, hop, c, thresh, anno, tolerance, onset_times, file_name)