-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `ScaledMeasure` is now `WeightedMeasure` to avoid confusion with scale parameters - Added an `Exp` constructor for lazy exponentiation - Poisson and Binomial distributions - Added `ForArray` and `ForGenerator` type aliases - `PowerMeasure` is now in terms of `ProductMeasure`, to avoid some performance hits due to compiler limitations - Added `@half` macro to build measures like `HalfNormal` and `HalfCauchy` - Added some tests
- Loading branch information
Showing
19 changed files
with
329 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
name = "MeasureTheory" | ||
uuid = "eadaa1a4-d27c-401d-8699-e962e1bbc33b" | ||
authors = ["Chad Scherrer <[email protected]> and contributors"] | ||
version = "0.2.3" | ||
version = "0.3.0" | ||
|
||
[deps] | ||
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" | ||
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4" | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c" | ||
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" | ||
InfiniteArrays = "4858937d-0d70-526a-a4dd-2d5cb5dd786c" | ||
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" | ||
KeywordDispatch = "5888135b-5456-5c80-a1b6-c91ef8180460" | ||
|
@@ -26,18 +25,17 @@ StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" | |
StrideArrays = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b" | ||
|
||
[compat] | ||
ArrayInterface = "2" | ||
ArrayInterface = "2,3" | ||
Bijectors = "0.8" | ||
Distributions = "0.23, 0.24" | ||
DistributionsAD = "0.6" | ||
FillArrays = "0.11" | ||
InfiniteArrays = "0.9" | ||
IntervalSets = "0.5" | ||
KeywordDispatch = "0.3" | ||
LazyArrays = "0.20" | ||
MLStyle = "0.4" | ||
MacroTools = "0.5" | ||
MappedArrays = "0.3" | ||
MLStyle = "0.4" | ||
NamedTupleTools = "0.13" | ||
NestedTuples = "0.1" | ||
SpecialFunctions = "0.10, 1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
import Base | ||
import FillArrays | ||
|
||
""" | ||
A power measure is a product of a measure with itself. The number of elements in | ||
the product determines the dimensionality of the resulting support. | ||
# """ | ||
# A power measure is a product of a measure with itself. The number of elements in | ||
# the product determines the dimensionality of the resulting support. | ||
|
||
Note that power measures are only well-defined for integer powers. | ||
# Note that power measures are only well-defined for integer powers. | ||
|
||
The nth power of a measure μ can be written μ^x. | ||
""" | ||
PowerMeasure{M,N,D} = ProductMeasure{Fill{M,N,D}} | ||
# The nth power of a measure μ can be written μ^x. | ||
# """ | ||
# PowerMeasure{M,N,D} = ProductMeasure{Fill{M,N,D}} | ||
|
||
function Base.show(io::IO, μ::PowerMeasure) | ||
io = IOContext(io, :compact => true) | ||
print(io, μ.data.value, " ^ ", size(μ.data)) | ||
end | ||
# function Base.show(io::IO, μ::PowerMeasure) | ||
# io = IOContext(io, :compact => true) | ||
# print(io, μ.data.value, " ^ ", size(μ.data)) | ||
# end | ||
|
||
function Base.show_unquoted(io::IO, μ::PowerMeasure{M,N,D}, indent::Int, prec::Int) where {M,N,D} | ||
io = IOContext(io, :compact => true) | ||
if Base.operator_precedence(:^) ≤ prec | ||
print(io, "(") | ||
show(io, μ.data.value) | ||
print(io, ")") | ||
else | ||
show(io, size(μ.data)) | ||
end | ||
return nothing | ||
end | ||
# function Base.show_unquoted(io::IO, μ::PowerMeasure{M,N,D}, indent::Int, prec::Int) where {M,N,D} | ||
# io = IOContext(io, :compact => true) | ||
# if Base.operator_precedence(:^) ≤ prec | ||
# print(io, "(") | ||
# show(io, μ.data.value) | ||
# print(io, ")") | ||
# else | ||
# show(io, size(μ.data)) | ||
# end | ||
# return nothing | ||
# end | ||
|
||
Base.:^(μ::AbstractMeasure, n::Integer) = μ ^ (n,) | ||
Base.:^(μ::AbstractMeasure, n::Integer) = For(_ -> μ, 1:n) | ||
|
||
Base.:^(μ::AbstractMeasure, size::NTuple{N,I}) where {N, I <: Integer} = ProductMeasure(Fill(μ, size)) | ||
Base.:^(μ::AbstractMeasure, size::NTuple{N,I}) where {N, I <: Integer} = For(_ -> μ, CartesianIndices(size)) | ||
|
||
sampletype(d::PowerMeasure{M,N}) where {M,N} = @inbounds Array{sampletype(first(d.data)), N} | ||
# sampletype(d::PowerMeasure{M,N}) where {M,N} = @inbounds Array{sampletype(first(d.data)), N} | ||
|
||
function Base.:^(μ::WeightedMeasure, n::NTuple{N,Int}) where {N} | ||
k = prod(n) * μ.logweight | ||
return WeightedMeasure(k, μ.base^n) | ||
end | ||
|
||
basemeasure(μ::PowerMeasure) = @inbounds basemeasure(first(μ.data))^size(μ.data) | ||
# basemeasure(μ::PowerMeasure) = @inbounds basemeasure(first(μ.data))^size(μ.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
42561ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
42561ea
There was a problem hiding this comment.
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/30019
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: