Skip to content

Commit 169241d

Browse files
author
Alexey Stukalov
committed
non_posdef_objective()
1 parent 9051dc7 commit 169241d

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/loss/ML/FIML.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function evaluate!(objective, gradient, hessian, loss::SemFIML, params)
144144
Σ_chol = cholesky!(Symmetric(loss.imp_inv); check = false)
145145

146146
if !isposdef(Σ_chol)
147-
isnothing(objective) || (objective = non_posdef_return(params))
147+
isnothing(objective) || (objective = non_posdef_objective(params))
148148
isnothing(gradient) || fill!(gradient, 1)
149149
return objective
150150
end

src/loss/ML/ML.jl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function evaluate!(
113113
Σ_chol = cholesky!(Symmetric(Σ⁻¹); check = false)
114114
if !isposdef(Σ_chol)
115115
#@warn "∑⁻¹ is not positive definite"
116-
isnothing(objective) || (objective = non_posdef_return(par))
116+
isnothing(objective) || (objective = non_posdef_objective(par))
117117
isnothing(gradient) || fill!(gradient, 1)
118118
isnothing(hessian) || copyto!(hessian, I)
119119
return objective
@@ -180,7 +180,7 @@ function evaluate!(objective, gradient, hessian, ml::SemML, par)
180180
Σ_chol = cholesky!(Symmetric(Σ⁻¹); check = false)
181181
if !isposdef(Σ_chol)
182182
#@warn "Σ⁻¹ is not positive definite"
183-
isnothing(objective) || (objective = non_posdef_return(par))
183+
isnothing(objective) || (objective = non_posdef_objective(par))
184184
isnothing(gradient) || fill!(gradient, 1)
185185
isnothing(hessian) || copyto!(hessian, I)
186186
return objective
@@ -243,18 +243,6 @@ function evaluate!(objective, gradient, hessian, ml::SemML, par)
243243
return objective
244244
end
245245

246-
############################################################################################
247-
### additional functions
248-
############################################################################################
249-
250-
function non_posdef_return(par)
251-
if eltype(par) <: AbstractFloat
252-
return floatmax(eltype(par))
253-
else
254-
return typemax(eltype(par))
255-
end
256-
end
257-
258246
############################################################################################
259247
### recommended methods
260248
############################################################################################

src/loss/ML/abstract.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ function check_observed_vars(observed::SemObserved, implied::SemImplied)
4040
end
4141

4242
check_observed_vars(sem::SemLoss) = check_observed_vars(observed(sem), implied(sem))
43+
44+
# returned objective if the implied Σ(par) matrix is not positive definite
45+
function non_posdef_objective(par::AbstractVector)
46+
if eltype(par) <: AbstractFloat
47+
return floatmax(eltype(par))
48+
else
49+
return typemax(eltype(par))
50+
end
51+
end

0 commit comments

Comments
 (0)