Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ authors:
repository-code: >-
https://github.com/StructuralEquationModels/StructuralEquationModels.jl
license: MIT
doi: 10.5281/zenodo.6719626
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# <img src="https://github.com/StructuralEquationModels/Data/blob/main/images/logo.png" width = 100> StructuralEquationModels.jl

| **Documentation** | **Build Status** |
|:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:|
| [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://structuralequationmodels.github.io/StructuralEquationModels.jl/) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://structuralequationmodels.github.io/StructuralEquationModels.jl/dev/) | [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![Github Action CI](https://github.com/StructuralEquationModels/StructuralEquationModels.jl/workflows/CI_extended/badge.svg)](https://github.com/StructuralEquationModels/StructuralEquationModels.jl/actions/) [![codecov](https://codecov.io/gh/StructuralEquationModels/StructuralEquationModels.jl/branch/main/graph/badge.svg?token=P2kjzpvM4V)](https://codecov.io/gh/StructuralEquationModels/StructuralEquationModels.jl) |
| **Documentation** | **Build Status** | Citation |
|:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:|
| [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://structuralequationmodels.github.io/StructuralEquationModels.jl/) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://structuralequationmodels.github.io/StructuralEquationModels.jl/dev/) | [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![Github Action CI](https://github.com/StructuralEquationModels/StructuralEquationModels.jl/workflows/CI_extended/badge.svg)](https://github.com/StructuralEquationModels/StructuralEquationModels.jl/actions/) [![codecov](https://codecov.io/gh/StructuralEquationModels/StructuralEquationModels.jl/branch/main/graph/badge.svg?token=P2kjzpvM4V)](https://codecov.io/gh/StructuralEquationModels/StructuralEquationModels.jl) | [![DOI](https://zenodo.org/badge/228649704.svg)](https://zenodo.org/badge/latestdoi/228649704) |


This is a package for Structural Equation Modeling.
It is still *in development*.
Expand Down
61 changes: 61 additions & 0 deletions src/loss/other/hellinger.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
############################################################################################
### Types
############################################################################################
"""
Squared Hellinger distance loss.

# Constructor

Hellinger()

# Examples
```julia
my_hellinger = Hellinger()
```

# Extended help
## Implementation
Subtype of `SemLossFunction`.
"""

struct Hellinger <: SemLossFunction end

using LinearAlgebra
import StructuralEquationModels: Σ, μ, obs_cov, obs_mean, objective!

function objective!(hell::Hellinger, parameters, model::AbstractSem)

# get model-implied covariance matrices
Σᵢ = Σ(imply(model))

# get observed covariance matrix
Σₒ = obs_cov(observed(model))

# get model-implued mean vector
μᵢ = μ(imply(model))

# get observed mean vector
μₒ = obs_mean(observed(model))

Sig = (Σᵢ + Σₒ)/2



# compute the objective
if isposdef(Symmetric(Σᵢ)) # is the model implied covariance matrix positive definite?

loss = ( det(Σᵢ)^(1/4) * det(Σₒ)^(1/4) ) / sqrt(det(Sig))

if !isnothing(μᵢ) & !isnothing(μₒ)
μd = (μᵢ-μₒ)
loss = loss * exp(0.125 * (μd)*inv(Sig)*(μd)')
end

loss = 1 - loss

return loss

else
return Inf
end
end