def recon_2d_haar_folder_size(data,row_tree,col_tree,threshold=0.0): """ Reconstruction of a function in two variables (data) by the following: Find the bi-Haar expansion of data in terms of the row_tree/col_tree basis. Then set all coefficients corresponding to folders of size < threshold to 0.0, and perform the inverse transform. """ coefs, folder_sizes = haar.bihaar_transform(data,row_tree,col_tree,True) coefs[folder_sizes < threshold] = 0.0 return haar.inverse_bihaar_transform(coefs,row_tree,col_tree)
def recon_2d_haar_folder_size(data, row_tree, col_tree, threshold=0.0): """ Reconstruction of a function in two variables (data) by the following: Find the bi-Haar expansion of data in terms of the row_tree/col_tree basis. Then set all coefficients corresponding to folders of size < threshold to 0.0, and perform the inverse transform. """ coefs, folder_sizes = haar.bihaar_transform(data, row_tree, col_tree, True) coefs[folder_sizes < threshold] = 0.0 return haar.inverse_bihaar_transform(coefs, row_tree, col_tree)
def recon_2d_sure(data,row_tree,col_tree,estimated_var=1.0): """ Reconstruction of a function in two dimensions using SURE wavelet shrinkage. """ bihaar_coefs = haar.bihaar_transform(data, row_tree, col_tree) new_bihaar_coefs = np.zeros(bihaar_coefs.shape) row_levels = haar.level_correspondence(row_tree) col_levels = haar.level_correspondence(col_tree) coef_levels = np.add.outer(row_levels,col_levels) for level in np.unique(coef_levels): hc = bihaar_coefs[coef_levels==level] if len(hc) == 1: t = 0 else: x = np.arange(0,6.0,0.1) estimates = [] for threshold in x: estimate = sure(hc,threshold,estimated_var) estimates.append(estimate[0]) t = x[np.argmin(estimates)] new_bihaar_coefs[coef_levels==level] = shrink_coefs(hc,t) return haar.inverse_bihaar_transform(new_bihaar_coefs, row_tree, col_tree)
def recon_2d_sure(data, row_tree, col_tree, estimated_var=1.0): """ Reconstruction of a function in two dimensions using SURE wavelet shrinkage. """ bihaar_coefs = haar.bihaar_transform(data, row_tree, col_tree) new_bihaar_coefs = np.zeros(bihaar_coefs.shape) row_levels = haar.level_correspondence(row_tree) col_levels = haar.level_correspondence(col_tree) coef_levels = np.add.outer(row_levels, col_levels) for level in np.unique(coef_levels): hc = bihaar_coefs[coef_levels == level] if len(hc) == 1: t = 0 else: x = np.arange(0, 6.0, 0.1) estimates = [] for threshold in x: estimate = sure(hc, threshold, estimated_var) estimates.append(estimate[0]) t = x[np.argmin(estimates)] new_bihaar_coefs[coef_levels == level] = shrink_coefs(hc, t) return haar.inverse_bihaar_transform(new_bihaar_coefs, row_tree, col_tree)