diff --git a/CITATION.cff b/CITATION.cff index f4f6b37d8..4d7ceb16b 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -21,3 +21,4 @@ authors: repository-code: >- https://github.com/StructuralEquationModels/StructuralEquationModels.jl license: MIT +doi: 10.5281/zenodo.6719626 diff --git a/README.md b/README.md index a7d9e4a39..ea15eeb1e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # 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*. diff --git a/src/loss/other/hellinger.jl b/src/loss/other/hellinger.jl new file mode 100644 index 000000000..cbdd171d5 --- /dev/null +++ b/src/loss/other/hellinger.jl @@ -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 \ No newline at end of file