Skip to content

Commit

Permalink
fixes for 0.7/1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
awllee committed Aug 13, 2018
1 parent e0cde31 commit 6267f11
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 160 deletions.
26 changes: 7 additions & 19 deletions .travis.yml
Expand Up @@ -4,9 +4,11 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
env:
- JULIA_NUM_THREADS=2
notifications:
email: false
git:
Expand All @@ -16,24 +18,10 @@ git:
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: 0.7
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
# packages:
# - gfortran
#before_script: # homebrew for mac
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi

## uncomment the following lines to override the default test script
script:
- julia -e 'Pkg.clone(pwd()); Pkg.build("SMCExamples")'
- JULIA_NUM_THREADS=2 julia -e 'Pkg.test("SMCExamples"; coverage=true)'
# - julia -e 'Pkg.clone(pwd()); Pkg.build("SMCExamples"); Pkg.test("SMCExamples"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("SMCExamples")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("SMCExamples")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
# push coverage results to Coveralls
- julia -e 'import Pkg, SMCExamples; cd(joinpath(dirname(pathof(SMCExamples)), "..")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'import Pkg, SMCExamples; cd(joinpath(dirname(pathof(SMCExamples)), "..")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
3 changes: 1 addition & 2 deletions REQUIRE
@@ -1,5 +1,4 @@
julia 0.6
julia 0.7
SequentialMonteCarlo
RNGPool
StaticArrays
Compat
64 changes: 30 additions & 34 deletions appveyor.yml
@@ -1,47 +1,43 @@
environment:
JULIA_NUM_THREADS: 2
matrix:
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1.0
- julia_version: latest

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
platform:
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
matrix:
allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: latest

branches:
only:
- master
- /release-.*/
# branches:
# only:
# - master
# - /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false
# notifications:
# - provider: Email
# on_build_success: false
# on_build_failure: false
# on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"SMCExamples\"); Pkg.build(\"SMCExamples\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"SMCExamples\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
27 changes: 14 additions & 13 deletions demo/lgDemo2.jl
Expand Up @@ -2,6 +2,7 @@ using SequentialMonteCarlo
using RNGPool
import SMCExamples.LinearGaussian.defaultLGModel
import SMCExamples.Particles.Float64Particle
import Statistics: mean, var

setRNGs(0)

Expand Down Expand Up @@ -29,14 +30,14 @@ println("Estimate: $filtVarSMC")

println("Running many particle filters with only 128 particles in parallel...")
m = 10000
lZs = Vector{Float64}(m)
Vs = Vector{Float64}(m)
lZhats = Vector{Float64}(m)
Vhats = Vector{Float64}(m)
lZs = Vector{Float64}(undef, m)
Vs = Vector{Float64}(undef, m)
lZhats = Vector{Float64}(undef, m)
Vhats = Vector{Float64}(undef, m)
f1(p::Float64Particle) = 1.0

nthreads = Threads.nthreads()
smcios = Vector{SMCIO}(nthreads)
smcios = Vector{SMCIO}(undef, nthreads)
Threads.@threads for i = 1:nthreads
smcios[i] = SMCIO{model.particle, model.pScratch}(128, model.maxn, 1, true)
end
Expand All @@ -50,15 +51,15 @@ end
end

print("Empirical relative variance of Z_n^N: ")
println(var(exp.(lZs-ko.logZhats[smcio.n-1])))
println(var(exp.(lZs.-ko.logZhats[smcio.n-1])))
print("Mean of unbiased estimator of relative variance of Z_n^N: ")
println(mean(Vs .* exp.(2*(lZs-ko.logZhats[smcio.n-1]))))
println(mean(Vs .* exp.(2*(lZs.-ko.logZhats[smcio.n-1]))))
print("Estimated standard deviation of the value above: ")
println(sqrt(var(Vs .* exp.(2*(lZs-ko.logZhats[smcio.n-1])))/m))
println(sqrt(var(Vs .* exp.(2*(lZs.-ko.logZhats[smcio.n-1])))/m))

print("Empirical relative variance of \hat{Z}_n^N: ")
println(var(exp.(lZhats-ko.logZhats[smcio.n])))
print("Mean of unbiased estimator of relative variance of \hat{Z}_n^N: ")
println(mean(Vhats .* exp.(2*(lZhats-ko.logZhats[smcio.n]))))
print("Empirical relative variance of \\hat{Z}_n^N: ")
println(var(exp.(lZhats.-ko.logZhats[smcio.n])))
print("Mean of unbiased estimator of relative variance of \\hat{Z}_n^N: ")
println(mean(Vhats .* exp.(2*(lZhats.-ko.logZhats[smcio.n]))))
print("Estimated standard deviation of the value above: ")
println(sqrt(var(Vhats .* exp.(2*(lZhats-ko.logZhats[smcio.n])))/m))
println(sqrt(var(Vhats .* exp.(2*(lZhats.-ko.logZhats[smcio.n])))/m))
29 changes: 9 additions & 20 deletions demo/lgPMMHDemo.jl
Expand Up @@ -2,13 +2,14 @@ using SequentialMonteCarlo
using RNGPool
using SMCExamples.LinearGaussian: LGTheta, Float64Particle, kalmanlogZ,
defaultLGModel, makeLGModel
import MonteCarloMarkovKernels: simulateChain!, makeAMKernel, kde, estimateBM
import MonteCarloMarkovKernels: simulateChainProgress, simulateChain,
makeAMKernel, kde, estimateBM
using StaticArrays
using StatsBase
using LinearAlgebra
using Random
using Plots
import Compat.Nothing
Plots.gr()
!isinteractive() && (ENV["GKSwstype"] = "100")

setRNGs(0)
lgModel, theta, ys, ko = defaultLGModel(100)
Expand Down Expand Up @@ -58,29 +59,17 @@ logtargetKalman = makelgkalmanltd(ys)
PSMC = makeAMKernel(logtargetSMC, sigmaProp)
PKalman = makeAMKernel(logtargetKalman, sigmaProp)

srand(12345)
chainSMC = Vector{SVector{3, Float64}}(2^6)
simulateChain!(chainSMC, PSMC, t0)
chainSMC = Vector{SVector{3, Float64}}(2^15)
@time simulateChain!(chainSMC, PSMC, t0)
Random.seed!(12345)
chainSMC = simulateChainProgress(PSMC, t0, 2^15)
sar = PSMC(:acceptanceRate)

chainKalman = Vector{SVector{3, Float64}}(2^6)
simulateChain!(chainKalman, PKalman, t0)
chainKalman = Vector{SVector{3, Float64}}(2^20)
@time simulateChain!(chainKalman, PKalman, t0)
@time chainKalman = simulateChain(PKalman, t0, 2^20)
kar = PKalman(:acceptanceRate)

savefigures = false

vsKalman = Vector{Vector{Float64}}(3)
for i = 1:3
vsKalman[i] = (x->x[i]).(chainKalman)
end
vsSMC = Vector{Vector{Float64}}(3)
for i = 1:3
vsSMC[i] = (x->x[i]).(chainSMC)
end
vsKalman = (i->(x->x[i]).(chainKalman)).(1:3)
vsSMC = (i->(x->x[i]).(chainSMC)).(1:3)

plot(kde(vsSMC[1], sar))
plot!(kde(vsKalman[1], kar))
Expand Down
4 changes: 2 additions & 2 deletions demo/mvlgcsmcDemo.jl
Expand Up @@ -14,14 +14,14 @@ nsamples = 2^14

smcio = SMCIO{model.particle, model.pScratch}(16, model.maxn, 1, true, 2.0)

v = Vector{MVFloat64Particle{2}}(10)
v = Vector{MVFloat64Particle{2}}(undef, 10)
for p = 1:10
v[p] = MVFloat64Particle{2}()
v[p].x .= zeros(MVector{2, Float64})
end

function smoothingMeans(model, smcio, m, v)
tmp = Vector{MVector{2,Float64}}(10)
tmp = Vector{MVector{2,Float64}}(undef, 10)
for p = 1:10
tmp[p] = zeros(MVector{2, Float64})
end
Expand Down
4 changes: 3 additions & 1 deletion demo/smcSamplerDemo2.jl
@@ -1,6 +1,7 @@
using SequentialMonteCarlo
using RNGPool
import SMCExamples.SMCSampler.defaultSMCSampler
using MonteCarloMarkovKernels
using StaticArrays
using Plots
Plots.gr()
Expand All @@ -17,6 +18,7 @@ xs = (p->p.x[1]).(smcio.zetas)
ys = (p->p.x[2]).(smcio.zetas)

## bimodal target needs a kde bandwidth adjustment since its variance is large
x, y, f = MonteCarloMarkovKernels.kde(xs, ys, 0.005)
# x, y, f = MonteCarloMarkovKernels.kde(xs, ys, 0.005)
x, y, f = MonteCarloMarkovKernels.kde(xs, ys, 1.0, 0.001)
contour(x, y, f)
contour!(x,y, (x,y) -> exp(ltarget((SVector{2,Float64}(x,y)))))
8 changes: 0 additions & 8 deletions src/SMCExamples.jl
@@ -1,17 +1,9 @@
VERSION < v"0.7-" && __precompile__()

module SMCExamples

using SequentialMonteCarlo
using RNGPool
using StaticArrays

import Compat.UndefInitializer
if VERSION < v"0.7-"
MVector{d, Float64}(::UndefInitializer) where d = MVector{d, Float64}()
MMatrix{d, d, Float64}(::UndefInitializer) where d = MMatrix{d, d, Float64}()
end

include("particles.jl")
include("lgModel.jl")
include("mvlgModel.jl")
Expand Down
1 change: 0 additions & 1 deletion src/finiteFK.jl
Expand Up @@ -7,7 +7,6 @@ using SequentialMonteCarlo
using RNGPool
using StaticArrays
import SMCExamples.Particles.Int64Particle
import Compat: undef, Nothing, findall

struct FiniteFK{d}
mu::SVector{d, Float64}
Expand Down
1 change: 0 additions & 1 deletion src/lgModel.jl
Expand Up @@ -5,7 +5,6 @@ module LinearGaussian
using SequentialMonteCarlo
using RNGPool
import SMCExamples.Particles.Float64Particle
import Compat: undef, Nothing

struct LGTheta
A::Float64
Expand Down
3 changes: 1 addition & 2 deletions src/lorenz96Model.jl
Expand Up @@ -8,8 +8,7 @@ using SequentialMonteCarlo
using RNGPool
using StaticArrays
import SMCExamples.Particles.MVFloat64Particle
using Compat.Random
import Compat.undef
using Random

struct LorenzTheta
σ::Float64
Expand Down
2 changes: 1 addition & 1 deletion src/mvlgKalman.jl
@@ -1,4 +1,4 @@
import Compat.LinearAlgebra.diagm
import LinearAlgebra.diagm

## Kalman filter for multivariate linear Gaussian models

Expand Down
27 changes: 6 additions & 21 deletions src/mvlgModel.jl
Expand Up @@ -6,21 +6,8 @@ using SequentialMonteCarlo
using RNGPool
using StaticArrays
import SMCExamples.Particles.MVFloat64Particle
using Compat.LinearAlgebra
using Compat.Random
using Compat

if VERSION < v"0.7-" mul! = A_mul_B! end

if VERSION >= v"0.7-"
function mychol(A)
return cholesky(A).L
end
else
function mychol(A)
return chol(Symmetric(A))'
end
end
using LinearAlgebra
using Random

struct MVLGTheta{d}
A::SMatrix{d, d, Float64}
Expand All @@ -42,8 +29,7 @@ MVLGPScratch{d}() where d = MVLGPScratch{d}(MVector{d, Float64}(undef),
function makeMVLGModel(theta::MVLGTheta, ys::Vector{SVector{d, Float64}}) where
d
n = length(ys)
# cholQ = chol(theta.Q)'
cholQ = SMatrix{d, d, Float64}(mychol(theta.Q))
cholQ = SMatrix{d, d, Float64}(cholesky(theta.Q).L)
invRover2 = 0.5 * inv(theta.R)
sqrtv0 = sqrt.(theta.v0)
logncG = - 0.5 * d * log(2 * π) - 0.5 * logdet(theta.R)
Expand Down Expand Up @@ -75,8 +61,7 @@ function simulateMVLGModel(theta::MVLGTheta{d}, n::Int64) where d
ys = Vector{SVector{d, Float64}}(undef, n)
xParticle = MVFloat64Particle{d}()
xScratch = MVLGPScratch{d}()
# cholR = chol(theta.R)'
cholR = mychol(theta.R)
cholR = cholesky(theta.R).L
rng = getRNG()
for p in 1:n
model.M!(xParticle, rng, p, xParticle, xScratch)
Expand All @@ -100,8 +85,8 @@ function defaultMVLGModel(d::Int64, n::Int64)
tC = toeplitz(d, 0.5, 1.2)
tQ = toeplitz(d, 0.2, 0.6)
tR = toeplitz(d, 0.3, 1.5)
tx0 = SVector{d,Float64}(Compat.range(1, step=1, length=d))
tv0 = SVector{d,Float64}(Compat.range(2, step=1, length=d))
tx0 = SVector{d,Float64}(range(1, step=1, length=d))
tv0 = SVector{d,Float64}(range(2, step=1, length=d))
theta = MVLGTheta(tA, tQ, tC, tR, tx0, tv0)
ys = simulateMVLGModel(theta, n)

Expand Down
2 changes: 0 additions & 2 deletions src/nettoModel.jl
Expand Up @@ -9,8 +9,6 @@ using SequentialMonteCarlo
using RNGPool
import SMCExamples.Particles.Float64Particle

import Compat: Nothing, undef

struct NettoTheta
σ²::Float64
δ²::Float64
Expand Down
1 change: 0 additions & 1 deletion src/particles.jl
Expand Up @@ -3,7 +3,6 @@
module Particles

using StaticArrays
import Compat.undef

mutable struct Int64Particle
x::Int64
Expand Down

0 comments on commit 6267f11

Please sign in to comment.