Skip to content

Commit

Permalink
updates according to pull request comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Ortner committed May 10, 2016
1 parent 5a64f9a commit 7f79877
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/gradient_descent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ function optimize{T}(d::DifferentiableFunction,

# The current search direction
s = similar(x)

# Buffers for use in line search
x_ls = similar(x)
gr_ls = similar(x)

# Store f(x) in f_x
f_x_previous, f_x = NaN, d.fg!(x, gr)
f_calls, g_calls = f_calls + 1, g_calls + 1

# Keep track of step-sizes
alpha = alphainit(one(T), x, gr, f_x)

Expand Down
5 changes: 2 additions & 3 deletions src/l_bfgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ function twoloop!(s::Vector,
end

# Copy q into s for forward pass
# UNPRECONDITIONED: copy!(s, q)
# this is equivalent to choosing Id as the preconditioner / initial guess
# PRECONDITIONING: (preconditioner update was done outside!)
# apply preconditioner if precon != nothing
# (Note: preconditioner update was done outside of this function)
precondfwd!(s, precon, q)

# Forward pass
Expand Down
12 changes: 5 additions & 7 deletions src/precon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ precondprep!(P::Void, x) = nothing
#####################################################
# [2] Diagonal preconditioner

function precondfwd!{T}(out::Array, p::Vector, A::Array{T})
function precondfwd!(out::Array, p::Vector, A::Array)
@simd for i in 1:length(A)
@inbounds out[i] = p[i] * A[i]
end
Expand All @@ -56,11 +56,9 @@ end

#####################################################
# [3] Matrix Preconditioner
# this assumption here is that P is given by its inverse, which
# is more typical
# the assumption here is that P is given by its inverse, which is typical

PMAT = Union{Matrix,SparseMatrixCSC}
precondfwd!(out::Vector, P::PMAT, A::Vector) = copy!(out, P \ A)
precondfwddot(A::Vector, P::PMAT, B::Vector) = dot(A, P \ B)
precondinvdot(A::Vector, P::PMAT, B::Vector) = dot(A, P * B)
precondfwd!(out::Vector, P::AbstractMatrix, A::Vector) = copy!(out, P \ A)
precondfwddot(A::Vector, P::AbstractMatrix, B::Vector) = dot(A, P \ B)
precondinvdot(A::Vector, P::AbstractMatrix, B::Vector) = dot(A, P * B)

0 comments on commit 7f79877

Please sign in to comment.