Skip to content

Encoding for binnings #177

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 19 commits into from
Dec 16, 2022
Merged
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
Binary file removed .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StateSpaceSets = "40b095a5-5852-4c12-98c7-d43bf788e795"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"

[compat]
Combinatorics = "1"
DelayEmbeddings = "2.5"
DelayEmbeddings = "2.6"
Distances = "0.9, 0.10"
FFTW = "1"
Neighborhood = "0.2.4"
QuadGK = "2"
Scratch = "1"
SpecialFunctions = "0.10, 1.0, 2"
StateSpaceSets = "0.1.2, 1"
StaticArrays = "0.12, 1.0"
Wavelets = "0.9"
julia = "1.5"
Binary file removed docs/.DS_Store
Binary file not shown.
9 changes: 5 additions & 4 deletions docs/src/devdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ Good practices in developing a code base apply in every Pull Request. The [Good
### Mandatory steps
1. Decide on the outcome space and how the estimator will map probabilities to outcomes.
2. Define your type and make it subtype `ProbabilitiesEstimator`.
3. Add a docstring to your type following the style of the docstrings of other estimators.
4. Implement dispatch for [`probabilities_and_outcomes`](@ref).
5. Implement dispatch for [`outcome_space`](@ref).
6. Add your type to the list in the docstring of [`ProbabilitiyEstimator`](@ref).
4. Add a docstring to your type following the style of the docstrings of other estimators.
5. If suitable, the estimator may be able to operate based on [`Encoding`]s. If so, it is preferred to implement an `Encoding` subtype and extend the methods [`encode`](@ref) and [`decode`](@ref). This will allow your probabilities estimator to be used with a larger span of entropy and complexity methods without additional effort.
6. Implement dispatch for [`probabilities_and_outcomes`](@ref) and your probabilities estimator type.
7. Implement dispatch for [`outcome_space`](@ref) and your probabilities estimator type.
8. Add your probabilities estimator type to the list in the docstring of [`ProbabilitiyEstimator`](@ref), and if you also made an encoding, add it to the [`Encoding`](@ref) docstring.

### Optional steps
You may extend any of the following functions if there are potential performance benefits in doing so:
Expand Down
14 changes: 8 additions & 6 deletions src/Entropies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ To install it, run `import Pkg; Pkg.add("Entropies")`.
"""
module Entropies

using DelayEmbeddings
using DelayEmbeddings: AbstractDataset, Dataset, dimension
export AbstractDataset, Dataset
export DelayEmbeddings
using StateSpaceSets
export Dataset, SVector
using DelayEmbeddings: embed, genembed

const Array_or_Dataset = Union{<:AbstractArray{<:Real}, <:AbstractDataset}
const Vector_or_Dataset = Union{<:AbstractVector{<:Real}, <:AbstractDataset}

# Core API types and functions
include("probabilities.jl")
include("entropy.jl")
include("encoding/outcomes.jl")
include("encodings.jl")
# Library implementations (files include other files)
include("probabilities_estimators/probabilities_estimators.jl")
include("entropies/entropies.jl")

include("encoding/all_encodings.jl")
include("deprecations.jl")


Expand Down
3 changes: 3 additions & 0 deletions src/encoding/all_encodings.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include("utils.jl")
include("gaussian_cdf.jl")
include("ordinal_pattern.jl")
42 changes: 0 additions & 42 deletions src/encoding/outcomes.jl

This file was deleted.

31 changes: 31 additions & 0 deletions src/encodings.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export Encoding, encode, decode

"""
Encoding

The supertype for all encoding schemes. Encodings **always encode elements of
input data into the positive integers**. The encoding API is defined by the
functions [`encode`](@ref) and [`decode`](@ref).
Some probability estimators utilize encodings internally.

Current available encodings are:

- [`OrdinalPatternEncoding`](@ref).
- [`GaussianCDFEncoding`](@ref).
- [`RectangularBinEncoding`](@ref).
"""
abstract type Encoding end

"""
encode(χ, e::Encoding) -> i::Int
Encoding an element `χ ∈ x` of input data `x` (those given to [`probabilities`](@ref))
using encoding `e`.
"""
function encode end

"""
decode(i::Int, e::Encoding) -> ω
Decode an encoded element `i::Int` into the outcome it corresponds to `ω ∈ Ω`.
`Ω` is the [`outcome_space`](@ref) of a probabilities estimator that uses encoding `e`.
"""
function decode end
3 changes: 2 additions & 1 deletion src/probabilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Base.IteratorSize(::Probabilities) = Base.HasLength()
@inline Base.sum(::Probabilities{T}) where T = one(T)

"""
ProbabilitiesEstimator
The supertype for all probabilities estimators.

In Entropies.jl, probability distributions are estimated from data by defining a set of
Expand Down Expand Up @@ -203,5 +204,5 @@ Equivalent with `probabilities_and_outcomes(x, est)[2]`, but for some estimators
it may be explicitly extended for better performance.
"""
function outcomes(x, est::ProbabilitiesEstimator)
return probabilities_and_outcomes(x, est)[2]
return probabilities_and_outcomes(est, x)[2]
end
Loading