Skip to content

Commit

Permalink
remove unecessary statsbase usage (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris authored Sep 29, 2023
1 parent 1a27d46 commit 5d716b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "TimeseriesSurrogates"
uuid = "c804724b-8c18-5caa-8579-6025a0767c70"
authors = ["Kristian Agasøster Haaga <[email protected]>", "George Datseris"]
repo = "https://github.com/JuliaDynamics/TimeseriesSurrogates.jl.git"
version = "2.6.1"
version = "2.6.2"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
2 changes: 1 addition & 1 deletion src/methods/pseudoperiodic.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DelayEmbeddings, StatsBase, LinearAlgebra
using DelayEmbeddings, LinearAlgebra
export PseudoPeriodic, noiseradius

"""
Expand Down
15 changes: 8 additions & 7 deletions src/methods/truncated_fourier.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export TFTS, TAAFT
using StatsBase: sample, sample!

"""
TFTS(fϵ::Real)
Expand Down Expand Up @@ -83,7 +84,7 @@ function (sg::SurrogateGenerator{<:TFTS})()
𝓕new, 𝓕s, ϕs = getfield.(Ref(sg.init), init_fields)

# Surrogate starts out as a random permutation of x
s .= x[StatsBase.sample(sg.rng, 1:L, L; replace = false)]
s .= x[sample(sg.rng, 1:L, L; replace = false)]
𝓕s .= forward * s
ϕs .= angle.(𝓕s)

Expand All @@ -103,7 +104,7 @@ function (sg::SurrogateGenerator{<:TFTS})()

𝓕new .= rx .* exp.(ϕs .* 1im)
s .= inverse * 𝓕new

return s
end

Expand Down Expand Up @@ -135,15 +136,15 @@ function surrogenerator(x, method::TAAFT, rng = Random.default_rng())
idxs = collect(1:length(x)),
perm = zeros(Int, length(x)),
)

s = similar(x)
return SurrogateGenerator(method, x, s, init, rng)
end

function (taaft::SurrogateGenerator{<:TAAFT})()
sg = taaft.init.gen
x_sorted, idxs, perm = taaft.init.x_sorted, taaft.init.idxs, taaft.init.perm

x, s = sg.x, sg.s
= sg.method.
L = length(x)
Expand All @@ -157,7 +158,7 @@ function (taaft::SurrogateGenerator{<:TAAFT})()
𝓕new, 𝓕s, ϕs = getfield.(Ref(sg.init), init_fields)

# Surrogate starts out as a random permutation of x
StatsBase.sample!(sg.rng, idxs, perm, replace = false)
sample!(sg.rng, idxs, perm, replace = false)
permuted_x_into_s!(s, x, perm)
𝓕s .= forward * s
ϕs .= angle.(𝓕s)
Expand All @@ -178,13 +179,13 @@ function (taaft::SurrogateGenerator{<:TAAFT})()

𝓕new .= rx .* exp.(ϕs .* 1im)
s .= inverse * 𝓕new

s[sortperm(s)] .= x_sorted
return s
end


function permuted_x_into_s!(s, x, perm)
function permuted_x_into_s!(s, x, perm)
k = 1
for i in perm
s[k] = x[i]
Expand Down

0 comments on commit 5d716b0

Please sign in to comment.