|
1 __precompile__() |
|
2 |
|
3 module Stats |
|
4 |
|
5 |
|
6 ######################## |
|
7 # Load external modules |
|
8 ######################## |
|
9 |
|
10 using CSV, DataFrames |
|
11 using Statistics |
|
12 |
|
13 export calculate_statistics |
|
14 |
|
15 function calculate_statistics() |
|
16 ImName = ("lighthouse200x300", "shepplogan256x256", "brainphantom256x256") |
|
17 AlgName = ("dualscaling", "greedy","noprediction","primalonly","proximal","rotation","zerodual") |
|
18 mystart = 41 # Corresponds to the 500th iterate |
|
19 |
|
20 # Define an array to store results |
|
21 results = DataFrame(experiment = String[], α = Float64[], algorithm = String[], psnr_mean1 = Float64[], psnr_mean500 = Float64[], psnr_ci = String[], ssim_mean1 = Float64[], ssim_mean500 = Float64[], ssim_ci = String[]) |
|
22 |
|
23 for imname in ImName |
|
24 for algname in AlgName |
|
25 directory_path = "./img/" |
|
26 files = readdir(directory_path) |
|
27 filtered_files = filter(file -> startswith(file, "$(imname)_pdps_known_$(algname)") && endswith(file, ".txt"), files) |
|
28 |
|
29 for file in filtered_files |
|
30 filename = directory_path * file |
|
31 data = CSV.File(filename, delim='\t', header=2) |> DataFrame |
|
32 |
|
33 # Extract α from filename |
|
34 α, _, _ = extract_parameters(filename) |
|
35 |
|
36 |
|
37 # Extract SSIM and PSNR columns starting from 1st iteration |
|
38 ssim_values1 = Float64.(data[:, :ssim]) |
|
39 psnr_values1 = Float64.(data[:, :psnr]) |
|
40 |
|
41 # Extract SSIM and PSNR columns starting from 500th iteration |
|
42 ssim_values500 = Float64.(data[mystart:end, :ssim]) |
|
43 psnr_values500 = Float64.(data[mystart:end, :psnr]) |
|
44 |
|
45 # Calculate mean and confidence intervals |
|
46 ssim_mean1 = round(mean(ssim_values1), digits=4) |
|
47 psnr_mean1 = round(mean(psnr_values1), digits=4) |
|
48 |
|
49 ssim_mean500 = round(mean(ssim_values500), digits=4) |
|
50 psnr_mean500 = round(mean(psnr_values500), digits=4) |
|
51 ssim_std500 = round(std(ssim_values500), digits=4) |
|
52 psnr_std500 = round(std(psnr_values500), digits=4) |
|
53 n = length(ssim_values500) |
|
54 |
|
55 ssim_ci_lower = round(ssim_mean500 - 1.96 * ssim_std500 / sqrt(n), digits=4) |
|
56 ssim_ci_upper = round(ssim_mean500 + 1.96 * ssim_std500 / sqrt(n), digits=4) |
|
57 psnr_ci_lower = round(psnr_mean500 - 1.96 * psnr_std500 / sqrt(n), digits=4) |
|
58 psnr_ci_upper = round(psnr_mean500 + 1.96 * psnr_std500 / sqrt(n), digits=4) |
|
59 |
|
60 ssim_ci = "$(ssim_ci_lower) - $(ssim_ci_upper)" |
|
61 psnr_ci = "$(psnr_ci_lower) - $(psnr_ci_upper)" |
|
62 experiment = "$(imname)" |
|
63 algorithm = "$(algname)" |
|
64 |
|
65 # Append results to DataFrame |
|
66 push!(results, (experiment, α, algorithm, psnr_mean1, psnr_mean500, psnr_ci, ssim_mean1, ssim_mean500, ssim_ci)) |
|
67 end |
|
68 end |
|
69 end |
|
70 sort!(results, [:experiment, :α]) |
|
71 csv_path = "./img/summarystats.csv" |
|
72 if isfile(csv_path) |
|
73 rm(csv_path) |
|
74 end |
|
75 CSV.write(csv_path, results) |
|
76 end |
|
77 |
|
78 end |