-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
160 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
include("DataTypes.jl") | ||
include("init_param.jl") | ||
include("doubleLogistics.jl") | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
using LinearAlgebra | ||
using StaticArrays | ||
|
||
include("SG_helper.jl") | ||
include("SG.jl") | ||
include("SG_weighted.jl") | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
using Test | ||
using VegCurveFit | ||
|
||
@testset "nlminb" begin | ||
# Write your own tests here. | ||
start = [0.0] # [1, 2, 3, 4] | ||
lower = [-4.0] | ||
upper = [4.0] | ||
|
||
function f2(x::Array{Float64,1})::Float64 | ||
x[1] - cos(x[1]) | ||
end | ||
|
||
f(x) = x[1] - cos(x[1]) | ||
r = nlminb(start, f, verbose=false) | ||
@test r["par"][1] == -1.5701006351106073 | ||
end | ||
include("test-lambda_init.jl") | ||
include("test-smooth_SG.jl") | ||
include("test-smooth_whit.jl") | ||
include("test-Optim.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@testset "nlminb" begin | ||
# Write your own tests here. | ||
start = [0.0] # [1, 2, 3, 4] | ||
lower = [-4.0] | ||
upper = [4.0] | ||
|
||
function f2(x::Array{Float64,1})::Float64 | ||
x[1] - cos(x[1]) | ||
end | ||
|
||
f(x) = x[1] - cos(x[1]) | ||
r = nlminb(start, f, verbose=false) | ||
@test r["par"][1] == -1.5701006351106073 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# using Random | ||
|
||
@testset "lambda init" begin | ||
# @examples | ||
# Random.seed!(1234) | ||
y = rand(100) | ||
coef = [0.9809, 0.7247, -2.6752, -0.3854, -0.0604] | ||
lamb = lambda_init(y, coef) | ||
@test lamb > 0 | ||
end | ||
# methods(lambda_init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Test | ||
|
||
@testset "Savitzky Golay filter" begin | ||
# works | ||
@test wSG([2., 3, 5, 7]; halfwin=1, d=2) ≈ [2, 3, 5, 7] | ||
|
||
y = 1.0:10 |> collect | ||
@test wSG(y; halfwin=1, d=1) ≈ y | ||
|
||
# 跟R语言版本基本一致 | ||
y = [2.0, 3, 4, 10, 6, 7] | ||
w = [1.0, 1, 1, 0.2, 1, 1] | ||
z = wSG(y, w; halfwin=1, d=1) | ||
@test round.(z, digits=2) ≈ [2, 3, 5, 5.45, 7, 6.5] | ||
|
||
# wSG对权重调整没有这么敏感 | ||
z = wSG(y, w; halfwin=1, d=2) | ||
@test round.(z, digits=2) ≈ y | ||
end | ||
|
||
|
||
@testset "Savitzky Golay filter" begin | ||
y = [1.0, 2, 5, 4, 3, 6] | ||
w = collect(1.0:7) | ||
halfwin = 3 | ||
S = sgmat_S(halfwin) | ||
B = sgmat_B(S) | ||
sgmat_wB(S, w) | ||
z = SG(y; halfwin=1) | ||
@test z ≈ y | ||
end | ||
|
||
|
||
@testset "Savitzky Golay filter" begin | ||
y = rand(100) | ||
w = rand(100) | ||
SG(y; halfwin=5) | ||
wSG(y, w; halfwin=5) | ||
end | ||
|
||
|
||
# using Plots | ||
# p = plot(y) | ||
# plot!(p, z1) | ||
# plot!(p, z2) | ||
# n = Int(1e5) | ||
# y = rand(n) | ||
# using BenchmarkTools | ||
|
||
## test the used memory | ||
# @time for i=1:1e3 | ||
# z = SG(y) | ||
# end | ||
# using Plots | ||
# gr() | ||
# plot(y) | ||
# plot!(z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Test | ||
|
||
@testset "whittaker smoother" begin | ||
y = [5.0, 8, 9, 10, 12, 10, 15, 10, 9, 19, 19, 17, 13, 14, 18, 19, 18, 12, 18, | ||
24, 0, 1, 18, 17, 6, 13, 12, 10, 9, 6, 6, 3, 4, 3, 3, 3, 2, 3, 4, 4, 3, 2, 3, 3, 1, 3] | ||
y = [y; y; y; y] | ||
m = length(y) | ||
FT = Float32 | ||
|
||
w = ones(Float32, m) | ||
c = zeros(Float32, m) | ||
d = zeros(Float32, m) | ||
e = zeros(Float32, m) | ||
|
||
lambda = 2.0 | ||
z = ones(m) | ||
interm = interm_whit{FT}(; n=length(y)) | ||
cve = whit2!(y, w, lambda, interm; include_cve=true) | ||
z, cve2 = whit2(y, w, lambda) | ||
|
||
@test cve == cve2 | ||
lamb_cv = lambda_cv(y, w, is_plot=false) | ||
lamb_vcurve = lambda_vcurve(y, w) | ||
|
||
z1, cve_cv = whit2(y, w, lamb_cv) | ||
z2, cve_vcurve = whit2(y, w, lamb_vcurve) | ||
@test cve_cv < cve | ||
@test cve_vcurve < cve | ||
@test cve_cv < cve_vcurve | ||
end | ||
|
||
# using BenchmarkTools | ||
# @benchmark | ||
# 4 times faster than R | ||
# @time for i in 1:1e4 | ||
# lamb_vcurve = lambda_vcurve(y, w) | ||
# end | ||
# @time lamb_vcurve = lambda_vcurve(y, w) | ||
|
||
# @time @benchmark lamb_cv = lambda_cv(y, w) | ||
# BenchmarkTools.Trial: | ||
# memory estimate: 412.55 KiB | ||
# allocs estimate: 374 | ||
# -------------- | ||
# minimum time: 172.600 μs (0.00% GC) | ||
# median time: 179.300 μs (0.00% GC) | ||
# mean time: 198.880 μs (3.88% GC) | ||
# maximum time: 1.882 ms (70.58% GC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @profview | ||
n = 1000 | ||
y = rand(n) | ||
w = rand(n) | ||
yfit = rand(n) | ||
|
||
# @testset "weights updating" begin | ||
# w_ts = wTSM(y, yfit, w, iter=2) | ||
# w_bi = wBisquare(y, yfit, w, iter=2) | ||
|
||
# @test length(w_ts) == n | ||
# @test length(w_bi) == n | ||
# end | ||
|
||
# using BenchmarkTools | ||
# @benchmark wnew = wTSM(y, yfit, w, iter = 2) | ||
|
||
# # Debugger.@run | ||
# @benchmark w2 = wBisquare(y, yfit, w, iter = 2) |