Created
October 12, 2022 19:15
-
-
Save crhea93/afd2eaafee15ddbe13dbe51e87412279 to your computer and use it in GitHub Desktop.
RIM-create-gaussians
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = 50 # Size of spectrum | |
| N = 5000 # Number of spectra | |
| def gaussian(x, mu, sig): | |
| return 1*np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.))) | |
| def conv_mat(n): | |
| """ | |
| Create convolution matrix that is an identity matrix with noise | |
| """ | |
| conv_mat = np.eye(n)+np.random.normal(0, 0.05, (n,n)) | |
| return conv_mat | |
| def create_convolved(N): | |
| ''' | |
| Create convolved Gaussian that are 28x28 | |
| Args: | |
| n - number of Gausians | |
| Return: | |
| gaussians - List of convolved Gaussians | |
| ''' | |
| a = 0.01 # Powerlaw slope | |
| gaussians_initial = [] # List of initial Gaussians | |
| powerlaw_conv = [] # List of Powerlaws used in convolution | |
| gaussians_final = [] # List of final Gaussians after convolution | |
| noise = [] # List of noises added | |
| for i in range(N): | |
| # Create original 1D Gaussian (32 points) | |
| x = np.linspace(-1,1,n) | |
| gaus_orig = gaussian(x, np.random.uniform(0,.01), np.random.uniform(0,0.1)) | |
| gaussians_initial.append(gaus_orig) | |
| # Convolve with additional Gaussian | |
| conv_mat_ = conv_mat(n) | |
| gaus_conv = conv_mat_@gaus_orig | |
| # Add noise | |
| noise_ = np.random.normal(0,0.1, n) | |
| gaus_noise = gaus_conv + noise_ | |
| gaussians_final.append(gaus_noise) | |
| powerlaw_conv.append(conv_mat_) | |
| noise.append(noise_) | |
| return gaussians_initial,gaussians_final,powerlaw_conv,noise | |
| # Create N instances | |
| gaussians_initial, gaussians_final,powerlaw_conv,noise = create_convolved(N) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment