Skip to content

Commit

Permalink
minor style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscoey committed May 16, 2021
1 parent e4a02c8 commit 886b853
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 68 deletions.
8 changes: 4 additions & 4 deletions src/Cones/epinorminf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ function update_hess_aux(cone::EpiNormInf{T}) where {T <: Real}
udenj = uden[j]
invdenj = inv(cone.den[j])
if cone.is_complex
(wdre, wdim) = reim(wdenj)
(wdre, w_dim) = reim(wdenj)
cone.Hure[j] = -wdre * udenj
cone.Huim[j] = -wdim * udenj
cone.Huim[j] = -w_dim * udenj
cone.Hrere[j] = abs2(wdre) + invdenj
cone.Himim[j] = abs2(wdim) + invdenj
cone.Hreim[j] = wdre * wdim
cone.Himim[j] = abs2(w_dim) + invdenj
cone.Hreim[j] = wdre * w_dim
else
cone.Hure[j] = -wdenj * udenj
cone.Hrere[j] = abs2(wdenj) + invdenj
Expand Down
14 changes: 7 additions & 7 deletions src/Cones/epirelentropy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ function get_central_ray_epirelentropy(w_dim::Int)
return central_rays_epirelentropy[w_dim, :]
end
# use nonlinear fit for higher dimensions
rtwdim = sqrt(w_dim)
rtw_dim = sqrt(w_dim)
if w_dim <= 20
u = 1.2023 / rtwdim - 0.015
v = 0.432 / rtwdim + 1.0125
w = -0.3057 / rtwdim + 0.972
u = 1.2023 / rtw_dim - 0.015
v = 0.432 / rtw_dim + 1.0125
w = -0.3057 / rtw_dim + 0.972
else
u = 1.1513 / rtwdim - 0.0069
v = 0.4873 / rtwdim + 1.0008
w = -0.4247 / rtwdim + 0.9961
u = 1.1513 / rtw_dim - 0.0069
v = 0.4873 / rtw_dim + 1.0008
w = -0.4247 / rtw_dim + 0.9961
end
return [u, v, w]
end
Expand Down
62 changes: 31 additions & 31 deletions src/Cones/hypogeomean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mutable struct HypoGeoMean{T <: Real} <: Cone{T}
inv_hess::Symmetric{T, Matrix{T}}
hess_fact_cache

iwdim::T
iw_dim::T
wgeo::T
z::T
tempw::Vector{T}
Expand All @@ -50,19 +50,19 @@ mutable struct HypoGeoMean{T <: Real} <: Cone{T}
end

function setup_extra_data!(cone::HypoGeoMean{T}) where {T <: Real}
wdim = cone.dim - 1
cone.tempw = zeros(T, wdim)
cone.iwdim = inv(T(wdim))
w_dim = cone.dim - 1
cone.tempw = zeros(T, w_dim)
cone.iw_dim = inv(T(w_dim))
return cone
end

get_nu(cone::HypoGeoMean) = cone.dim

function set_initial_point!(arr::AbstractVector{T}, cone::HypoGeoMean{T}) where T
wdim = cone.dim - 1
c = sqrt(T(5 * wdim ^ 2 + 2 * wdim + 1))
arr[1] = -sqrt((-c + 3 * wdim + 1) / T(2 * cone.dim))
@views arr[2:end] .= (c - wdim + 1) / sqrt(cone.dim * (-2 * c + 6 * wdim + 2))
w_dim = cone.dim - 1
c = sqrt(T(5 * w_dim ^ 2 + 2 * w_dim + 1))
arr[1] = -sqrt((-c + 3 * w_dim + 1) / T(2 * cone.dim))
@views arr[2:end] .= (c - w_dim + 1) / sqrt(cone.dim * (-2 * c + 6 * w_dim + 2))
return arr
end

Expand All @@ -72,7 +72,7 @@ function update_feas(cone::HypoGeoMean{T}) where T
@views w = cone.point[2:end]

if all(>(eps(T)), w)
cone.wgeo = exp(cone.iwdim * sum(log, w))
cone.wgeo = exp(cone.iw_dim * sum(log, w))
cone.z = cone.wgeo - u
cone.is_feas = (cone.z > eps(T))
else
Expand All @@ -88,7 +88,7 @@ function is_dual_feas(cone::HypoGeoMean{T}) where T
@views w = cone.dual_point[2:end]

