JuliaDynamics / TimeseriesSurrogates.jl

A Julia package for generating timeseries surrogates
https://juliadynamics.github.io/TimeseriesSurrogates.jl/stable/
Other
47 stars 9 forks source link

Strange behaviour for PseudoPeriodic surrogates #45

Closed kahaaga closed 2 years ago

kahaaga commented 4 years ago

(I'm on the docsbranch, see #39 )

For certain time series

using TimeseriesSurrogates
ts = NSAR2() # create a realization of an NSAR2 process
phases = true

# Embedding parameters need to be specified
d, τ, ρ = 3, 2, 0.05
method = PseudoPeriodic(d, τ, ρ)
s = surrogate(ts, method)

surrplot(ts, s)

gives

Screenshot 2020-05-12 05 50 34

@Datseris Any idea why the orbit gets stuck in a small neighborhood? I am just naively picking some random value for ρ here, so it might just be because of my ignorance, but I seem to be able to reproduce this for different values of ρ.

If this is an issue inherent to the algorithm, perhaps this should be mentioned in the PseudoPeriodic docstring, or even discussed on the PseudoPeriodic page.

Datseris commented 4 years ago

I don't think it makes sense to use PseudoPeriodic with such timeseries. The method really targets periodic orbits, or approximately periodic orbits, with added noise on top. I.e. there must be a clear signal, or huge peaks in the fourier transform, for it to work.

Datseris commented 4 years ago

Okay, I now what is happening here, gimme a second.

Datseris commented 4 years ago

Yeap:

function pseudoperiodic!(y, x, z, w, ρ, shift)
    N, Ñ = length.((x, z))
    y[1] = shift ? rand(z.data) : z[1]
    @inbounds for i in 1:N-1
        w .= (exp(-norm(z[t] - y[i])/ρ) for t in 1:Ñ-1)
        j = sample(1:Ñ-1, pweights(w))
        y[i+1] = z[j+1]
    end
    return y[:, 1]
end

What I guess happens is that you always get the same j in that algorithm after some point.

I am not sure whether this should be fixed. I actually don't know how to fix it. (I don't think we can call this a "fix": the method worked fine with periodic timeseries. With them there is no problem)

kahaaga commented 2 years ago

This method works for the intented type of time series. Closing.