Skip to content

Commit

Permalink
Merge 11ef5d3 into 0c4d0a5
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon committed Feb 27, 2019
2 parents 0c4d0a5 + 11ef5d3 commit 642099d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
87 changes: 44 additions & 43 deletions src/StatsBase.jl
@@ -1,27 +1,28 @@
__precompile__()

module StatsBase
import Base: length, isempty, eltype, values, sum, show, maximum, minimum, extrema
import Base.Cartesian: @nloops, @nref, @nextract
using Base: @irrational, @propagate_inbounds
import DataStructures: heapify!, heappop!, percolate_down!
using SortingAlgorithms
using Missings

using Statistics
using LinearAlgebra
using Random
using Printf
using SparseArrays
import Random: rand, rand!
import LinearAlgebra: BlasReal, BlasFloat
import Statistics: mean, mean!, var, varm, varm!, std, stdm, cov, covm,
cor, corm, cov2cor!, unscaled_covzm, quantile, sqrt!,
median, middle

import Base: length, isempty, eltype, values, sum, show, maximum, minimum, extrema
import Base.Cartesian: @nloops, @nref, @nextract
using Base: @irrational, @propagate_inbounds
import DataStructures: heapify!, heappop!, percolate_down!
using SortingAlgorithms
using Missings

using Statistics
using LinearAlgebra
using Random
using Printf
using SparseArrays
import Random: rand, rand!
import LinearAlgebra: BlasReal, BlasFloat
import Statistics: mean, mean!, var, varm, varm!, std, stdm, cov, covm,
cor, corm, cov2cor!, unscaled_covzm, quantile, sqrt!,
median, middle

## tackle compatibility issues

export
export

## weights
AbstractWeights, # abstract type to represent any weight vector
Expand Down Expand Up @@ -207,30 +208,30 @@ module StatsBase
ZScoreTransform, # the type to represent a z-score data transformation
UnitRangeTransform # the type to represent a 0-1 data transformation

# source files

include("common.jl")
include("weights.jl")
include("moments.jl")
include("scalarstats.jl")
include("robust.jl")
include("deviation.jl")
include("cov.jl")
include("counts.jl")
include("ranking.jl")
include("toeplitzsolvers.jl")
include("rankcorr.jl")
include("signalcorr.jl")
include("partialcor.jl")
include("empirical.jl")
include("hist.jl")
include("misc.jl")

include("sampling.jl")
include("statmodels.jl")

include("transformations.jl")

include("deprecates.jl")
# source files

include("common.jl")
include("weights.jl")
include("moments.jl")
include("scalarstats.jl")
include("robust.jl")
include("deviation.jl")
include("cov.jl")
include("counts.jl")
include("ranking.jl")
include("toeplitzsolvers.jl")
include("rankcorr.jl")
include("signalcorr.jl")
include("partialcor.jl")
include("empirical.jl")
include("hist.jl")
include("misc.jl")

include("sampling.jl")
include("statmodels.jl")

include("transformations.jl")

include("deprecates.jl")

end # module
3 changes: 2 additions & 1 deletion src/scalarstats.jl
Expand Up @@ -438,7 +438,8 @@ zscore(X::AbstractArray{<:Real}, dim::Int) = ((μ, σ) = mean_and_std(X, dim); z
Compute the entropy of a collection of probabilities `p`, optionally specifying a real number
`b` such that the entropy is scaled by `1/log(b)`.
"""
entropy(p) = -sum(pi -> pi * log(pi), p)
entropy(p) = -sum(pᵢ -> iszero(pᵢ) ? zero(pᵢ) : pᵢ * log(pᵢ), p)

entropy(p, b::Real) = entropy(p) / log(b)

"""
Expand Down
2 changes: 2 additions & 0 deletions test/scalarstats.jl
Expand Up @@ -119,6 +119,8 @@ it = (xᵢ for xᵢ in x)

@test entropy([0.5, 0.5],2) 1.0
@test entropy([0.2, 0.3, 0.5], 2) 1.4854752972273344
@test entropy([0.2, 0.3, 0.5], 2) 1.4854752972273344
@test entropy([1.0, 0.0]) 0.0

##### Renyi entropies
# Generate a random probability distribution
Expand Down

0 comments on commit 642099d

Please sign in to comment.