Skip to content

Commit

Permalink
FAN method (#102)
Browse files Browse the repository at this point in the history
* added FAN-threshold method

* parallel_false implementation done

* debugged fan-methods; set up tests

* minor improvements

* made requested changes; resolve_scale type-stable

* Parametrized types of AbstractRecurrenceMatrix for FAN

* FAN by columns, not rows

* exclude LOI in FAN for RP with single time series

make `_computescale` type stable

* allow non-square CrossRecurrenceMatrix{FAN}

* avoid errors in @windowed RecurrenceMatrix{FAN} etc.

* adapt deprecate.jl and tests to parametric types

* generalize dispatch on AbstractDataset

* redefine FixedRange > WithinRange and FixedAmount > NeighborNumber

Co-authored-by: K. Hauke Kraemer <[email protected]>
  • Loading branch information
heliosdrm and hkraemer authored Dec 14, 2020
1 parent 1d45308 commit d7c5f3f
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RecurrenceAnalysis"
uuid = "639c3291-70d9-5ea2-8c5b-839eba1ee399"
repo = "https://github.com/JuliaDynamics/RecurrenceAnalysis.jl.git"
version = "1.3.2"
version = "1.4.0"

[deps]
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"
Expand All @@ -15,7 +15,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"

[compat]
DelayEmbeddings = "0.1,0.2,0.3,1"
DelayEmbeddings = "1"
Distances = "0.8, 0.9, 0.10"
StaticArrays = "0.8,0.9,0.10,0.11,0.12, 1.0"
UnicodePlots = "0.3,1"
Expand Down
2 changes: 1 addition & 1 deletion src/RecurrenceAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end


export RecurrenceMatrix, CrossRecurrenceMatrix, JointRecurrenceMatrix,
AbstractRecurrenceMatrix
AbstractRecurrenceMatrix, WithinRange, NeighborNumber, FAN

export embed,
reconstruct,
Expand Down
37 changes: 19 additions & 18 deletions src/deprecate.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
function RecurrenceMatrix(x::AbstractMatrix, ε; kwargs...)
@warn "`RecurrenceMatrix(x::AbstractMatrix, ε; kwargs...)` is deprecated, use `RecurrenceMatrix(Dataset(x), ε; kwargs...)`"
RecurrenceMatrix(Dataset(x), ε; kwargs...)
end

for call in (:CrossRecurrenceMatrix, :JointRecurrenceMatrix)
@eval function ($call)(x::AbstractMatrix, y, ε; kwargs...)
@warn string("`", $call, "(x::AbstractMatrix, y, ε; kwargs...)` is deprecated, use `", $call, "(Dataset(x), y, ε; kwargs...)`")
($call)(Dataset(x), y, ε; kwargs...)
end

@eval function ($call)(x, y::AbstractMatrix, ε; kwargs...)
@warn string("`", $call, "(x, y::AbstractMatrix, ε; kwargs...)` is deprecated, use `", $call, "(x, Dataset(y), ε; kwargs...)`")
($call)(x, Dataset(y), ε; kwargs...)
for T in (:WithinRange, :NeighborNumber)
@eval function RecurrenceMatrix{$T}(x::AbstractMatrix, ε; kwargs...)
@warn string("`RecurrenceMatrix{", $T, "}(x::AbstractMatrix, ε; kwargs...)` is deprecated, use `RecurrenceMatrix{", $T, "}(Dataset(x), ε; kwargs...)`")
RecurrenceMatrix{$T}(Dataset(x), ε; kwargs...)
end

@eval function ($call)(x::AbstractMatrix, y::AbstractMatrix, ε; kwargs...)
@warn string("`", $call, "(x::AbstractMatrix, y::AbstractMatrix, ε; kwargs...)` is deprecated, use `", $call, "(Dataset(x), Dataset(y), ε; kwargs...)`")
($call)(Dataset(x), Dataset(y), ε; kwargs...)
for call in (:CrossRecurrenceMatrix, :JointRecurrenceMatrix)
@eval function $call{$T}(x::AbstractMatrix, y, ε; kwargs...)
@warn string("`", $call, "{", $T, "}(x::AbstractMatrix, y, ε; kwargs...)` is deprecated, use `", $call, "{", $T, "}(Dataset(x), y, ε; kwargs...)`")
$call{$T}(Dataset(x), y, ε; kwargs...)
end

@eval function $call{$T}(x, y::AbstractMatrix, ε; kwargs...)
@warn string("`", $call, "{", $T, "}(x, y::AbstractMatrix, ε; kwargs...)` is deprecated, use `", $call, "{", $T, "}(x, Dataset(y), ε; kwargs...)`")
$call{$T}(x, Dataset(y), ε; kwargs...)
end

@eval function $call{$T}(x::AbstractMatrix, y::AbstractMatrix, ε; kwargs...)
@warn string("`", $call, "{", $T, "}(x::AbstractMatrix, y::AbstractMatrix, ε; kwargs...)` is deprecated, use `", $call, "{", $T, "}(Dataset(x), Dataset(y), ε; kwargs...)`")
$call{$T}(Dataset(x), Dataset(y), ε; kwargs...)
end
end
end

14 changes: 7 additions & 7 deletions src/distance_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Create a matrix with the distances between each pair of points of the
time series `x` and `y` using `metric`.
The time series `x` and `y` can be `Dataset`s or vectors or matrices with data points
The time series `x` and `y` can be `AbstractDataset`s or vectors or matrices with data points
in rows.
The data point dimensions (or number of columns) must be the same for `x` and `y`.
The returned value is a `n×m` matrix, with `n` being the length (or number of rows)
Expand All @@ -34,7 +34,7 @@ distancematrix(x, y, metric::String, parallel = size(x)[1] > 500) = distancematr

const MAXDIM = 9
function distancematrix(x::Tx, y::Ty, metric::Metric=DEFAULT_METRIC, parallel = size(x)[1] > 500) where
{Tx<:Union{AbstractMatrix, Dataset}} where {Ty<:Union{AbstractMatrix, Dataset}}
{Tx<:Union{AbstractMatrix, AbstractDataset}} where {Ty<:Union{AbstractMatrix, AbstractDataset}}
sx, sy = size(x), size(y)
@assert sx[2] == sy[2] """
The dimensions of the data points in `x` and `y` must be equal!
Expand All @@ -54,8 +54,8 @@ end
_distancematrix(x::AbstractMatrix, y::AbstractMatrix, metric::Metric, ::Val{false}) = pairwise(metric, x', y', dims=2)

# First we define the serial versions of the functions.
# Core function for Datasets
function _distancematrix(x::Dataset{S,Tx}, y::Dataset{S,Ty},
# Core function for AbstractDatasets
function _distancematrix(x::AbstractDataset{S,Tx}, y::AbstractDataset{S,Ty},
metric::Metric, ::Val{false}) where {S, Tx, Ty}

x = x.data
Expand All @@ -71,7 +71,7 @@ end

# Now, we define the parallel versions.

function _distancematrix(x::Dataset{S,Tx}, y::Dataset{S,Ty},
function _distancematrix(x::AbstractDataset{S,Tx}, y::AbstractDataset{S,Ty},
metric::Metric, ::Val{true}) where {S, Tx, Ty}

x = x.data
Expand Down Expand Up @@ -118,7 +118,7 @@ function _distancematrix(x::Vector{T}, metric::Metric, ::Val{false}) where T

end

function _distancematrix(x::Dataset{S, T}, metric::Metric, ::Val{false}) where T where S
function _distancematrix(x::AbstractDataset{S, T}, metric::Metric, ::Val{false}) where T where S
d = zeros(T, length(x), length(x))

for j in 1:length(x)
Expand Down Expand Up @@ -175,7 +175,7 @@ function _distancematrix(x::Vector{T}, metric::Metric, ::Val{true}) where T

end

function _distancematrix(x::Dataset{S, T}, metric::Metric, ::Val{true}) where T where S
function _distancematrix(x::AbstractDataset{S, T}, metric::Metric, ::Val{true}) where T where S
d = zeros(T, length(x), length(x))

Threads.@threads for k in partition_indices(length(x))
Expand Down
Loading

0 comments on commit d7c5f3f

Please sign in to comment.