if u < -eps(T) && all(>(eps(T)), w)
return ((cone.dim - 1) * exp(cone.iwdim * sum(log, w)) + u > eps(T))
return ((cone.dim - 1) * exp(cone.iw_dim * sum(log, w)) + u > eps(T))
end

return false
Expand All @@ -100,7 +100,7 @@ function update_grad(cone::HypoGeoMean)
@views w = cone.point[2:end]

cone.grad[1] = inv(cone.z)
gconst = -cone.iwdim * cone.wgeo / cone.z - 1
gconst = -cone.iw_dim * cone.wgeo / cone.z - 1
@. @views cone.grad[2:end] = gconst / w

cone.grad_updated = true
Expand All @@ -114,9 +114,9 @@ function update_hess(cone::HypoGeoMean)
u = cone.point[1]
@views w = cone.point[2:end]
z = cone.z
iwdim = cone.iwdim
wgeoz = iwdim * cone.wgeo / z
wgeozm1 = wgeoz - iwdim
iw_dim = cone.iw_dim
wgeoz = iw_dim * cone.wgeo / z
wgeozm1 = wgeoz - iw_dim
constww = wgeoz * (1 + wgeozm1) + 1

H[1, 1] = abs2(cone.grad[1])
Expand Down Expand Up @@ -145,9 +145,9 @@ function hess_prod!(
u = cone.point[1]
@views w = cone.point[2:end]
z = cone.z
iwdim = cone.iwdim
wgeoz = iwdim * cone.wgeo / z
wgeozm1 = wgeoz - iwdim
iw_dim = cone.iw_dim
wgeoz = iw_dim * cone.wgeo / z
wgeozm1 = wgeoz - iw_dim
constww = wgeoz + 1

@inbounds @views for j in 1:size(arr, 2)
Expand All @@ -170,10 +170,10 @@ function update_inv_hess(cone::HypoGeoMean{T}) where T
Hi = cone.inv_hess.data
u = cone.point[1]
@views w = cone.point[2:end]
wdim = length(w)
wgeoid = cone.wgeo * cone.iwdim
denom = cone.dim * cone.wgeo - wdim * u
zd2 = wdim * cone.z / denom
w_dim = length(w)
wgeoid = cone.wgeo * cone.iw_dim
denom = cone.dim * cone.wgeo - w_dim * u
zd2 = w_dim * cone.z / denom

Hi[1, 1] = cone.wgeo * (cone.dim * wgeoid - 2 * u) + abs2(u)
@inbounds for j in eachindex(w)
Expand All @@ -199,12 +199,12 @@ function inv_hess_prod!(
) where T
u = cone.point[1]
@views w = cone.point[2:end]
wdim = length(w)
w_dim = length(w)
wgeo = cone.wgeo
wgeoid = wgeo * cone.iwdim
wgeoid = wgeo * cone.iw_dim
const1 = wgeo * (cone.dim * wgeoid - 2 * u) + abs2(u)
denom = cone.dim * wgeo - wdim * u
zd2 = wdim * cone.z / denom
denom = cone.dim * wgeo - w_dim * u
zd2 = w_dim * cone.z / denom

@inbounds @views for j in 1:size(prod, 2)
arr_u = arr[1, j]
Expand All @@ -228,23 +228,23 @@ function dder3(cone::HypoGeoMean, dir::AbstractVector)
dder3 = cone.dder3
z = cone.z
wdw = cone.tempw
iwdim = cone.iwdim
iw_dim = cone.iw_dim

piz = cone.wgeo / z
@. wdw = w_dir / w
udz = u_dir / z
uz = u / z
const6 = -2 * udz * piz
awdw = iwdim * sum(wdw)
awdw = iw_dim * sum(wdw)
const1 = awdw * piz * (2 * piz - 1)
awdw2 = iwdim * sum(abs2, wdw)
awdw2 = iw_dim * sum(abs2, wdw)
dder3[1] = (abs2(udz) + const6 * awdw + (const1 * awdw + piz * awdw2) / 2) / -z

const2 = piz * (1 - piz)
const3 = iwdim * ((const6 * udz + const2 * awdw2 -
const3 = iw_dim * ((const6 * udz + const2 * awdw2 -
uz * const1 * awdw) / -2 - udz * const1)
const4 = -iwdim * (const2 * awdw + udz * piz)
const5 = iwdim * (piz + iwdim * (const2 + piz * uz)) + 1
const4 = -iw_dim * (const2 * awdw + udz * piz)
const5 = iw_dim * (piz + iw_dim * (const2 + piz * uz)) + 1
@inbounds for (j, wdwj) in enumerate(wdw)
dder3[j + 1] = ((const4 + const5 * wdwj) * wdwj + const3) / w[j]
end
Expand Down
6 changes: 3 additions & 3 deletions src/Cones/hypoperlog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ reset_data(cone::HypoPerLog) = (cone.feas_updated = cone.grad_updated =
cone.inv_hess_aux_updated = cone.hess_fact_updated = false)

function setup_extra_data!(cone::HypoPerLog{T}) where {T <: Real}
# wdim = cone.dim - 2
# cone.wivzi = zeros(T, wdim)
# cone.tempw = zeros(T, wdim)
# w_dim = cone.dim - 2
# cone.wivzi = zeros(T, w_dim)
# cone.tempw = zeros(T, w_dim)


# don't alloc here
Expand Down
43 changes: 21 additions & 22 deletions src/Cones/hypopowermean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,12 @@ function dder3(cone::HypoPowerMean, dir::AbstractVector)
u_dir = dir[1]
@views w_dir = dir[2:end]
dder3 = cone.dder3
@views wdder3 = dder3[2:end]
pi = cone.wprod # TODO rename
@views w_dder3 = dder3[2:end]
z = cone.z
alpha = cone.alpha
wdw = cone.tempw

piz = pi / z
piz = cone.wprod / z
@. wdw = w_dir / w
udz = u_dir / z
const6 = -2 * udz * piz
Expand All @@ -202,39 +201,39 @@ function dder3(cone::HypoPowerMean, dir::AbstractVector)
const4 = const2 * awdw + udz * piz
const5 = const2 + piz * u / z

@. wdder3 = piz + const5 * alpha
wdder3 .*= alpha
wdder3 .+= 1
wdder3 .*= wdw
@. wdder3 -= const4 * alpha
wdder3 .*= wdw
@. wdder3 += const3 * alpha
wdder3 ./= w
@. w_dder3 = piz + const5 * alpha
w_dder3 .*= alpha
w_dder3 .+= 1
w_dder3 .*= wdw
@. w_dder3 -= const4 * alpha
w_dder3 .*= wdw
@. w_dder3 += const3 * alpha
w_dder3 ./= w

return dder3
end

# see analysis in
# https://github.com/lkapelevich/HypatiaSupplements.jl/tree/master/centralpoints
function get_central_ray_hypopowermean(alpha::Vector{<:Real})
wdim = length(alpha)
w_dim = length(alpha)
# predict each w_i given alpha_i and n
w = zeros(wdim)
if wdim == 1
w = zeros(w_dim)
if w_dim == 1
w .= 1.306563
elseif wdim == 2
elseif w_dim == 2
@. w = 1.0049885 + 0.2986276 * alpha
elseif wdim <= 5
@. w = 1.0040142949 - 0.0004885108 * wdim + 0.3016645951 * alpha
elseif wdim <= 20
@. w = 1.001168 - 4.547017e-05 * wdim + 3.032880e-01 * alpha
elseif wdim <= 100
@. w = 1.000069 - 5.469926e-07 * wdim + 3.074084e-01 * alpha
elseif w_dim <= 5
@. w = 1.0040142949 - 0.0004885108 * w_dim + 0.3016645951 * alpha
elseif w_dim <= 20
@. w = 1.001168 - 4.547017e-05 * w_dim + 3.032880e-01 * alpha
elseif w_dim <= 100
@. w = 1.000069 - 5.469926e-07 * w_dim + 3.074084e-01 * alpha
else
@. w = 1 + 3.086535e-01 * alpha
end
# get u in closed form from w
p = exp(sum(alpha[i] * log(w[i]) for i in eachindex(alpha)))
u = sum(p .- alpha .* p ./ (abs2.(w) .- 1)) / wdim
u = sum(p .- alpha .* p ./ (abs2.(w) .- 1)) / w_dim
return [u, w]
end
2 changes: 1 addition & 1 deletion src/Solvers/steppers/predorcent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
function load(stepper::PredOrCentStepper{T}, solver::Solver{T}) where {T <: Real}
model = solver.model
if stepper.use_adjustment && !any(Cones.use_adjustment, model.cones)
# model has no cones that use adjustment
# model has no cones that use third order deriv
stepper.use_adjustment = false
end

Expand Down

0 comments on commit 886b853

Please sign in to comment.