Skip to content

Commit 460b580

Browse files
authored
Merge pull request #80 from JuliaAI/dev
For a 0.2.0 release
2 parents daa0879 + d95e0d8 commit 460b580

19 files changed

+338
-323
lines changed

.github/codecov.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coverage:
33
project:
44
default:
55
threshold: 0.5%
6+
removed_code_behavior: fully_covered_patch
67
patch:
78
default:
8-
target: 80%
9+
target: 80

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "monthly"

.github/workflows/CompatHelper.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ jobs:
77
CompatHelper:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Pkg.add("CompatHelper")
11-
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
12-
- name: CompatHelper.main()
10+
- name: Install CompatHelper
11+
shell: julia --color=yes {0}
12+
run: using Pkg; Pkg.add("CompatHelper")
13+
- name: Run CompatHelper
14+
shell: julia --color=yes {0}
15+
run: using CompatHelper; CompatHelper.main()
1316
env:
1417
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1518
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV}}
16-
run: julia -e 'using CompatHelper; CompatHelper.main()'

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
version:
20-
- '1.6'
20+
- '1.10'
2121
- '1' # automatically expands to the latest stable 1.x release of Julia.
2222
os:
2323
- ubuntu-latest
@@ -28,12 +28,12 @@ jobs:
2828
version: '1'
2929
arch: x86
3030
steps:
31-
- uses: actions/checkout@v2
32-
- uses: julia-actions/setup-julia@v1
31+
- uses: actions/checkout@v5
32+
- uses: julia-actions/setup-julia@v2
3333
with:
3434
version: ${{ matrix.version }}
3535
arch: ${{ matrix.arch }}
36-
- uses: actions/cache@v1
36+
- uses: julia-actions/cache@v2
3737
env:
3838
cache-name: cache-artifacts
3939
with:
@@ -48,6 +48,6 @@ jobs:
4848
env:
4949
JULIA_NUM_THREADS: 2
5050
- uses: julia-actions/julia-processcoverage@v1
51-
- uses: codecov/codecov-action@v1
51+
- uses: codecov/codecov-action@v5
5252
with:
53-
file: lcov.info
53+
files: lcov.info

Project.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name = "CategoricalDistributions"
22
uuid = "af321ab8-2d2e-40a6-b165-3d674595d28e"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "0.1.15"
4+
version = "0.2.0"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
88
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
99
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
1010
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1111
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
12+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1213
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
1314
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
1415

@@ -20,21 +21,24 @@ UnivariateFiniteDisplayExt = "UnicodePlots"
2021

2122
[compat]
2223
BenchmarkTools = "1.3.2"
23-
CategoricalArrays = "0.9, 0.10"
24+
CategoricalArrays = "1"
2425
Distributions = "0.25"
2526
Missings = "0.4, 1"
2627
OrderedCollections = "1.1"
28+
Reexport = "1.2.2"
2729
ScientificTypes = "3.0"
30+
Suppressor = "0.2.8"
2831
UnicodePlots = "2, 3"
29-
julia = "1.6"
32+
julia = "1.10"
3033

3134
[extras]
3235
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3336
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
3437
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3538
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
39+
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
3640
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3741
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
3842

3943
[targets]
40-
test = ["BenchmarkTools", "FillArrays", "Random", "StableRNGs", "Test", "UnicodePlots"]
44+
test = ["BenchmarkTools", "FillArrays", "Random", "StableRNGs", "Suppressor", "Test", "UnicodePlots"]

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Probability distributions and measures for finite sample spaces whose
44
elements are *labeled* (consist of the class pool of a
55
`CategoricalArray`).
66

