Skip to content

Commit b8c8210

Browse files
committed
Hopefully found the bug!
1 parent da905e3 commit b8c8210

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/solvers/gradient_sampling.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ end
181181
function default_stepsize(
182182
M::AbstractManifold, ::Type{GradientSamplingState}; retraction_method = default_retraction_method(M),
183183
)
184-
return ArmijoLinesearchStepsize(M; stop_increasing_at_step = 1, retraction_method = retraction_method, initial_stepsize = 1.0)
184+
return ArmijoLinesearchStepsize(M; retraction_method = retraction_method)
185185
end
186186
#
187187
#
@@ -317,7 +317,7 @@ function gradient_sampling!(
317317
sub_state = InplaceEvaluation(),
318318
sampling_radius_reduction::Real = 0.5, sampling_radius_threshold::Real = 1.0e-2,
319319
subgradient_norm_reduction::Real = 0.5, subgradient_norm_tolerance::Real = 0.1, subgradient_norm_threshold::Real = 1.0e-3,
320-
stopping_criterion::StoppingCriterion = StopAfterIteration(200) | (
320+
stopping_criterion::StoppingCriterion = StopAfterIteration(100) | (
321321
StopWhenGradientNormLess(subgradient_norm_threshold) & (
322322
StopWhenSmallerOrEqual(:sampling_radius, sampling_radius_threshold)
323323
)
@@ -338,12 +338,10 @@ function gradient_sampling!(
338338
sample_size = sample_size,
339339
convex_hull_coeffs = convex_hull_coeffs,
340340
retraction_method = retraction_method,
341-
sampled_points = sampled_points,
342-
sampled_vectors = sampled_vectors,
341+
sampled_points = sampled_points, sampled_vectors = sampled_vectors,
343342
sampling_radius = sampling_radius,
344343
sampling_radius_reduction = sampling_radius_reduction,
345-
subgradient_norm_reduction = subgradient_norm_reduction,
346-
subgradient_norm_tolerance = subgradient_norm_tolerance,
344+
subgradient_norm_reduction = subgradient_norm_reduction, subgradient_norm_tolerance = subgradient_norm_tolerance,
347345
stepsize = _produce_type(stepsize, M, p),
348346
stopping_criterion = stopping_criterion,
349347
vector_transport_method = vector_transport_method,
@@ -401,8 +399,8 @@ function step_solver!(
401399
else
402400
# We already have the gradient in the sampled vectors[1]
403401
# and set normed -Y as search direction
404-
step = get_stepsize(mp, gss, i, -gss.Y / norm(M, gss.p, gss.Y))
405-
ManifoldsBase.retract_fused!(M, gss.p, gss.p, gss.X, step, gss.retraction_method)
402+
step = get_stepsize(mp, gss, i, -gss.Y / norm(M, gss.p, gss.Y); gradient = gss.sampled_vectors[1])
403+
ManifoldsBase.retract_fused!(M, gss.p, gss.p, -gss.Y / norm(M, gss.p, gss.Y), step, gss.retraction_method)
406404
get_gradient!(mp, gss.X, gss.p)
407405
end
408406
return gss

test/solvers/test_gradient_sampling.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ f(M, p) = sum(1 / (2 * d) * distance.(Ref(M), Ref(p), data) .^ 2)
1717
grad_f(M, p) = sum(1 / d * grad_distance.(Ref(M), data, Ref(p)))
1818

1919
# For comparison
20-
#m1 = gradient_descent(
21-
# M, f, grad_f, p0;
22-
# return_state = true,
23-
# record = [:Iteration, :Cost, RecordGradientNorm()]
24-
#);
20+
m1 = gradient_descent(
21+
M, f, grad_f, p0;
22+
return_state = true,
23+
debug = _debug_gradient_sampling ? [:Iteration, :Cost, " ", :Stepsize, " ", :GradientNorm, "\n", :Stop] : [],
24+
record = [:Iteration, :Cost, RecordGradientNorm()]
25+
);
2526

2627
m2 = gradient_sampling(
2728
M, f, grad_f, p0;
2829
return_state = true,
29-
debug = _debug_gradient_sampling ? [:Iteration, :Cost, " ", :Stepsize, " ", :GradientNorm, "\n", :Stop] : [],
30+
debug = _debug_gradient_sampling ? [:Iteration, :Cost, " ", :Stepsize, " ", :GradientNorm, " ", :Change, "\n", :Stop] : [],
3031
record = [:Iteration, :Cost, RecordGradientNorm()]
3132
)
3233

3334
if _debug_gradient_sampling
34-
using CairoMakie
35-
# p1 = get_solver_result(m1)
35+
p1 = get_solver_result(m1)
3636
p2 = get_solver_result(m2)
37-
# @info "p1 " p1 "with cost " f(M, p1)
37+
@info "p1 " p1 "with cost " f(M, p1)
3838
@info "p2 " p2 "with cost " f(M, p2)
39-
39+
using CairoMakie
4040
fig, ax, plt = lines(get_record(m2, :Iteration, 1), get_record(m2, :Iteration, 2))
41-
# lines!(ax, get_record(m1, :Iteration, 1),get_record(m1, :Iteration, 2))
41+
lines!(ax, get_record(m1, :Iteration, 1), get_record(m1, :Iteration, 2))
4242
fig
4343
end

0 commit comments

Comments
 (0)