Skip to content

Commit

Permalink
merge in master
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Jan 5, 2018
1 parent 3dff681 commit b1b84ef
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions src/derivative_free.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,89 +149,76 @@ end
# * `f(x) == 0.0` or
# * `f(prevfloat(x)) * f(nextfloat(x)) < 0`.
# if a bracket is found that can be done, otherwise secant step is used
function update_state(method::Order0, fs, o::UnivariateZeroState{T}, options::UnivariateZeroOptions{T}) where {T}
function update_state(method::Order0, fs, o::UnivariateZeroState{T}, options::UnivariateZeroOptions) where {T}

f = fs
α = o.xn0
β = o.xn1
= o.fxn0
= o.fxn1

S = eltype(fα)
f = fs.f
alpha, beta = o.xn0, o.xn1
falpha, fbeta = o.fxn0, o.fxn1

incsteps(o)

if sign() * sign() < 0.0
if sign(falpha) * sign(fbeta) < 0.0
_run_bisection(fs, o, options)
return nothing
end

gamma, issue = guarded_secant_step(alpha, beta, falpha, fbeta)

= fs(ξ)
incfn(o)
fgamma = f(gamma); incfn(o)

if sign(fξ) * sign(fβ) < 0.0
o.xn0 = ξ
o.xn1 = β
o.fxn0 =
o.fxn1 =
if sign(fgamma)*sign(fbeta) < 0.0
o.xn0, o.xn1 = gamma, beta
o.fxn0, o.fxn1 = fgamma, fbeta
_run_bisection(fs, o, options)
return nothing
return nothing
end

if norm(fξ) <= norm(fβ)
o.xn0 = β
o.xn1 = ξ
o.fxn0 =
o.fxn1 =

if norm(fgamma) <= norm(fbeta)
o.xn0, o.xn1 = beta, gamma
o.fxn0, o.fxn1 = fbeta, fgamma
return nothing
end

ctr = 0
while true
## quadratic step
ctr += 1
if ctr >= 3
o.stopped = true
o.message = "dithering, algorithm failed to improve using quadratic steps"
return nothing
o.stopped = true
o.message = "dithering, algorithm failed to improve using quadratic steps"
return nothing
end

# quadratic_step. Put new ξ at vertex of parabola through α, β, (old) ξ
denom = (β - α) * ( - ) - (β - ) * ( - )
# quadratic_step. Put new gamma at vertex of parabola through alpha, beta, (old) gamma
denom = (beta - alpha) * (fbeta - fgamma) - (beta - fgamma) * (fbeta - falpha)
if isissue(denom)
o.stopped = true
o.stopped
o.message = "dithering, algorithm failed to improve using quadratic steps"
return nothing
end
ξ = tmp::T = β - ((β - α)^2 * ( - ) - (β - ξ)^2 * ( - ))/denom/2
gamma = beta - ((beta - alpha)^2 * (fbeta - fgamma) - (beta - gamma)^2 * (fbeta - falpha))/denom/2


= ftmp::S = f); incfn(o)
fgamma = f(gamma); incfn(o)
incfn(o)

if norm() < norm()
o.xn0, o.xn1 = β, ξ
o.fxn0, o.fxn1 = fβ, fξ
if norm(fgamma) < norm(fbeta)
o.xn0, o.xn1 = beta, gamma
o.fxn0, o.fxn1 = fbeta, fgamma
return nothing
end

theta, issue = guarded_secant_step(beta, gamma, fbeta, fgamma)

ftheta = f(theta); incfn(o)

if sign(fθ) * sign(fβ) < 0

o.xn0 = β
o.xn1 = θ
o.fxn0 =
o.fxn1 =
if sign(ftheta) * sign(fbeta) < 0
o.xn0, o.xn1 = beta, theta
o.fxn0, o.fxn1 = fbeta, ftheta

_run_bisection(fs, o, options)
return nothing
end

end

# failed to improve
Expand All @@ -240,7 +227,6 @@ function update_state(method::Order0, fs, o::UnivariateZeroState{T}, options::Un
return nothing
end


##################################################

## Secant
Expand Down

0 comments on commit b1b84ef

Please sign in to comment.