Skip to content

Commit

Permalink
0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
paschermayr committed Jul 10, 2023
1 parent 635c97f commit 06cac1a
Show file tree
Hide file tree
Showing 39 changed files with 889 additions and 795 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelWrappers"
uuid = "44c54197-9f56-47cc-9960-7f2e20bfb0d6"
authors = ["Patrick Aschermayr <[email protected]>"]
version = "0.4.3"
version = "0.5.0"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand All @@ -18,7 +18,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
[compat]
ArgCheck = "2"
BaytesCore = "0.2"
Bijectors = "0.12"
Bijectors = "0.13"
ChainRulesCore = "1"
Distributions = "0.24, 0.25"
DocStringExtensions = "0.8, 0.9"
Expand Down
85 changes: 83 additions & 2 deletions src/Core/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,73 @@ struct UnflattenStrict <: UnflattenTypes end
struct UnflattenFlexible <: UnflattenTypes end

############################################################################################
include("constrain/constrain.jl")
# Abstract supertypes for flatten/unflatten parameter

"""
$(FUNCTIONNAME)(x )
Convert 'x' into a Vector.
# Examples
```julia
```
"""
function flatten end

"""
$(FUNCTIONNAME)(x )
Convert 'x' into a Vector that is AD compatible.
# Examples
```julia
```
"""
function flattenAD end

"""
$(FUNCTIONNAME)(x )
Unflatten 'x' into original shape.
# Examples
```julia
```
"""
function unflatten end

"""
$(FUNCTIONNAME)(x )
Unflatten 'x' into original shape but keep type information of 'x' for AD compatibility.
# Examples
```julia
```
"""
function unflattenAD end

############################################################################################
# Abstract supertypes for constrain/unconstrain
"""
$(TYPEDEF)
Abstract super type for parameter constraints.
"""
abstract type AbstractConstraint end

"Constrain `val` with given `constraint`"
function constrain end

"Unconstrain `val` with given `constraint`"
function unconstrain end

############################################################################################
# Default Methods for unconstrain_flatten and unflatten_constrain
function unconstrain_flatten end
function unconstrain_flattenAD end

function unflatten_constrain end
function unflattenAD_constrain end

############################################################################################
include("flatten/flatten.jl")
include("constrain/constrain.jl")

include("utility.jl")
include("checks.jl")
Expand All @@ -49,6 +114,22 @@ include("parameterinfo.jl")
export FlattenTypes,
FlattenAll,
FlattenContinuous,

UnflattenTypes,
UnflattenStrict,
UnflattenFlexible
UnflattenFlexible,

flatten,
flattenAD,

unflatten,
unflattenAD,

AbstractConstraint,
constrain,
unconstrain,

unconstrain_flatten,
unconstrain_flattenAD,
unflatten_constrain,
unflattenAD_constrain
12 changes: 0 additions & 12 deletions src/Core/constrain/constrain.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
############################################################################################
#!NOTE: These are abstract super types needed if additional constraints are added to ModelWrappers.
"""
$(TYPEDEF)
Abstract super type for parameter constraints.
"""
abstract type AbstractConstraint end

"Constrain `val` with given `constraint`"
function constrain(constraint::AbstractConstraint, val) end

"Unconstrain `val` with given `constraint`"
function unconstrain(constraint::AbstractConstraint, val) end

"Compute log(abs(determinant(jacobian(`x`)))) for given transformer to unconstrained (!) domain."
function log_abs_det_jac end

Expand Down
7 changes: 4 additions & 3 deletions src/Core/constrain/constraints/bijector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

############################################################################################
#=
2. Define functions to unconstrain(constraint, val) to unconstrained domain valᵤ, and a function constrain(constraint, valᵤ) back to val.
2.1 Define functions to unconstrain(constraint, val) to unconstrained domain valᵤ, and a function constrain(constraint, valᵤ) back to val.
Dimensions of val and valᵤ should be the same, flattening will be handled separately.
=#
function unconstrain(bijection::Bijection, val)
Expand Down Expand Up @@ -52,11 +52,12 @@ end
function _check(
_rng::Random.AbstractRNG,
b::Bijection,
val::Union{R,Array{R},AbstractArray},
val::Union{Cholesky, R,Array{R},AbstractArray},
) where {R<:Real}
return typeof( unconstrain(b, val) ) == typeof(val) ? true : false
return true
end


############################################################################################
#Export
export
Expand Down
2 changes: 1 addition & 1 deletion src/Core/constrain/constraints/constrained.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

############################################################################################
#=
2. Define functions to unconstrain(constraint, val) to unconstrained domain valᵤ, and a function constrain(constraint, valᵤ) back to val.
2.1 Define functions to unconstrain(constraint, val) to unconstrained domain valᵤ, and a function constrain(constraint, valᵤ) back to val.
Dimensions of val and valᵤ should be the same, flattening will be handled separately.
=#
function unconstrain(constrained::Constrained, val)
Expand Down
4 changes: 0 additions & 4 deletions src/Core/constrain/constraints/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
include("bijector.jl")
include("distribution.jl")

include("simplex.jl")
include("corrmatrix.jl")
include("covmatrix.jl")

include("unconstrained.jl")
include("constrained.jl")
include("fixed.jl")
Expand Down
126 changes: 0 additions & 126 deletions src/Core/constrain/constraints/corrmatrix.jl

This file was deleted.

Loading

2 comments on commit 06cac1a

@paschermayr
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/87199

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 06cac1af5c9c2aee5c7cc85f68e5577fa7921935
git push origin v0.5.0

Please sign in to comment.