Skip to content

Commit

Permalink
update name again
Browse files Browse the repository at this point in the history
  • Loading branch information
benjione committed Mar 6, 2024
1 parent 9646b0f commit 8bd86d4
Show file tree
Hide file tree
Showing 24 changed files with 120 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "SequentialTransportMaps"
name = "SequentialMeasureTransport"
uuid = "880b6c9a-c7f7-4f83-b244-c5d4e47b6fa9"
authors = ["Benjamin Zanger <[email protected]>"]
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SequentialTransportMaps.jl
# SequentialMeasureTransport.jl

Code of the paper [Seqential Transport maps using SoS densities and $\alpha$-divergences](https://arxiv.org/abs/2402.17943)

Expand Down
8 changes: 4 additions & 4 deletions src/MCMC/mcmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Implements MCMC based on the `AbstractMCMC` interface using the
sampler from `Sampler` in this package.
"""

using ..SequentialTransportMaps
using ..SequentialTransportMaps: AbstractSampler
using ..SequentialMeasureTransport
using ..SequentialMeasureTransport: AbstractSampler
import AbstractMCMC
import MCMCChains
using Distributions
Expand All @@ -29,7 +29,7 @@ end
function (a::MCMCModel{F})(x::Vector{T},
sampler::AbstractSampler{<:Any, <:Any, T}
) where {F, T<:Number}
return SequentialTransportMaps.pullback(sampler, x->a.model(x))(x)
return SequentialMeasureTransport.pullback(sampler, x->a.model(x))(x)
end

function proposal(sampler::MCMCSampler{T}, x::Vector{T}) where {T}
Expand All @@ -42,7 +42,7 @@ function AbstractMCMC.step(rng::Random.AbstractRNG,
model::MCMCModel,
samp::MCMCSampler{T};
kwargs...) where {T <: Number}
next_θ = SequentialTransportMaps.sample(samp.sampler)
next_θ = SequentialMeasureTransport.sample(samp.sampler)
return next_θ, next_θ
end
function AbstractMCMC.step(rng::Random.AbstractRNG,
Expand Down
2 changes: 1 addition & 1 deletion src/PSDModels/models.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include("kernel/PSDModelKernel.jl")
include("feature_map/PSDModelFM.jl")

# optimization algorithms acting on SequentialTransportMaps
# optimization algorithms acting on SequentialMeasureTransport
include("optimization.jl")

function PSDModel(k::Kernel, X::PSDDataVector{T}; kwargs...) where {T<:Number}
Expand Down
2 changes: 1 addition & 1 deletion src/Samplers/bridging/bridging_densities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module BridgingDensities
abstract type BridgingDensity{d, T} end

using DifferentialEquations
using ..SequentialTransportMaps: PSDDataVector, PSDdata
using ..SequentialMeasureTransport: PSDDataVector, PSDdata

include("algebraic.jl")
include("diffusion.jl")
Expand Down
8 changes: 4 additions & 4 deletions src/Samplers/reference_maps/algebraic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ struct AlgebraicReference{d, T} <: ReferenceMap{d, T}
end


function SequentialTransportMaps.pushforward(
function SequentialMeasureTransport.pushforward(
m::AlgebraicReference{<:Any, T},
x::PSDdata{T}
) where {T<:Number}
return ((x./sqrt.(1 .+ x.^2)).+1.0)/2.0
end


function SequentialTransportMaps.pullback(
function SequentialMeasureTransport.pullback(
m::AlgebraicReference{<:Any, T},
u::PSDdata{T}
) where {T<:Number}
Expand All @@ -26,15 +26,15 @@ function SequentialTransportMaps.pullback(
end


function SequentialTransportMaps.Jacobian(
function SequentialMeasureTransport.Jacobian(
m::AlgebraicReference{<:Any, T},
x::PSDdata{T}
) where {T<:Number}
return mapreduce(xi->0.5/(1+xi^2)^(3/2), *, x)
end


function SequentialTransportMaps.inverse_Jacobian(
function SequentialMeasureTransport.inverse_Jacobian(
mapping::AlgebraicReference{<:Any, T},
u::PSDdata{T}
) where {T<:Number}
Expand Down
8 changes: 4 additions & 4 deletions src/Samplers/reference_maps/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ function sample_reference(map::GaussianReference{d, T}, n::Int) where {d, T<:Num
eachcol(randn(T, d, n) * map.σ)
end

function SequentialTransportMaps.pushforward(
function SequentialMeasureTransport.pushforward(
m::GaussianReference{d, T},
x::PSDdata{T}
) where {d, T<:Number}
return 0.5 * (1 .+ erf.(x ./ (m.σ * sqrt(2))))
end


function SequentialTransportMaps.pullback(
function SequentialMeasureTransport.pullback(
m::GaussianReference{d, T},
u::PSDdata{T}
) where {d, T<:Number}
return sqrt(2) * m.σ * erfcinv.(2.0 .- 2*u)
end


function SequentialTransportMaps.Jacobian(
function SequentialMeasureTransport.Jacobian(
m::GaussianReference{d, T},
x::PSDdata{T}
) where {d, T<:Number}
return mapreduce(xi->Distributions.pdf(Distributions.Normal(0, m.σ), xi), *, x)
end


function SequentialTransportMaps.inverse_Jacobian(
function SequentialMeasureTransport.inverse_Jacobian(
mapping::GaussianReference{d, T},
u::PSDdata{T}
) where {d, T<:Number}
Expand Down
12 changes: 6 additions & 6 deletions src/Samplers/reference_maps/reference_maps.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ReferenceMaps

import ..SequentialTransportMaps
using ..SequentialTransportMaps: PSDModelOrthonormal, domain_interval_left, domain_interval_right,
import ..SequentialMeasureTransport
using ..SequentialMeasureTransport: PSDModelOrthonormal, domain_interval_left, domain_interval_right,
PSDdata, Mapping, pullback, pushforward, Jacobian, inverse_Jacobian

using SpecialFunctions: erf, erfcinv
Expand Down Expand Up @@ -44,7 +44,7 @@ end
Pushes forward a vector of a reference distribution to the uniform distribution.
"""
function SequentialTransportMaps.pushforward(
function SequentialMeasureTransport.pushforward(
mapping::ReferenceMap{d, T},
x::PSDdata{T}
) where {d, T<:Number}
Expand All @@ -56,7 +56,7 @@ end
Pulls back a vector of the uniform distribution to the reference distribution.
"""
function SequentialTransportMaps.pullback(
function SequentialMeasureTransport.pullback(
mapping::ReferenceMap{d, T},
u::PSDdata{T}
) where {d, T<:Number}
Expand All @@ -68,7 +68,7 @@ end
Computes the Jacobian of the mapping at the point u.
"""
function SequentialTransportMaps.Jacobian(
function SequentialMeasureTransport.Jacobian(
mapping::ReferenceMap{d, T},
x::PSDdata{T}
) where {d, T<:Number}
Expand All @@ -80,7 +80,7 @@ inverse_Jacobian(mapping, u)
Computes the inverse Jacobian of the mapping at the point x.
"""
function SequentialTransportMaps.inverse_Jacobian(
function SequentialMeasureTransport.inverse_Jacobian(
mapping::ReferenceMap{d, T},
u::PSDdata{T}
) where {d, T<:Number}
Expand Down
8 changes: 4 additions & 4 deletions src/Samplers/reference_maps/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end

## Interface implementation

function SequentialTransportMaps.pushforward(
function SequentialMeasureTransport.pushforward(
m::ScalingReference{d, T},
x::PSDdata{T}
) where {d, T<:Number}
Expand All @@ -36,7 +36,7 @@ function SequentialTransportMaps.pushforward(
end


function SequentialTransportMaps.pullback(
function SequentialMeasureTransport.pullback(
m::ScalingReference{d, T},
u::PSDdata{T}
) where {d, T<:Number}
Expand All @@ -45,7 +45,7 @@ function SequentialTransportMaps.pullback(
end


function SequentialTransportMaps.Jacobian(
function SequentialMeasureTransport.Jacobian(
mapping::ScalingReference{d, T},
x::PSDdata{T}
) where {d, T<:Number}
Expand All @@ -57,7 +57,7 @@ function SequentialTransportMaps.Jacobian(
end


function SequentialTransportMaps.inverse_Jacobian(
function SequentialMeasureTransport.inverse_Jacobian(
mapping::ScalingReference{d, T},
u::PSDdata{T}
) where {d, T<:Number}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SequentialTransportMaps
module SequentialMeasureTransport

using LinearAlgebra, SparseArrays
using KernelFunctions: Kernel, kernelmatrix
Expand Down
18 changes: 9 additions & 9 deletions src/statistics.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Statistics

using ..SequentialTransportMaps
using ..SequentialTransportMaps: PSDDataVector
using ..SequentialTransportMaps: PSDModelOrthonormal
using ..SequentialTransportMaps: CondSampler
using ..SequentialTransportMaps: domain_interval_left, domain_interval_right
using ..SequentialTransportMaps: greedy_IRLS
using ..SequentialTransportMaps: _ML_JuMP!
using ..SequentialTransportMaps: _KL_JuMP!
using ..SequentialTransportMaps: _α_divergence_JuMP!
using ..SequentialMeasureTransport
using ..SequentialMeasureTransport: PSDDataVector
using ..SequentialMeasureTransport: PSDModelOrthonormal
using ..SequentialMeasureTransport: CondSampler
using ..SequentialMeasureTransport: domain_interval_left, domain_interval_right
using ..SequentialMeasureTransport: greedy_IRLS
using ..SequentialMeasureTransport: _ML_JuMP!
using ..SequentialMeasureTransport: _KL_JuMP!
using ..SequentialMeasureTransport: _α_divergence_JuMP!
using LinearAlgebra
using FastGaussQuadrature: gausslegendre
using Distributions: pdf
Expand Down
4 changes: 2 additions & 2 deletions test/PSDKernel_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ end
model = PSDModel(X, Y, k; solver=:gradient_descent)

@inline interval(x) = 0..x[1]
int_vec = SequentialTransportMaps.integrate.(Ref(model), interval.(X))
int_vec = SequentialMeasureTransport.integrate.(Ref(model), interval.(X))
@test norm(int_vec - f_int.(X)) < 1e-1
end

Expand Down Expand Up @@ -195,7 +195,7 @@ end

X2 = Float64[4, 5, 6]
X2 = [[x] for x in X2]
model2 = SequentialTransportMaps.add_support(model, X2)
model2 = SequentialMeasureTransport.add_support(model, X2)

for i in rand(20) * 4
@test model(i) model2(i)
Expand Down
16 changes: 8 additions & 8 deletions test/PSDPolynomial_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ end
normalize_orth_measure!(model)
@test tr(model.B) 1.0

SequentialTransportMaps.normalize!(model)
SequentialMeasureTransport.normalize!(model)
@test tr(model.B) 1.0
end

Expand All @@ -162,7 +162,7 @@ end
normalize_orth_measure!(model)
@test tr(model.B) 1.0

SequentialTransportMaps.normalize!(model)
SequentialMeasureTransport.normalize!(model)
@test tr(model.B) 1.0
end
end
Expand All @@ -177,7 +177,7 @@ end
Y = f.(X)

fit!(model, X, Y, maxit=2000)
model_perm = SequentialTransportMaps.permute_indices(model, [2,1])
model_perm = SequentialMeasureTransport.permute_indices(model, [2,1])
for i=1:100
x = (rand(2) .- 0.5) * 30.0
@test model_perm(x) == model([x[2], x[1]])
Expand All @@ -194,7 +194,7 @@ end
Y = f.(X)

fit!(model, X, Y, maxit=2000)
model_poly = SequentialTransportMaps.compile(model)
model_poly = SequentialMeasureTransport.compile(model)
for i=1:100
x = (rand(2) .- 0.5) * 30.0
@test model_poly(x) model(x)
Expand All @@ -213,11 +213,11 @@ end
fit!(model, X, Y)

int_model = integral(model, 1; C=0.0)
int_model_compiled = SequentialTransportMaps.compiled_integral(model, 1; C=0.0)
int_model_compiled = SequentialMeasureTransport.compiled_integral(model, 1; C=0.0)
@test all(int_model.(X) .≈ int_model_compiled.(X))

int_model2 = integral(model, 2; C=0.0)
int_model_compiled2 = SequentialTransportMaps.compiled_integral(model, 2; C=0.0)
int_model_compiled2 = SequentialMeasureTransport.compiled_integral(model, 2; C=0.0)
@test all(int_model2.(X) .≈ int_model_compiled2.(X))
end

Expand All @@ -233,13 +233,13 @@ end
fit!(model, X, Y)

int_model = integral(model, 1)
int_model_compiled = SequentialTransportMaps.compiled_integral(model, 1)
int_model_compiled = SequentialMeasureTransport.compiled_integral(model, 1)
for x in X
@test isapprox(int_model(x), int_model_compiled(x), atol=1e-10)
end

int_model2 = integral(model, 2)
int_model_compiled2 = SequentialTransportMaps.compiled_integral(model, 2)
int_model_compiled2 = SequentialMeasureTransport.compiled_integral(model, 2)
for x in X
@test isapprox(int_model2(x), int_model_compiled2(x), atol=1e-10)
end
Expand Down
8 changes: 4 additions & 4 deletions test/Sampler/SR_ML_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
samples = [[x] for x in samples]
model = PSDModel(Legendre(0.0..1.0), :downward_closed, 3)
bridge = DiffusionBrigdingDensity{1}(x->1.0, [1.0, 0.5, 0.25, 0.1, 0.05, 0.0], 2.0)
ref_map = SequentialTransportMaps.ReferenceMaps.GaussianReference{1, Float64}(2.0)
sra = SequentialTransportMaps.SelfReinforced_ML_estimation(
ref_map = SequentialMeasureTransport.ReferenceMaps.GaussianReference{1, Float64}(2.0)
sra = SequentialMeasureTransport.SelfReinforced_ML_estimation(
samples,
model,
bridge,
Expand All @@ -38,8 +38,8 @@ end
X_train = [[x] for x in X_train]
X_val = [[x] for x in X_val]
model = PSDModel(Legendre(0.0..1.0), :downward_closed, 5)
ref_map = SequentialTransportMaps.ReferenceMaps.AlgebraicReference{1, Float64}()
sra = SequentialTransportMaps.Adaptive_Self_reinforced_ML_estimation(
ref_map = SequentialMeasureTransport.ReferenceMaps.AlgebraicReference{1, Float64}()
sra = SequentialMeasureTransport.Adaptive_Self_reinforced_ML_estimation(
X_train,
X_val,
model,
Expand Down
Loading

0 comments on commit 8bd86d4

Please sign in to comment.