This file contains hidden or 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
| using Sobol, ArraysOfArrays | |
| function sobolrand(n,k, extraskip::Int=0) | |
| ω = SobolSeq(k) | |
| Sobol.skip(ω, n) # recommended in the Sobol.jl README | |
| for _ in 1:extraskip | |
| Sobol.next!(ω) | |
| end | |
| x = Matrix{Float64}(undef, k, n) |
This file contains hidden or 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
| using LinearAlgebra | |
| # Modify column jᵥ to be orthogonal to column jᵤ | |
| function ortho!(A::AbstractMatrix, jᵥ, jᵤ; startat=1) | |
| # v ← v - projᵤ(v) | |
| nrows = size(A,1) | |
| u_v = 0.0 | |
| u_u = 0.0 | |
| @inbounds for i in startat:nrows | |
| u_v += A[i,jᵤ] * A[i,jᵥ] |
This file contains hidden or 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
| # Origin: | |
| # https://julialang.zulipchat.com/#narrow/stream/274208-helpdesk-.28published.29/topic/Constraining.20method.20signatures/near/262358928 | |
| struct MethodWrapper{F, T <: Tuple, R} | |
| f::F | |
| end | |
| MethodWrapper(f::F, Ts) where {F} = MethodWrapper{F, toTuple(Ts), Any}(f) | |
| MethodWrapper(f::F, (Ts, R)::Pair) where {F} = MethodWrapper{F, toTuple(Ts), R}(f) | |
| toTuple(::Type{T}) where {T} = Tuple{T} |
This file contains hidden or 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
| using Soss | |
| using ZigZagBoomerang | |
| using MeasureTheory | |
| using Soss: logdensity, xform, ConditionalModel | |
| using ZigZagBoomerang | |
| using ForwardDiff | |
| using ForwardDiff: gradient! | |
| using LinearAlgebra |
This file contains hidden or 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
| using Soss, MeasureTheory, AbstractGPs, Test, SampleChainsDynamicHMC | |
| @testset "Soss" begin | |
| @testset "GP regression" begin | |
| k = SqExponentialKernel() | |
| y = randn(3) | |
| X = randn(3, 1) | |
| x = [rand(1) for _ in 1:3] | |
| gp_regression = Soss.@model X begin |
This file contains hidden or 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
| using Soss, MeasureTheory, Plots | |
| # ℓ: log-posterior density we want to sample | |
| # propose: the Markov kernel for the proposal | |
| # x: current point | |
| mhstep = @model ℓ,propose,x begin | |
| y ~ propose(x) | |
| u ~ Uniform() | |
| accept = log(u) < ℓ(y) - ℓ(x) | |
| return accept ? y : x |
This file contains hidden or 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
| using PositiveFactorizations | |
| using LinearAlgebra | |
| using StatsFuns | |
| using Random | |
| using OnlineStatsBase | |
| using Statistics | |
| const OSB = OnlineStatsBase | |
| const bessel = OSB.bessel |
This file contains hidden or 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
| using Soss | |
| using ZigZagBoomerang | |
| using Soss: logdensity, xform, ConditionalModel | |
| using ForwardDiff | |
| using ForwardDiff: gradient! | |
| using LinearAlgebra | |
| using SparseArrays | |
| using StructArrays | |
| using TransformVariables | |
| using MeasureTheory |
This file contains hidden or 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
| using MacroTools: @q | |
| using GeneralizedGenerated | |
| struct TypelevelExpr{T} | |
| expr::Expr | |
| TypelevelExpr(expr::Expr) = new{to_type(expr)}(expr) | |
| end | |
| @gg function with(nt::NamedTuple{N,T}, ::TypelevelExpr{E}) where {N,T,E} |
This file contains hidden or 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
| using Sobol | |
| using MeasureTheory | |
| abstract type Hypercube{k} end | |
| struct SobolHypercube{k} <: Hypercube{k} | |
| seq :: SobolSeq{k} | |
| value :: Vector{Float64} | |
| index :: Ref{Int} # start at zero |
NewerOlder