From e9e943c04fccfd914fc965888167ace1cbd4a069 Mon Sep 17 00:00:00 2001 From: kagalenko-m-b Date: Sun, 29 May 2022 17:32:40 +0300 Subject: [PATCH] Remove unneeded stuff from tests --- src/signalcorr.jl | 4 ++-- test/rcall_test.jl | 29 ----------------------------- test/signalcorr.jl | 28 ++++++++++------------------ 3 files changed, 12 insertions(+), 49 deletions(-) delete mode 100644 test/rcall_test.jl diff --git a/src/signalcorr.jl b/src/signalcorr.jl index 717d8bbee..f31d85ae2 100644 --- a/src/signalcorr.jl +++ b/src/signalcorr.jl @@ -302,7 +302,7 @@ function crosscov!(r::AbstractMatrix, x::AbstractVector, y::AbstractMatrix, lags return r end -function crosscov!(r::AbstractArray{<:Any}, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true) +function crosscov!(r::AbstractArray{<:Any,3}, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true) lx = size(x, 1) nx = size(x, 2) ny = size(y, 2) @@ -458,7 +458,7 @@ function crosscor!(r::AbstractMatrix, x::AbstractVector, y::AbstractMatrix, lags return r end -function crosscor!(r::AbstractArray{<:Any}, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true) +function crosscor!(r::AbstractArray{<:Any,3}, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true) lx = size(x, 1) nx = size(x, 2) ny = size(y, 2) diff --git a/test/rcall_test.jl b/test/rcall_test.jl deleted file mode 100644 index efa0c1bfb..000000000 --- a/test/rcall_test.jl +++ /dev/null @@ -1,29 +0,0 @@ -using RCall - -_r_ccf(x, y, lm) = rcopy(rcall(:ccf, x, y, plot=false, lag=lm, type="covariance"))[:acf] -_r_acf(x, lm) = rcopy(rcall(:acf, x, plot=false, lag=lm, type="covariance"))[:acf] -_r_pacf(x, lm) = rcopy(rcall(:acf, x, plot=false, lag=lm))[:acf] - -function _ccf(is_auto::Bool, x::AbstractVector{<:Real}...) - lx = size(x[1], 1) - lag_max = min(lx - 1, round(Int, 10*log10(lx))) - cor = reverse(dropdims(_r_ccf(x[1], x[end], lag_max), dims = (2, 3))) - is_auto ? cor[lx:end] : cor -end - -r_autocov(x::AbstractVector) = r_crosscov(x, x, true) - -function r_crosscov(x::AbstractVector, y::AbstractVector, is_auto=false) - cv(x,y) = _ccf(is_auto, x, y) - cc_re = cv(real.(x), real.(y)) + cv(imag.(x), imag.(y)) - cc_im = cv(real.(x), imag.(y)) - cv(imag.(x), real.(y)) - cc_re + im*cc_im -end - -r_autocor(x::AbstractVector) = r_crosscor(x, x, true) - -function r_crosscor(x::AbstractVector, y::AbstractVector, is_auto=false) - cc = r_crosscov(x, y, is_auto) - sc(z) = _r_ccf(real.(z), real.(z), 0) + _r_ccf(imag.(z), imag.(z), 0) - cc/sqrt(sc(x)*sc(y)) -end diff --git a/test/signalcorr.jl b/test/signalcorr.jl index 978b2e7f1..f251f612c 100644 --- a/test/signalcorr.jl +++ b/test/signalcorr.jl @@ -129,25 +129,17 @@ pacf_ls = [-1.598495044296996e-03 - 2.915104118351207e-01im @test pacf(x1, 1:4) ≈ pacf_ls[1:4] -## pacf Yule-Walker - -function yulewalker_qr(v::AbstractVector) - A = toeplitz(v) - b = v[2:end] - x = -A\b -end -function toeplitz(v::AbstractVector{T}) where T - N = length(v) - A = zeros(T, N - 1, N - 1) - for n in 1:N-1 - A[n, n+1:end] = conj(v[2:N-n]) - A[n, 1:n] = reverse(v[1:n]) - end - return A -end -# durbin solver +## PACF Durbin solver +p_qr = [ 0.007061066965510003 + 0.2467057077053922im + 0.3390065585042673 - 0.19328284216710082im + 0.17336154780689775 - 0.026816622064955047im + 0.17103798323175215 - 0.16022674917138569im + -0.10466472359738815 - 0.1320218198465664im + 0.0486999464280363 - 0.10069213696609468im + 0.056254003938430636 - 0.09745957137815701im + -0.07247287124498031 + 0.05734525689737796im + 0.10967412213230482 - 0.05581001671362978im] acf = autocor(x1) -p_qr = [yulewalker_qr(acf[1:n])[n-1] for n in 2:length(acf)] y = similar(acf[2:end]) pd = similar(acf[2:end]) StatsBase.durbin!(acf[2:end], y, pd)