Skip to content

Commit

Permalink
some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed May 4, 2020
1 parent dd13d7a commit bc3ec05
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ consecutive windows of `A` will be compared to the entire `B`. The resulting mat

If `dist` is provided, a generic (slow) method is used. If `dist` is not provided and the inputs `A,B` are one dimensional vectors of numbers, a fast method is used. The fast method handles long time series, `length(A) = length(B) = 100k` takes less than 30s.

If the time-series is sampled very fast in relation to the time scale on which interesting things happen, you may try the function [`resample(T, fraction::Real)`](https://juliadsp.github.io/DSP.jl/stable/filters/#DSP.Filters.resample) to reduce the amount of data to process. Example, `resample(T, desired_samplerate/original_samplerate)`.

## Motif grouping
Using the fake data from the example above, we can do
```julia
Expand All @@ -50,7 +52,7 @@ plot(profile, mot)
```
- `k` is the number of motifs to extract
- `r` controls how similar two windows must be to belong to the same motif. A higher value leads to more windows being grouped together.
- `th` is a threshold on how far nearby in time two motifs are allowed to be.
- `th` is a threshold on how nearby in time two motifs are allowed to be.
![motif_plot](figures/motifs.svg)

Also see the function `anomalies(profile)` to find anomalies in the data, sometimes called *discords*.
Expand Down
2 changes: 1 addition & 1 deletion src/MatrixProfile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using RecipesBase
using SlidingDistancesBase
import SlidingDistancesBase: floattype, lastlength, distance_profile, distance_profile!

export matrix_profile, distance_profile, motifs, anomalies, mpdist, mpdist_profile, onsets, snippets, seqs
export matrix_profile, distance_profile, motifs, anomalies, mpdist, mpdist_profile, onsets, snippets, seqs, resample


struct Profile{TT,TP,QT}
Expand Down
4 changes: 2 additions & 2 deletions src/motifs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SubSeqType = Union{AbstractSubSequence, AbstractVector{<:AbstractSubSequen
onsets(m::Motif) = getfield.(m.seqs, :onset)
seqs(m::Motif) = getfield.(m.seqs, :seq)
seqlength(m::Motif) = length(m.seqs[1].seq)
subseqtype(::Motif) = "Motif"
subseqtype(::Union{Motif, Vector{<:Motif}}) = "Motif"

onsets(m::Subsequence) = m.onset
seqs(m::Subsequence) = [m.seq]
Expand All @@ -24,7 +24,7 @@ subseqtype(m::Subsequence) = m.type

onsets(m::Array{<:Subsequence}) = onsets.(m)
seqs(m::Array{<:Subsequence}) = getfield.(m, :seq)
seqlength(m::Array{<:Subsequence}) = seqlength(length(m[1]))
seqlength(m::Array{<:Subsequence}) = length(m[1].seq)
subseqtype(m::Array{<:Subsequence}) = subseqtype(m[1])

function motifs(p::Profile, k, r, th = 0, found_motifs = Motif[])
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,19 @@ end
profile = matrix_profile(T, length(y0))

@time mot = motifs(profile, 2, 2, 5)
@test MatrixProfile.subseqtype(mot) == "Motif"
@test onsets(mot[1]) == [51, 112]
@test_nowarn plot(mot)
@test_nowarn plot(profile, mot)

an = MatrixProfile.anomalies(profile, 3)
@test length(an) == 3
@test length(seqs(an)) == 3
@test MatrixProfile.subseqtype(an) == "Anomaly"
@test onsets(an)[1] == argmax(profile.P)
@test_nowarn plot(an)
@test MatrixProfile.seqlength(an) == length(y0)

end


Expand Down

0 comments on commit bc3ec05

Please sign in to comment.