Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check formatting
on:
push:
branches:
- 'master'
- 'release-'
tags:
- '*'
pull_request:
jobs:
runic:
name: Runic
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- uses: julia-actions/cache@v2
- uses: fredrikekre/runic-action@v1
with:
version: '1'
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

*StatsBase.jl* is a Julia package that provides basic support for statistics. Particularly, it implements a variety of statistics-related functions, such as scalar statistics, high-order moment computation, counting, ranking, covariances, sampling, and empirical density estimation.

- **Build & Testing Status:**
- **Build, Testing Status & Code Style:**
[![CI](https://github.com/JuliaStats/StatsBase.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaStats/StatsBase.jl/actions/workflows/ci.yml)
[![codecov](https://codecov.io/github/JuliaStats/StatsBase.jl/graph/badge.svg?token=XhM6RcXdrB)](https://codecov.io/github/JuliaStats/StatsBase.jl)
[![code style: runic](https://img.shields.io/badge/code_style-%E1%9A%B1%E1%9A%A2%E1%9A%BE%E1%9B%81%E1%9A%B2-black)](https://github.com/fredrikekre/Runic.jl)

- **Documentation**: [![][docs-stable-img]][docs-stable-url] [![][docs-latest-img]][docs-latest-url]

Expand Down
34 changes: 18 additions & 16 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ makedocs(
sitename = "StatsBase.jl",
modules = [StatsBase, StatsAPI],
format = Documenter.HTML(assets = ["assets/favicon.ico"]),
pages = ["index.md",
"weights.md",
"scalarstats.md",
"robust.md",
"deviation.md",
"cov.md",
"counts.md",
"ranking.md",
"sampling.md",
"empirical.md",
"signalcorr.md",
"multivariate.md",
"misc.md",
"statmodels.md",
"transformations.md"],
checkdocs=:exports
pages = [
"index.md",
"weights.md",
"scalarstats.md",
"robust.md",
"deviation.md",
"cov.md",
"counts.md",
"ranking.md",
"sampling.md",
"empirical.md",
"signalcorr.md",
"multivariate.md",
"misc.md",
"statmodels.md",
"transformations.md",
],
checkdocs = :exports
)

deploydocs(
Expand Down
54 changes: 29 additions & 25 deletions perf/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ mutable struct Xmultinom <: WithRep end
tsample!(s::Xmultinom, a, x) = xmultinom_sample!(a, x)

mutable struct Sample_WRep <: WithRep end
tsample!(s::Sample_WRep, a, x) = sample!(a, x; replace=true, ordered=false)
tsample!(s::Sample_WRep, a, x) = sample!(a, x; replace = true, ordered = false)

mutable struct Sample_WRep_Ord <: WithRep end
tsample!(s::Sample_WRep_Ord, a, x) = sample!(a, x; replace=true, ordered=true)
tsample!(s::Sample_WRep_Ord, a, x) = sample!(a, x; replace = true, ordered = true)

mutable struct Knuths <: NoRep end
tsample!(s::Knuths, a, x) = knuths_sample!(a, x)
Expand All @@ -46,22 +46,22 @@ mutable struct Seq_D <: NoRep end
tsample!(s::Seq_D, a, x) = seqsample_d!(a, x)

mutable struct Sample_NoRep <: NoRep end
tsample!(s::Sample_NoRep, a, x) = sample!(a, x; replace=false, ordered=false)
tsample!(s::Sample_NoRep, a, x) = sample!(a, x; replace = false, ordered = false)

mutable struct Sample_NoRep_Ord <: NoRep end
tsample!(s::Sample_NoRep_Ord, a, x) = sample!(a, x; replace=false, ordered=true)
tsample!(s::Sample_NoRep_Ord, a, x) = sample!(a, x; replace = false, ordered = true)


# config is in the form of (n, k)

Base.string(p::SampleProc{Alg}) where {Alg} = lowercase(string(Alg))

Base.length(p::SampleProc, cfg::Tuple{Int,Int}) = cfg[2]
Base.isvalid(p::SampleProc{<:WithRep}, cfg::Tuple{Int,Int}) = ((n, k) = cfg; n >= 1 && k >= 1)
Base.isvalid(p::SampleProc{<:NoRep}, cfg::Tuple{Int,Int}) = ((n, k) = cfg; n >= k >= 1)
Base.length(p::SampleProc, cfg::Tuple{Int, Int}) = cfg[2]
Base.isvalid(p::SampleProc{<:WithRep}, cfg::Tuple{Int, Int}) = ((n, k) = cfg; n >= 1 && k >= 1)
Base.isvalid(p::SampleProc{<:NoRep}, cfg::Tuple{Int, Int}) = ((n, k) = cfg; n >= k >= 1)

Base.start(p::SampleProc, cfg::Tuple{Int,Int}) = Vector{Int}(cfg[2])
Base.run(p::SampleProc{Alg}, cfg::Tuple{Int,Int}, s::Vector{Int}) where {Alg} = tsample!(Alg(), 1:cfg[1], s)
Base.start(p::SampleProc, cfg::Tuple{Int, Int}) = Vector{Int}(cfg[2])
Base.run(p::SampleProc{Alg}, cfg::Tuple{Int, Int}, s::Vector{Int}) where {Alg} = tsample!(Alg(), 1:cfg[1], s)
Base.done(p::SampleProc, cfg, s) = nothing


Expand All @@ -72,26 +72,30 @@ const ks = 2 .^ [1:16]

## with replacement

const procs1 = Proc[ SampleProc{Direct}(),
SampleProc{Sample_WRep}(),
SampleProc{Xmultinom}(),
SampleProc{Sample_WRep_Ord}() ]
const procs1 = Proc[
SampleProc{Direct}(),
SampleProc{Sample_WRep}(),
SampleProc{Xmultinom}(),
SampleProc{Sample_WRep_Ord}(),
]

const cfgs1 = vec([(n, k) for k in ks, n in ns])

rtable1 = run(procs1, cfgs1; duration=0.2)
rtable1 = run(procs1, cfgs1; duration = 0.2)
println()

## without replacement

const procs2 = Proc[ SampleProc{Knuths}(),
SampleProc{Fisher_Yates}(),
SampleProc{Self_Avoid}(),
SampleProc{Sample_NoRep}(),
SampleProc{Seq_A}(),
SampleProc{Seq_C}(),
SampleProc{Seq_D}(),
SampleProc{Sample_NoRep_Ord}() ]
const procs2 = Proc[
SampleProc{Knuths}(),
SampleProc{Fisher_Yates}(),
SampleProc{Self_Avoid}(),
SampleProc{Sample_NoRep}(),
SampleProc{Seq_A}(),
SampleProc{Seq_C}(),
SampleProc{Seq_D}(),
SampleProc{Sample_NoRep_Ord}(),
]

const cfgs2 = (Int, Int)[]
for n in 5 * (2 .^ [0:11]), k in 2 .^ [1:16]
Expand All @@ -100,17 +104,17 @@ for n in 5 * (2 .^ [0:11]), k in 2 .^ [1:16]
end
end

rtable2 = run(procs2, cfgs2; duration=0.2)
rtable2 = run(procs2, cfgs2; duration = 0.2)
println()

## show results

println("Sampling With Replacement")
println("===================================")
show(rtable1; unit=:mps, cfghead="(n, k)")
show(rtable1; unit = :mps, cfghead = "(n, k)")
println()

println("Sampling Without Replacement")
println("===================================")
show(rtable2; unit=:mps, cfghead="(n, k)")
show(rtable2; unit = :mps, cfghead = "(n, k)")
println()
38 changes: 19 additions & 19 deletions perf/wsampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ mutable struct Direct_S <: WithRep end
tsample!(s::Direct_S, wv, x) = sort!(direct_sample!(1:length(wv), wv, x))

mutable struct Sample_WRep <: WithRep end
tsample!(s::Sample_WRep, wv, x) = sample!(1:length(wv), wv, x; ordered=false)
tsample!(s::Sample_WRep, wv, x) = sample!(1:length(wv), wv, x; ordered = false)

mutable struct Sample_WRep_Ord <: WithRep end
tsample!(s::Sample_WRep_Ord, wv, x) = sample!(1:length(wv), wv, x; ordered=true)
tsample!(s::Sample_WRep_Ord, wv, x) = sample!(1:length(wv), wv, x; ordered = true)


# config is in the form of (n, k)

Base.string(p::WSampleProc{Alg}) where {Alg} = lowercase(string(Alg))

Base.length(p::WSampleProc, cfg::Tuple{Int,Int}) = cfg[2]
Base.isvalid(p::WSampleProc{<:WithRep}, cfg::Tuple{Int,Int}) = ((n, k) = cfg; n >= 1 && k >= 1)
Base.isvalid(p::WSampleProc{<:NoRep}, cfg::Tuple{Int,Int}) = ((n, k) = cfg; n >= k >= 1)
Base.length(p::WSampleProc, cfg::Tuple{Int, Int}) = cfg[2]
Base.isvalid(p::WSampleProc{<:WithRep}, cfg::Tuple{Int, Int}) = ((n, k) = cfg; n >= 1 && k >= 1)
Base.isvalid(p::WSampleProc{<:NoRep}, cfg::Tuple{Int, Int}) = ((n, k) = cfg; n >= k >= 1)

function Base.start(p::WSampleProc, cfg::Tuple{Int,Int})
function Base.start(p::WSampleProc, cfg::Tuple{Int, Int})
n, k = cfg
x = Vector{Int}(k)
w = weights(fill(1.0/n, n))
w = weights(fill(1.0 / n, n))
return (w, x)
end

Base.run(p::WSampleProc{Alg}, cfg::Tuple{Int,Int}, s) where {Alg} = tsample!(Alg(), s[1], s[2])
Base.run(p::WSampleProc{Alg}, cfg::Tuple{Int, Int}, s) where {Alg} = tsample!(Alg(), s[1], s[2])
Base.done(p::WSampleProc, cfg, s) = nothing


Expand All @@ -60,25 +60,25 @@ const ks = 2 .^ [1:16]

## with replacement

const procs1 = Proc[ WSampleProc{Direct}(),
WSampleProc{Alias}(),
WSampleProc{Xmultinom_S}(),
WSampleProc{Sample_WRep}(),
WSampleProc{Xmultinom}(),
WSampleProc{Direct_S}(),
WSampleProc{Sample_WRep_Ord}() ]
const procs1 = Proc[
WSampleProc{Direct}(),
WSampleProc{Alias}(),
WSampleProc{Xmultinom_S}(),
WSampleProc{Sample_WRep}(),
WSampleProc{Xmultinom}(),
WSampleProc{Direct_S}(),
WSampleProc{Sample_WRep_Ord}(),
]

const cfgs1 = vec([(n, k) for k in ks, n in ns])

rtable1 = run(procs1, cfgs1; duration=0.2)
rtable1 = run(procs1, cfgs1; duration = 0.2)
println()


## show results

println("Sampling With Replacement")
println("===================================")
show(rtable1; unit=:mps, cfghead="(n, k)")
show(rtable1; unit = :mps, cfghead = "(n, k)")
println()


Loading