7-
Designed for performance in machine learning applications. For
7+
Designed for performance in machine learning applications, where one is constructing large arrays of such distributions. For
88
example, probabilistic classifiers in
99
[MLJ](https://alan-turing-institute.github.io/MLJ.jl/dev/) typically
10-
predict the `UnivariateFiniteVector` objects defined in this package.
10+
predict the `UnivariateFiniteArray` objects defined in this package.
1111

1212
For probability distributions over integers see the
1313
[Distributions.jl](https://juliastats.org/Distributions.jl/stable/univariate/#Discrete-Distributions)
@@ -50,6 +50,16 @@ julia> mode(d)
5050
CategoricalValue{String, UInt32} "no"
5151
```
5252

53+
Of course, a `UnivariateFinite` object can be sampled:
54+
55+
```julia
56+
julia> rand(d, 5)
57+
3-element Vector{CategoricalValue{String, UInt32}}:
58+
"no"
59+
"no"
60+
"maybe"
61+
```
62+
5363
A `UnivariateFinite` distribution can also be constructed directly
5464
from a probability vector:
5565

@@ -62,11 +72,11 @@ julia> d2 = UnivariateFinite(["no", "yes"], [0.15, 0.85], pool=data)
6272
└ ┘
6373
```
6474

65-
A `UnivariateFinite` distribution tracks all classes in the pool:
75+
A `UnivariateFinite` distribution tracks all classes (levels) in the pool:
6676

6777
```julia
6878
levels(d2)
69-
3-element Vector{String}:
79+
3-element CategoricalArray{String,1,UInt32}:
7080
"maybe"
7181
"no"
7282
"yes"
@@ -106,7 +116,7 @@ probability array:
106116

107117
```julia
108118
julia> L = levels(data)
109-
3-element Vector{String}:
119+
3-element CategoricalArray{String,1,UInt32}:
110120
"maybe"
111121
"no"
112122
"yes"
@@ -121,26 +131,28 @@ julia> pdf(v, L)
121131

122132
## Measures over finite labeled sets
123133

124-
There is, in fact, no enforcement that probabilities in a
125-
`UnivariateFinite` distribution sum to one, only that they be belong
126-
to a type `T` for which `zero(T)` is defined. In particular
127-
`UnivariateFinite` objects implement arbitrary non-negative, signed,
128-
or complex measures over a finite labeled set.
134+
There is, in fact, no enforcement that probabilities in a `UnivariateFinite` distribution
135+
sum to one, only that they be belong to a type `T` for which `zero(T)` is defined. In
136+
particular `UnivariateFinite` objects implement arbitrary non-negative, signed, or complex
137+
measures over a finite labeled set.
138+
139+
However, you cannot sample using `pdf` unless "probabilities" are non-negative (their type
140+
`T` must support `>` and addition).
129141

130142
## What does this package provide?
131143

132-
- A new type `UnivariateFinite{S}` for representing probability
133-
distributions over the pool of a `CategoricalArray`, that is, over
134-
finite *labeled* sets. Here `S` is a subtype of `OrderedFactor`
135-
from ScientificTypesBase.jl, if the pool is ordered, or of
136-
`Multiclass` if the pool is unordered.
144+
- A new type `UnivariateFinite{S}` for representing probability distributions over the
145+
pool of a `CategoricalArray`, that is, over finite *labeled* sets. Here `S` is a subtype
146+
of `OrderedFactor` from
147+
[ScientificTypesBase.jl](https://github.com/JuliaAI/ScientificTypesBase.jl), if the pool
148+
is ordered, or of `Multiclass` if the pool is unordered.
137149

138150
- A new array type `UnivariateFiniteArray{S} <:
139151
AbstractArray{<:UnivariateFinite{S}}` for efficiently manipulating
140152
arrays of `UnivariateFinite` distributions.
141153

142-
- Implementations of `rand` for generating random samples of a
143-
`UnivariateFinite` distribution.
154+
- Implementations of `rand` for generating random samples of a `UnivariateFinite`
155+
distribution, in the case that "probabilities" come from an ordered field.
144156

145157
- Implementations of the `pdf`, `logpdf`, `mode` and `modes` methods of
146158
Distributions.jl, with efficient broadcasting over the new array

ext/UnivariateFiniteDisplayExt.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import UnicodePlots
88
import ScientificTypes.Finite
99

1010
# The following is a specialization of a `show` method already in /src/ for the common
11-
# case of `Real` probabilities.
11+
# case of certain numerical probabilities.
12+
13+
const Numerical = Union{AbstractFloat,Integer}
1214
function Base.show(io::IO, mime::MIME"text/plain",
13-
d::UnivariateFinite{<:Finite{K},V,R,P}) where {K,V,R,P<:Real}
15+
d::UnivariateFinite{<:Finite{K},V,R,P}) where {K,V,R,P<:Numerical}
1416
show_bars = false
1517
if K <= MAX_NUM_LEVELS_TO_SHOW_BARS &&
1618
all(>=(0), values(d.prob_given_ref))

src/CategoricalDistributions.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module CategoricalDistributions
22

3+
using Reexport
34
import Distributions
45
import ScientificTypes:
56
Finite,
@@ -10,7 +11,7 @@ import ScientificTypes:
1011
ScientificTypesBase
1112

1213
using OrderedCollections
13-
using CategoricalArrays
14+
@reexport using CategoricalArrays
1415
import Missings
1516
using Random
1617

@@ -24,6 +25,7 @@ include("scitypes.jl")
2425
include("methods.jl")
2526
include("arrays.jl")
2627
include("arithmetic.jl")
28+
include("deprecated.jl")
2729

2830
export UnivariateFinite, UnivariateFiniteArray, UnivariateFiniteVector
2931

@@ -33,9 +35,4 @@ export pdf, logpdf, support, mode, modes
3335
# re-export from ScientificTypesBase:
3436
export Multiclass, OrderedFactor
3537

36-
# for julia < 1.9
37-
if !isdefined(Base, :get_extension)
38-
include("../ext/UnivariateFiniteDisplayExt.jl")
39-
end
40-
4138
end

src/arithmetic.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ pdf_matrix(d::UnivariateFinite, L) = pdf.(d, L)
1010
pdf_matrix(d::AbstractArray{<:UnivariateFinite}, L) = pdf(d, L)
1111

1212
function +(d1::UnivariateFinite{S, V}, d2::UnivariateFinite{S, V}) where {S, V}
13-
L = classes(d1)
14-
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
13+
L = levels(d1)
14+
L == levels(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
1515
return UnivariateFinite(L, pdf_matrix(d1, L) + pdf_matrix(d2, L))
1616
end
1717
function +(d1::UnivariateFiniteArray{S, V}, d2::UnivariateFiniteArray{S, V}) where {S, V}
18-
L = classes(d1)
19-
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
18+
L = CategoricalDistributions.element_levels(d1)
19+
L == CategoricalDistributions.element_levels(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
2020
return UnivariateFinite(L, pdf_matrix(d1, L) + pdf_matrix(d2, L))
2121
end
2222

@@ -33,13 +33,13 @@ end
3333
-(d::UnivariateFiniteArray) = _minus(d, UnivariateFiniteArray)
3434

3535
function -(d1::UnivariateFinite{S, V}, d2::UnivariateFinite{S, V}) where {S, V}
36-
L = classes(d1)
37-
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
36+
L = levels(d1)
37+
L == levels(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
3838
return UnivariateFinite(L, pdf_matrix(d1, L) - pdf_matrix(d2, L))
3939
end
4040
function -(d1::UnivariateFiniteArray{S, V}, d2::UnivariateFiniteArray{S, V}) where {S, V}
41-
L = classes(d1)
42-
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
41+
L = CategoricalDistributions.element_levels(d1)
42+
L == CategoricalDistributions.element_levels(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
4343
return UnivariateFinite(L, pdf_matrix(d1, L) - pdf_matrix(d2, L))
4444
end
4545

0 commit comments

Comments
 (0)