-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor api #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor api #89
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7ccca83
Remove @show
kahaaga 9eea571
Refactor nearest neighbors methods
kahaaga 327dff7
Typos
kahaaga 6b435b2
Remove duplicate function
kahaaga 89e5b62
Reorganize docs
kahaaga 8281f50
API renaming
kahaaga 37eee1e
Switch order of docs
kahaaga 0d76704
Refactoring
kahaaga 6537561
Unnecessary capitalization
kahaaga 50aa265
Further refactoring
kahaaga 1ea12f8
Missing part of equation
kahaaga 873e7c6
Use new name
kahaaga 256b4e1
Add deprecations
kahaaga 46c86db
Add note for single-symbol encoding in docstring
kahaaga e23dbcc
Add note for single-symbol encoding in docstring
kahaaga 6110d54
Merge remote-tracking branch 'origin/refactor_api' into refactor_api
kahaaga 25fd231
Remove redundant note
kahaaga 73f0a58
Use @deprecate for genentropy
kahaaga ddeb1db
Add (preliminary) update message
Datseris bf07639
[wip] reusable docs
Datseris bb9019b
re-write intro page
Datseris 51cf580
improve entropy wording
Datseris 48c5ba2
Complete re-organization of source code folders
Datseris b7b2758
correct includes state
Datseris fd97c39
finish first draft of docs new way (many TODOs left_)
Datseris c9084cf
Fix wavelet entropy docs
Datseris ed6f2ac
add docstrings to convenience calls
Datseris c5acd2f
final touches
Datseris 47189f0
add documentation build phase
Datseris a9e6512
Add power spectrum probability estimator (#94)
Datseris 8b4dd4b
even better test reorganization
Datseris 608a804
add one more depth level
Datseris aace207
WIP: reviewing new api (#95)
kahaaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
""" | ||
genentropy(p::Probabilities; q = 1.0, base = MathConstants.e) | ||
|
||
Compute the generalized order-`q` entropy of some probabilities | ||
returned by the [`probabilities`](@ref) function. Alternatively, compute entropy | ||
from pre-computed `Probabilities`. | ||
|
||
genentropy(x::Array_or_Dataset, est; q = 1.0, base) | ||
|
||
A convenience syntax, which calls first `probabilities(x, est)` | ||
and then calculates the entropy of the result (and thus `est` can be a | ||
`ProbabilitiesEstimator` or simply `ε::Real`). | ||
|
||
## Description | ||
|
||
Let ``p`` be an array of probabilities (summing to 1). Then the generalized (Rényi) entropy is | ||
|
||
```math | ||
H_q(p) = \\frac{1}{1-q} \\log \\left(\\sum_i p[i]^q\\right) | ||
``` | ||
|
||
and generalizes other known entropies, | ||
like e.g. the information entropy | ||
(``q = 1``, see [^Shannon1948]), the maximum entropy (``q=0``, | ||
also known as Hartley entropy), or the correlation entropy | ||
(``q = 2``, also known as collision entropy). | ||
|
||
[^Rényi1960]: A. Rényi, *Proceedings of the fourth Berkeley Symposium on Mathematics, | ||
Statistics and Probability*, pp 547 (1960) | ||
[^Shannon1948]: C. E. Shannon, Bell Systems Technical Journal **27**, pp 379 (1948) | ||
""" | ||
function genentropy end | ||
|
||
function genentropy(prob::Probabilities; q = 1.0, α = nothing, base = MathConstants.e) | ||
Base.depwarn("`genentropy(x)` is deprecated, use `renyientropy(x)` instead.", :genentropy) | ||
|
||
if α ≠ nothing | ||
@warn "Keyword `α` is deprecated in favor of `q`." | ||
q = α | ||
end | ||
q < 0 && throw(ArgumentError("Order of generalized entropy must be ≥ 0.")) | ||
haszero = any(iszero, prob) | ||
p = if haszero | ||
i0 = findall(iszero, prob.p) | ||
# We copy because if someone initialized Probabilities with 0s, I would guess | ||
# they would want to index the zeros as well. Not so costly anyways. | ||
deleteat!(copy(prob.p), i0) | ||
else | ||
prob.p | ||
end | ||
|
||
if q ≈ 0 | ||
return log(base, length(p)) #Hartley entropy, max-entropy | ||
elseif q ≈ 1 | ||
return -sum( x*log(base, x) for x in p ) #Shannon entropy | ||
elseif isinf(q) | ||
return -log(base, maximum(p)) #Min entropy | ||
else | ||
return (1/(1-q))*log(base, sum(x^q for x in p) ) #Renyi q entropy | ||
end | ||
end | ||
|
||
function genentropy(::AbstractArray{<:Real}) | ||
Base.depwarn("`genentropy(x)` is deprecated, use `renyientropy(x)` instead.", :genentropy) | ||
error("For single-argument input, do `genentropy(Probabilities(x))` instead.") | ||
end | ||
|
||
function genentropy(x::Array_or_Dataset, est; q = 1.0, α = nothing, base = MathConstants.e) | ||
Base.depwarn("`genentropy(x, est)` is deprecated, use `renyientropy(x, est)` instead.", :genentropy) | ||
if α ≠ nothing | ||
@warn "Keyword `α` is deprecated in favor of `q`." | ||
q = α | ||
end | ||
p = probabilities(x, est) | ||
genentropy(p; q = q, base = base) | ||
end | ||
|
||
""" | ||
genentropy!(p, x, est::ProbabilitiesEstimator; q = 1.0, base = MathConstants.e) | ||
Similarly with `probabilities!` this is an in-place version of `genentropy` that allows | ||
pre-allocation of temporarily used containers. | ||
Only works for certain estimators. See for example [`SymbolicPermutation`](@ref). | ||
""" | ||
function genentropy!(p, x, est; q = 1.0, α = nothing, base = MathConstants.e) | ||
Base.depwarn("`genentropy(p, x, est)` is deprecated, use `renyientropy(p, x, est)` instead.", :genentropy) | ||
|
||
if α ≠ nothing | ||
@warn "Keyword `α` is deprecated in favor of `q`." | ||
q = α | ||
end | ||
probabilities!(p, x, est) | ||
genentropy(p; q = q, base = base) | ||
end |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function symbolize(x::AbstractDataset{m, T}, est::PermutationProbabilityEstimator) where {m, T} | ||
Base.depwarn("`symbolize(x, est::$P)` is deprecated, use `symbolize(x, scheme::OrdinalPattern)` instead.", :symbolize) | ||
|
||
m >= 2 || error("Data must be at least 2-dimensional to symbolize. If data is a univariate time series, embed it using `genembed` first.") | ||
s = zeros(Int, length(x)) | ||
symbolize!(s, x, est) | ||
return s | ||
end | ||
|
||
function symbolize(x::AbstractVector{T}, est::P) where {T, P <: PermutationProbabilityEstimator} | ||
Base.depwarn("`symbolize(x, est::$P)` is deprecated, use `symbolize(x, scheme::OrdinalPattern)` instead.", :symbolize) | ||
|
||
τs = tuple([est.τ*i for i = 0:est.m-1]...) | ||
x_emb = genembed(x, τs) | ||
|
||
s = zeros(Int, length(x_emb)) | ||
symbolize!(s, x_emb, est) | ||
return s | ||
end | ||
|
||
function symbolize!(s::AbstractVector{Int}, x::AbstractDataset{m, T}, est::SymbolicPermutation) where {m, T} | ||
Base.depwarn("`symbolize!(s, x, est::SymbolicPermutation)` is deprecated, use `symbolize!(s, x, scheme::OrdinalPattern)` instead.", :symbolize) | ||
|
||
@assert length(s) == length(x) | ||
#= | ||
Loop over embedding vectors `E[i]`, find the indices `p_i` that sort each `E[i]`, | ||
then get the corresponding integers `k_i` that generated the | ||
permutations `p_i`. Those integers are the symbols for the embedding vectors | ||
`E[i]`. | ||
=# | ||
sp = zeros(Int, m) # pre-allocate a single symbol vector that can be overwritten. | ||
fill_symbolvector!(s, x, sp, m, lt = est.lt) | ||
|
||
return s | ||
end | ||
|
||
function symbolize!(s::AbstractVector{Int}, x::AbstractVector{T}, est::SymbolicPermutation) where T | ||
Base.depwarn("`symbolize!(s, x, est::SymbolicPermutation)` is deprecated, use `symbolize!(s, x, scheme::OrdinalPattern)` instead.", :symbolize) | ||
τs = tuple([est.τ*i for i = 0:est.m-1]...) | ||
x_emb = genembed(x, τs) | ||
symbolize!(s, x_emb, est) | ||
end |
This file contains hidden or 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 +1,5 @@ | ||
@deprecate TimeScaleMODWT WaveletOverlap | ||
include("deprecated/genentropy.jl") | ||
include("deprecated/symbolization.jl") | ||
|
||
@deprecate TimeScaleMODWT WaveletOverlap | ||
@deprecate genentropy renyientropy |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.