Skip to content

Commit 32860fd

Browse files
authored
Remove trailing whitespace (#1108)
No functional changes
1 parent e890943 commit 32860fd

File tree

20 files changed

+56
-56
lines changed

20 files changed

+56
-56
lines changed

docs/src/examples/maxlikenlm.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ parameters = Optim.minimizer(opt)
196196
numerical_hessian = hessian!(func,parameters)
197197

198198
# Let's find the estimated value of σ, rather than log σ, and it's standard error
199-
# To do this, we will use the Delta Method: https://en.wikipedia.org/wiki/Delta_method
199+
# To do this, we will use the Delta Method: https://en.wikipedia.org/wiki/Delta_method
200200

201201
# this function exponetiates log σ
202202
function transform(parameters)
203203
parameters[end] = exp(parameters[end])
204204
parameters
205-
end
205+
end
206206

207207
# get the Jacobian of the transformation
208208
J = ForwardDiff.jacobian(transform, parameters)'

docs/src/examples/rasch.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ using Optim, Random #hide
1111
# assessment data such as student responses to a standardized
1212
# test. Let $X_{pi}$ be the response accuracy of student $p$
1313
# to item $i$ where $X_{pi}=1$ if the item was answered correctly
14-
# and $X_{pi}=0$ otherwise for $p=1,\ldots,n$ and $i=1,\ldots,m$.
15-
# The model for this accuracy is
14+
# and $X_{pi}=0$ otherwise for $p=1,\ldots,n$ and $i=1,\ldots,m$.
15+
# The model for this accuracy is
1616
# ```math
1717
# P(\mathbf{X}_{p}=\mathbf{x}_{p}|\xi_p, \mathbf\epsilon) = \prod_{i=1}^m \dfrac{(\xi_p \epsilon_j)^{x_{pi}}}{1 + \xi_p\epsilon_i}
1818
# ```
19-
# where $\xi_p > 0$ the latent ability of person $p$ and $\epsilon_i > 0$
20-
# is the difficulty of item $i$.
19+
# where $\xi_p > 0$ the latent ability of person $p$ and $\epsilon_i > 0$
20+
# is the difficulty of item $i$.
2121

2222
# We simulate data from this model:
2323

@@ -28,9 +28,9 @@ theta = randn(n)
2828
delta = randn(m)
2929
r = zeros(n)
3030
s = zeros(m)
31-
31+
3232
for i in 1:n
33-
p = exp.(theta[i] .- delta) ./ (1.0 .+ exp.(theta[i] .- delta))
33+
p = exp.(theta[i] .- delta) ./ (1.0 .+ exp.(theta[i] .- delta))
3434
for j in 1:m
3535
if rand() < p[j] ##correct
3636
r[i] += 1
@@ -40,9 +40,9 @@ for i in 1:n
4040
end
4141
f = [sum(r.==j) for j in 1:m];
4242

43-
# Since the number of parameters increases
44-
# with sample size standard maximum likelihood will not provide us
45-
# consistent estimates. Instead we consider the conditional likelihood.
43+
# Since the number of parameters increases
44+
# with sample size standard maximum likelihood will not provide us
45+
# consistent estimates. Instead we consider the conditional likelihood.
4646
# It can be shown that the Rasch model is an exponential family model and
4747
# that the sum score $r_p = \sum_{i} x_{pi}$ is the sufficient statistic for
4848
# $\xi_p$. If we condition on the sum score we should be able to eliminate
@@ -55,7 +55,7 @@ f = [sum(r.==j) for j in 1:m];
5555
# \gamma_r(\mathbf\epsilon) = \sum_{\mathbf{y} : \mathbf{1}^\intercal \mathbf{y} = r} \prod_{j=1}^m \epsilon_j^{y_j}
5656
# ```
5757
# where the sum is over all possible answer configurations that give a sum
58-
# score of $r$. Algorithms to efficiently compute $\gamma$ and its
58+
# score of $r$. Algorithms to efficiently compute $\gamma$ and its
5959
# derivatives are available in the literature (see eg Baker (1996) for a review
6060
# and Biscarri (2018) for a more modern approach)
6161

@@ -65,7 +65,7 @@ function esf_sum!(S::AbstractArray{T,1}, x::AbstractArray{T,1}) where T <: Real
6565
S[1] = one(T)
6666
@inbounds for col in 1:n
6767
for r in 1:col
68-
row = col - r + 1
68+
row = col - r + 1
6969
S[row+1] = S[row+1] + x[col] * S[row]
7070
end
7171
end
@@ -114,20 +114,20 @@ function neglogLC(β)
114114
return -s'log.(ϵ) + f'log.(S[2:end])
115115
end
116116

117-
# Parameter estimation is usually performed with respect to the unconstrained parameter
118-
# $\beta_i = -\log{\epsilon_i}$. Taking the derivative with respect to $\beta_i$
119-
# (and applying the chain rule) one obtains
117+
# Parameter estimation is usually performed with respect to the unconstrained parameter
118+
# $\beta_i = -\log{\epsilon_i}$. Taking the derivative with respect to $\beta_i$
119+
# (and applying the chain rule) one obtains
120120
# ```math
121-
# \dfrac{\partial\log L_C(\mathbf\epsilon|\mathbf{r})}{\partial \beta_i} = -s_i + \epsilon_i\sum_{r=1}^m \dfrac{f_r \gamma_{r-1}^{(j)}}{\gamma_r}
121+
# \dfrac{\partial\log L_C(\mathbf\epsilon|\mathbf{r})}{\partial \beta_i} = -s_i + \epsilon_i\sum_{r=1}^m \dfrac{f_r \gamma_{r-1}^{(j)}}{\gamma_r}
122122
# ```
123-
# where $\gamma_{r-1}^{(i)} = \partial \gamma_{r}(\mathbf\epsilon)/\partial\epsilon_i$.
123+
# where $\gamma_{r-1}^{(i)} = \partial \gamma_{r}(\mathbf\epsilon)/\partial\epsilon_i$.
124124

125125
function g!(storage, β)
126126
calculate_common!(β, last_β)
127127
for j in 1:m
128128
storage[j] = s[j]
129129
for l in 1:m
130-
storage[j] -= ϵ[j] * f[l] * (H[j,j,l+1] / S[l+1])
130+
storage[j] -= ϵ[j] * f[l] * (H[j,j,l+1] / S[l+1])
131131
end
132132
end
133133
end
@@ -147,25 +147,25 @@ function h!(storage, β)
147147
storage[k,j] = 0.0
148148
for l in 1:m
149149
if j == k
150-
storage[j,j] += f[l] * (ϵ[j]*H[j,j,l+1] / S[l+1]) *
150+
storage[j,j] += f[l] * (ϵ[j]*H[j,j,l+1] / S[l+1]) *
151151
(1 - ϵ[j]*H[j,j,l+1] / S[l+1])
152152
elseif k > j
153-
storage[k,j] += ϵ[j] * ϵ[k] * f[l] *
153+
storage[k,j] += ϵ[j] * ϵ[k] * f[l] *
154154
((H[k,j,l] / S[l+1]) - (H[j,j,l+1] * H[k,k,l+1]) / S[l+1] ^ 2)
155155
else #k < j
156-
storage[k,j] += ϵ[j] * ϵ[k] * f[l] *
156+
storage[k,j] += ϵ[j] * ϵ[k] * f[l] *
157157
((H[j,k,l] / S[l+1]) - (H[j,j,l+1] * H[k,k,l+1]) / S[l+1] ^ 2)
158158
end
159159
end
160160
end
161161
end
162162
end
163163

164-
# The estimates of the item parameters are then obtained via standard optimization
165-
# algorithms (either Newton-Raphson or L-BFGS). One last issue is that the model is
166-
# not identifiable (multiplying the $\xi_p$ by a constant and dividing the $\epsilon_i$
167-
# by the same constant results in the same likelihood). Therefore some kind of constraint
168-
# must be imposed when estimating the parameters. Typically either $\epsilon_1 = 0$ or
164+
# The estimates of the item parameters are then obtained via standard optimization
165+
# algorithms (either Newton-Raphson or L-BFGS). One last issue is that the model is
166+
# not identifiable (multiplying the $\xi_p$ by a constant and dividing the $\epsilon_i$
167+
# by the same constant results in the same likelihood). Therefore some kind of constraint
168+
# must be imposed when estimating the parameters. Typically either $\epsilon_1 = 0$ or
169169
# $\prod_{i=1}^m \epsilon_i = 1$ (which is equivalent to $\sum_{i=1}^m \beta_i = 0$).
170170

171171
con_c!(c, x) = (c[1] = sum(x); c)

docs/src/user/algochoice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ There are two main settings you must choose in Optim: the algorithm and the line
66

77
The first choice to be made is that of the order of the method. Zeroth-order methods do not have gradient information, and are very slow to converge, especially in high dimension. First-order methods do not have access to curvature information and can take a large number of iterations to converge for badly conditioned problems. Second-order methods can converge very quickly once in the vicinity of a minimizer. Of course, this enhanced performance comes at a cost: the objective function has to be differentiable, you have to supply gradients and Hessians, and, for second order methods, a linear system has to be solved at each step.
88

9-
If you can provide analytic gradients and Hessians, and the dimension of the problem is not too large, then second order methods are very efficient. The Newton method with trust region is the method of choice.
9+
If you can provide analytic gradients and Hessians, and the dimension of the problem is not too large, then second order methods are very efficient. The Newton method with trust region is the method of choice.
1010

1111
When you do not have an explicit Hessian or when the dimension becomes large enough that the linear solve in the Newton method becomes the bottleneck, first order methods should be preferred. BFGS is a very efficient method, but also requires a linear system solve. LBFGS usually has a performance very close to that of BFGS, and avoids linear system solves (the parameter `m` can be tweaked: increasing it can improve the convergence, at the expense of memory and time spent in linear algebra operations). The conjugate gradient method usually converges less quickly than LBFGS, but requires less memory. Gradient descent should only be used for testing. Acceleration methods are experimental.
1212

docs/src/user/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ In addition to the solver, you can alter the behavior of the Optim package by us
5252
* `show_warnings`: Should warnings due to NaNs or Inf be shown? Defaults to `true`.
5353
* `trace_simplex`: Include the full simplex in the trace for `NelderMead`. Defaults to `false`.
5454
* `show_every`: Trace output is printed every `show_every`th iteration.
55-
* `callback`: A function to be called during tracing. A return value of `true` stops the `optimize` call. The callback function is called every `show_every`th iteration. If `store_trace` is false, the argument to the callback is of the type [`OptimizationState`](https://github.com/JuliaNLSolvers/Optim.jl/blob/a1035134ca1f3ebe855f1cde034e32683178225a/src/types.jl#L155), describing the state of the current iteration. If `store_trace` is true, the argument is a list of all the states from the first iteration to the current.
55+
* `callback`: A function to be called during tracing. A return value of `true` stops the `optimize` call. The callback function is called every `show_every`th iteration. If `store_trace` is false, the argument to the callback is of the type [`OptimizationState`](https://github.com/JuliaNLSolvers/Optim.jl/blob/a1035134ca1f3ebe855f1cde034e32683178225a/src/types.jl#L155), describing the state of the current iteration. If `store_trace` is true, the argument is a list of all the states from the first iteration to the current.
5656
* `time_limit`: A soft upper limit on the total run time. Defaults to `NaN` (unlimited).
5757

5858
Box constrained optimization has additional keywords to alter the behavior of the outer solver:

joss/paper.bib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ @article{damle2018variational
9292
year = 2018,
9393
month = jan,
9494
adsurl = {http://adsabs.harvard.edu/abs/2018arXiv180108572D},
95-
adsnote = {Provided by the SAO/NASA Astrophysics Data System},
95+
adsnote = {Provided by the SAO/NASA Astrophysics Data System},
9696
}
9797

9898
@article{dony2018parametric,
@@ -119,7 +119,7 @@ @article{rackauckas2017differentialequations
119119
}
120120

121121
@article{regier2016celeste,
122-
author = {{Regier}, J. and {Pamnany}, K. and {Giordano}, R. and {Thomas}, R. and
122+
author = {{Regier}, J. and {Pamnany}, K. and {Giordano}, R. and {Thomas}, R. and
123123
{Schlegel}, D. and {McAuliffe}, J. and {Prabhat}},
124124
title = "{Learning an Astronomical Catalog of the Visible Universe through Scalable Bayesian Inference}",
125125
journal = {ArXiv e-prints},

src/multivariate/solvers/constrained/fminbox.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function in_box(bb::BoxBarrier, x)
3131
all(x->x[1]>=x[2] && x[1]<=x[3], zip(x, bb.lower, bb.upper))
3232
end
3333
in_box(bw::BarrierWrapper, x) = in_box(bw.b, x)
34-
# evaluates the value and gradient components comming from the log barrier
34+
# evaluates the value and gradient components comming from the log barrier
3535
function _barrier_term_value(x::T, l, u) where T
3636
dxl = x - l
3737
dxu = u - x
38-
38+
3939
if dxl <= 0 || dxu <= 0
4040
return T(Inf)
4141
end
@@ -53,7 +53,7 @@ function _barrier_term_gradient(x::T, l, u) where T
5353
if isfinite(u)
5454
g += one(T)/dxu
5555
end
56-
return g
56+
return g
5757
end
5858
function value_gradient!(bb::BoxBarrier, g, x)
5959
g .= _barrier_term_gradient.(x, bb.lower, bb.upper)
@@ -134,7 +134,7 @@ end
134134
# position, the gradient of the input function should dominate the
135135
# gradient of the barrier.
136136
function initial_mu(gfunc::AbstractArray{T}, gbarrier::AbstractArray{T}, mu0factor::T = T(1)/1000, mu0::T = convert(T, NaN)) where T
137-
137+
138138
if isnan(mu0)
139139
gbarriernorm = sum(abs, gbarrier)
140140
if gbarriernorm > 0
@@ -378,7 +378,7 @@ function optimize(
378378
# we need to update the +mu*barrier_grad part. Since we're using the
379379
# value_gradient! not !! as in initial_state, we won't make a superfluous
380380
# evaluation
381-
381+
382382
if !(F.method isa NelderMead)
383383
value_gradient!(dfbox, x)
384384
else
@@ -412,7 +412,7 @@ function optimize(
412412
println()
413413
println("Decreasing barrier term μ.\n")
414414
end
415-
415+
416416
# Decrease mu
417417
dfbox.mu *= T(F.mufactor)
418418
# Test for convergence
@@ -429,7 +429,7 @@ function optimize(
429429
stopped_by_time_limit = _time-t0 > options.time_limit ? true : false
430430
stopped = stopped_by_time_limit
431431
end
432-
432+
433433
stopped_by =(#f_limit_reached=f_limit_reached,
434434
#g_limit_reached=g_limit_reached,
435435
#h_limit_reached=h_limit_reached,

src/multivariate/solvers/constrained/ipnewton/interior.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ end
203203
function optimize(d, lower::AbstractArray, upper::AbstractArray, initial_x::AbstractArray, method::ConstrainedOptimizer,
204204
options::Options = Options(;default_options(method)...))
205205
twicediffed = d isa TwiceDifferentiable ? d : TwiceDifferentiable(d, initial_x)
206-
206+
207207
bounds = ConstraintBounds(lower, upper, [], [])
208208
constraints = TwiceDifferentiableConstraints(
209209
(c,x)->nothing, (J,x)->nothing, (H,x,λ)->nothing, bounds)

src/multivariate/solvers/constrained/samin.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function optimize(obj_fn, lb::AbstractArray, ub::AbstractArray, x::AbstractArray
258258
# last value close enough to last neps values?
259259
fstar[1] = f_old
260260
f_absΔ = abs.(fopt - f_old) # close enough to best so far?
261-
if all((abs.(fopt .- fstar)) .< f_tol) # within to for last neps trials?
261+
if all((abs.(fopt .- fstar)) .< f_tol) # within to for last neps trials?
262262
f_converged = true
263263
# check for bound narrow enough for parameter convergence
264264
if any(bounds .> x_tol)

src/multivariate/solvers/first_order/adam.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function initial_state(method::Adam, options, d, initial_x::AbstractArray{T}) wh
4242

4343
value_gradient!!(d, initial_x)
4444
α, β₁, β₂ = method.α, method.β₁, method.β₂
45-
45+
4646
m = copy(gradient(d))
4747
u = zero(m)
4848
a = 1 - β₁

src/multivariate/solvers/first_order/adamax.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function initial_state(method::AdaMax, options, d, initial_x::AbstractArray{T})
4343

4444
value_gradient!!(d, initial_x)
4545
α, β₁, β₂ = method.α, method.β₁, method.β₂
46-
46+
4747
m = copy(gradient(d))
4848
u = zero(m)
4949
a = 1 - β₁

src/multivariate/solvers/first_order/cg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function reset!(cg, cgs::ConjugateGradientState, obj, x)
111111
if cg.P !== nothing
112112
project_tangent!(cg.manifold, cgs.pg, x)
113113
end
114-
cgs.s .= -cgs.pg
114+
cgs.s .= -cgs.pg
115115
cgs.f_x_previous = typeof(cgs.f_x_previous)(NaN)
116116
end
117117
function initial_state(method::ConjugateGradient, options, d, initial_x)

src/univariate/optimize/interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function optimize(f,
3535
lower::Union{Integer, Real},
3636
upper::Union{Integer, Real};
3737
kwargs...)
38-
38+
3939
T = promote_type(typeof(lower/1), typeof(upper/1))
4040
optimize(f,
4141
T(lower),
@@ -48,7 +48,7 @@ function optimize(f,
4848
upper::Union{Integer, Real},
4949
method::Union{Brent, GoldenSection};
5050
kwargs...)
51-
51+
5252
T = promote_type(typeof(lower/1), typeof(upper/1))
5353
optimize(f,
5454
T(lower),

src/univariate/printing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Base.show(io::IO, r::UnivariateOptimizationResults)
4343
status_string = ""
4444
if time_run(r) > time_limit(r)
4545
status_string *= "failure (exceeded time limit of $(time_limit(r)))"
46-
else
46+
else
4747
status_string = "success"
4848
end
4949

src/univariate/solvers/golden_section.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function optimize(f, x_lower::T, x_upper::T,
130130
rel_tol,
131131
abs_tol,
132132
tr,
133-
f_calls,
133+
f_calls,
134134
time_limit,
135135
_time)
136136
end

test/general/objective_types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
@test Optim.gradient(odad2) == [0.0]
1414
# @test odad3.g == [0.0]
1515
end
16-
16+
1717
for a in (1.0, 5.0)
1818
xa = rand(1)
1919
odad1 = OnceDifferentiable(x->a*x[1], xa; autodiff = :finite)
2020
odad2 = OnceDifferentiable(x->a*x[1], xa; autodiff = :forward)
21-
# odad3 = OnceDifferentiable(x->a*x[1], xa; autodiff = :reverse)
21+
# odad3 = OnceDifferentiable(x->a*x[1], xa; autodiff = :reverse)
2222
Optim.gradient!(odad1, xa)
2323
Optim.gradient!(odad2, xa)
2424
@test Optim.gradient(odad1) [a]

test/multivariate/measurements.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ import Measurements
99
#given an initial value, they should give the exact same answer
1010
@test all(Optim.minimizer(resmes) .|> Measurements.value .== Optim.minimizer(resfloat))
1111
@test Optim.minimum(resmes) .|> Measurements.value .== Optim.minimum(resfloat)
12-
12+
1313
end

test/multivariate/optimize/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
end
5454

5555
@testset "#718" begin
56-
56+
5757
f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
5858
function g!(G, x)
5959
G[1] = -2.0 * (1.0 - x[1]) - 400.0 * (x[2] - x[1]^2) * x[1]

test/multivariate/solvers/first_order/adam_adamax.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# TODO: Check why skip problems fail
1515
skip = ("Large Polynomial", "Parabola", "Paraboloid Random Matrix",
1616
"Paraboloid Diagonal", "Penalty Function I", "Polynomial", "Powell",
17-
"Extended Powell", "Trigonometric", "Himmelblau", "Rosenbrock", "Extended Rosenbrock",
18-
"Quadratic Diagonal", "Beale", "Fletcher-Powell", "Exponential",
17+
"Extended Powell", "Trigonometric", "Himmelblau", "Rosenbrock", "Extended Rosenbrock",
18+
"Quadratic Diagonal", "Beale", "Fletcher-Powell", "Exponential",
1919
)
2020
run_optim_tests(Adam();
2121
skip = skip,
@@ -38,7 +38,7 @@ end
3838
skip = ("Trigonometric", "Large Polynomial", "Parabola", "Paraboloid Random Matrix",
3939
"Paraboloid Diagonal", "Extended Rosenbrock", "Penalty Function I", "Beale",
4040
"Extended Powell", "Himmelblau", "Large Polynomial", "Polynomial", "Powell",
41-
"Exponential",
41+
"Exponential",
4242
)
4343
run_optim_tests(AdaMax();
4444
skip = skip,

test/univariate/solvers/brent.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@test Optim.converged(result)
2828
@test Optim.minimum(result) == -1.0
2929

30-
## time limit
30+
## time limit
3131
function slow_obj(x)
3232
sleep(0.05)
3333
return sin(x)

test/univariate/solvers/golden_section.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@test Optim.minimum(result) == 2.0
1717
@test_throws ErrorException optimize(identity, 2.0, 1.0, GoldenSection())
1818

19-
## time limit
19+
## time limit
2020
function slow_obj(x)
2121
sleep(0.05)
2222
return sin(x)

0 commit comments

Comments
 (0)