Skip to content

Commit

Permalink
move stuff from ExpFamily.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdmitri committed Oct 10, 2023
1 parent 93dc0ef commit 1f5b041
Show file tree
Hide file tree
Showing 15 changed files with 1,518 additions and 10 deletions.
27 changes: 23 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
name = "BayesBase"
uuid = "b4ee3484-f114-42fe-b91c-797d54a0c67e"
authors = ["Bagaev Dmitry <bvdmitri@gmail.com> and contributors"]
version = "1.0.0-DEV"
authors = ["Bagaev Dmitry <d.v.bagaev@tue.nl> and contributors"]
version = "1.0.0"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TinyHugeNumbers = "783c9a47-75a3-44ac-a16b-f1ab7b3acf04"

[compat]
julia = "1"
Distributions = "0.25"
Random = "1.9"
Statistics = "1.9"
StatsAPI = "1.7"
StatsBase = "0.34"
TinyHugeNumbers = "1.0"
julia = "1.9"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Aqua", "CpuId", "Test", "ReTestItems", "LinearAlgebra", "StableRNGs"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
[![Coverage](https://codecov.io/gh/biaslab/BayesBase.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/biaslab/BayesBase.jl)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
[![PkgEval](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/B/BayesBase.svg)](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/B/BayesBase.html)

`BayesBase` is a package that serves as an umbrella, defining, exporting, and re-exporting methods essential for Bayesian statistics.
The `BayesBase` depends on [`Distributions`](https://github.com/JuliaStats/Distributions.jl), [`StatsBase`](https://github.com/JuliaStats/StatsBase.jl) and [`StatsAPI`](https://github.com/JuliaStats/StatsAPI.jl).

Related projects:

- [`ExponentialFamily`](https://github.com/biaslab/ExponentialFamily.jl)
7 changes: 7 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Documentation for [BayesBase](https://github.com/biaslab/BayesBase.jl).
```@index
```

# List of exported functions

```@docs
StatsAPI.params
Statistics.mean
```

```@autodocs
Modules = [BayesBase]
```
69 changes: 68 additions & 1 deletion src/BayesBase.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
module BayesBase

# Write your package code here.
using TinyHugeNumbers

using StatsAPI, StatsBase, Statistics, Distributions, Random

using StatsAPI: params

export params

using Statistics: mean, median, std, var, cov

export mean, median, std, var, cov

using StatsBase: mode, entropy

export mode, entropy

using Distributions:
failprob,
succprob,
insupport,
shape,
scale,
rate,
invcov,
pdf,
logpdf,
logdetcov,
VariateForm,
ValueSupport,
Distribution,
Univariate,
Multivariate,
Matrixvariate,
variate_form,
value_support

export failprob,
succprob,
insupport,
shape,
scale,
rate,
invcov,
pdf,
logpdf,
logdetcov,
VariateForm,
ValueSupport,
Distribution,
Univariate,
Multivariate,
Matrixvariate,
variate_form,
value_support

using Base: precision, eltype, convert, length, isapprox

export precision, eltype, convert, length, isapprox

using Random: rand, rand!

export rand, rand!

include("statsfuns.jl")
include("promotion.jl")
include("prod.jl")

include("densities/factorizedjoint.jl")

end
42 changes: 42 additions & 0 deletions src/densities/factorizedjoint.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export FactorizedJoint

"""
FactorizedJoint
`FactorizedJoint` represents a joint distribution of independent random variables.
Use `component()` function or square-brackets indexing to access the marginal distribution for individual variables.
Use `components()` function to get a tuple of multipliers.
"""
struct FactorizedJoint{T}
multipliers::T
end

BayesBase.components(joint::FactorizedJoint) = joint.multipliers

Base.@propagate_inbounds function BayesBase.component(joint::FactorizedJoint, i::Int)
return getindex(joint, i)
end
Base.@propagate_inbounds function Base.getindex(joint::FactorizedJoint, i::Int)
return getindex(components(joint), i)
end

BayesBase.length(joint::FactorizedJoint) = length(joint.multipliers)

function BayesBase.isapprox(x::FactorizedJoint, y::FactorizedJoint; kwargs...)
return length(x) === length(y) && all(
tuple -> isapprox(tuple[1], tuple[2]; kwargs...),
zip(components(x), components(y)),
)
end

BayesBase.entropy(joint::FactorizedJoint) = mapreduce(entropy, +, components(joint))

function BayesBase.paramfloattype(joint::FactorizedJoint)
return BayesBase.paramfloattype(BayesBase.components(joint))
end

function BayesBase.convert_paramfloattype(::Type{T}, joint::FactorizedJoint) where {T}
return FactorizedJoint(
map(e -> BayesBase.convert_paramfloattype(T, joint), BayesBase.components(joint))
)
end
Loading

0 comments on commit 1f5b041

Please sign in to comment.