-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from ethan-lame/dev
Compressed Sensing Implementation
- Loading branch information
Showing
12 changed files
with
677 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,62 @@ | ||
import h5py | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import scipy.fft as spfft | ||
import cvxpy as cp | ||
|
||
# Note: there are some lines in main.py with np.save(...) that I added | ||
# for ease of post-processing, like getting the center points used and | ||
# the sampling matrix S. None are required for the input file and this | ||
# script to run, but may be useful for debugging purposes | ||
|
||
# Load results | ||
with h5py.File("output.h5", "r") as f: | ||
# print(f["tallies"].keys()) | ||
print(f["input_deck"]["cell_tallies"].keys()) | ||
S = f["tallies"]["cs_tally_0"]["S"][:] | ||
recon = f["tallies"]["cs_tally_0"]["fission"]["reconstruction"] | ||
plt.imshow(recon) | ||
plt.title("Reconstruction, $\lambda$ = 0.5") # assuming l in main.py remains at 0.5 | ||
plt.colorbar() | ||
plt.show() | ||
|
||
cs_results = f["tallies"]["cs_tally_0"]["fission"]["mean"][:] | ||
|
||
mesh_results = f["tallies"]["mesh_tally_0"]["fission"]["mean"][:] | ||
plt.imshow(mesh_results) | ||
plt.title("mesh results") | ||
plt.colorbar() | ||
plt.show() | ||
|
||
Nx = 40 | ||
Ny = 40 | ||
N_fine_cells = Nx * Ny | ||
|
||
# Can use this for post-processing | ||
# mesh_b = S @ mesh_results.flatten() | ||
# b = mesh_b | ||
|
||
# Use this for analyzing the in-situ results | ||
cs_b = cs_results | ||
b = cs_b | ||
|
||
for i in range(len(f["input_deck"]["cell_tallies"])): | ||
fission_score = f[f"tallies/cell_tally_{i}/fission"] | ||
# Constructing T and A | ||
idct_basis_x = spfft.idct(np.identity(Nx), axis=0) | ||
idct_basis_y = spfft.idct(np.identity(Ny), axis=0) | ||
|
||
print( | ||
f'for sphere {i+1}, mean = {fission_score["mean"][()]}, sdev = {fission_score["sdev"][()]}' | ||
) | ||
T_inv = np.kron(idct_basis_y, idct_basis_x) | ||
A = S @ T_inv | ||
|
||
# print(fission_score["mean"][()]) | ||
# print(fission_score["sdev"][()]) | ||
# Basis pursuit denoising solver - change l to get different results | ||
vx = cp.Variable(N_fine_cells) | ||
l = 10 | ||
objective = cp.Minimize(0.5 * cp.norm(A @ vx - b, 2) + l * cp.norm(vx, 1)) | ||
prob = cp.Problem(objective) | ||
result = prob.solve(verbose=False) | ||
sparse_solution = np.array(vx.value).squeeze() | ||
|
||
# print(f"fission_score mean = {fission_score["mean"][()]}") | ||
# print(f"fission_score mean = {fission_score["sdev"][()]}") | ||
# Obtaining the reconstruction | ||
recon = T_inv @ sparse_solution | ||
recon_reshaped = recon.reshape(Ny, Nx) | ||
|
||
# cell = f["tallies/cell_tally_0/fission"] | ||
# print(f'sphere1 mean = {cell["mean"][()]}') | ||
# print(f'sphere2 sdev = {cell["sdev"][()]}') | ||
plt.imshow(recon_reshaped) | ||
plt.title(f"Reconstruction, $\lambda$ = {l}") | ||
plt.colorbar() | ||
plt.show() |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.