Skip to content

Commit 8656e03

Browse files
author
arismav
committed
remove paper method
1 parent 201fdf9 commit 8656e03

File tree

1 file changed

+17
-87
lines changed

1 file changed

+17
-87
lines changed

src/sge.jl

Lines changed: 17 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct sge <: regularization_solver
4343
s_weight::Real
4444
end
4545

46-
4746
function solve_regularization(K::AbstractMatrix, g::AbstractVector, α::Real, solver::sge)
4847

4948
s = sigmoid(X, solver.s_centre , width = solver.s_width)
@@ -53,46 +52,13 @@ function solve_regularization(K::AbstractMatrix, g::AbstractVector, α::Real, so
5352

5453
end
5554

56-
57-
# Testing the paper method, for reference
58-
function SGE_washburn(X, M, to, T2;
59-
smoothing = 0.0001,
60-
sig = 38,
61-
sigwidth = 1.0,
62-
sigweightA = 0.001,
63-
sigweightB = 0.001,
64-
)
65-
66-
halfX = div(length(X), 2)
67-
A = X[1:halfX]
68-
B = X[(halfX + 1):end]
69-
70-
T = eltype(X)
71-
72-
Mhat = zeros(T, length(M))
73-
74-
sigcent = collect(T, (-sig):(-sig + halfX - 1))
75-
76-
sigup = ((1 ./ (1 .+ exp.(-sigcent .* sigwidth))) .* sigweightA) .+ smoothing
77-
sigdown = (smoothing .+ (1 .- (1 ./ (1 .+ exp.(-sigcent .* sigwidth)))) .* sigweightB)
78-
79-
for ii in 1:halfX
80-
Mhat .+= A[ii] .* exp.(-((to ./ T2[ii]) .^ 2)) .+ B[ii] .* exp.(-to ./ T2[ii])
81-
end
82-
83-
SS = sum((M .- Mhat) .^ 2) + sum(A .* sigup) + sum(B .* sigdown)
84-
85-
return SS
86-
end
87-
8855
function log_gaussian(x, μ, σ, amp)
8956
return amp .* exp.(-(log10.(x) .- log10(μ)).^2 ./ (2 * σ^2))
9057
end
9158

92-
function test_sge()
59+
function test_sge(mode::Int = 1)
9360

94-
# make T distributions
95-
X = collect(logrange(1e-5, 1, 50))
61+
X = collect(logrange(1e-5, 1, floor(Int, 128/mode)))
9662
f_gauss = log_gaussian(X, 0.2e-3, 0.2, 0.6)
9763
f_exp = log_gaussian(X, 0.6e-1, 0.2, 0.4)
9864

@@ -108,60 +74,24 @@ function test_sge()
10874

10975
s = sigmoid(X, 5e-3 , width = 0.001)
11076

111-
# return X, f_gauss + f_exp
112-
11377
K_sge = [K_g K_e]
11478

11579
s_weight = 1
11680

117-
solver = optim_nnls(L = Diagonal(s_weight .* [s ; 1 .- s]), opts= Optim.Options(show_trace=true))
118-
119-
f, r = solve_regularization(K_sge, y, 1.0, solver)
120-
121-
return f
122-
123-
# initial_guess = fill(1.0 / (length(X) * 2), length(X) * 2)
124-
# lower_bounds = fill(0.0, length(initial_guess))
125-
# upper_bounds = fill(200.0, length(initial_guess))
126-
#
127-
# inner_obj = X -> NMRInversions.SGE_washburn(X, y, x, X)
128-
#
129-
# res = optimize(
130-
# inner_obj,
131-
# lower_bounds,
132-
# upper_bounds,
133-
# initial_guess,
134-
# Fminbox(LBFGS()),
135-
# Optim.Options(
136-
# show_trace = true,
137-
# outer_iterations = 5,
138-
# iterations = 100,
139-
# f_abstol = 1e-3,
140-
# f_reltol = 1e-3,
141-
# g_tol = 1e-4
142-
# ),
143-
# autodiff = :forward
144-
# )
145-
#
146-
# optimized_X = Optim.minimizer(res)
147-
# A_final = optimized_X[1:length(X)]
148-
# B_final = optimized_X[length(X)+1:end]
149-
#
150-
# return x, y, X, f_gauss, f_exp, A_final, B_final
151-
#
152-
end
81+
if mode == 1
15382

154-
#==
155-
function testplot(x, y, T2Values, f_gauss, f_exp, A_final, B_final)
156-
fig = GLMakie.Figure()
157-
ax_1 = GLMakie.Axis(fig[1,:], xscale = log10, title="Distribution")
158-
ax_2 = GLMakie.Axis(fig[2,:], title = "CPMG")
159-
ax_3 = GLMakie.Axis(fig[3,:], xscale = log10, title="Results")
160-
lines!(ax_1, T2Values, f_gauss)
161-
lines!(ax_1, T2Values, f_exp)
162-
lines!(ax_2, x, y)
163-
lines!(ax_3, T2Values, A_final)
164-
lines!(ax_3, T2Values, B_final)
165-
return fig
83+
# solver=optim_nnls(opts= Optim.Options(show_trace=true))
84+
# return @time invert(CPMG,x,y, alpha = 1.0, solver=solver )
85+
86+
solver = nnls(L = 0, algorithm=:fnnls)
87+
return @time invert(CPMG,x,y, solver=solver )
88+
89+
elseif mode ==2
90+
91+
# solver = optim_nnls(L = Diagonal(s_weight .* [s ; 1 .- s]), opts= Optim.Options(show_trace=true))
92+
solver = nnls(L = Diagonal(s_weight .* [s ; 1 .- s]),algorithm=:pivot)
93+
94+
f, r = @time solve_regularization(K_sge, y, 0.1, solver)
95+
return f
96+
end
16697
end
167-
==#

0 commit comments

Comments
 (0)