Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ps = ComponentArrays.ComponentArray(ps)
function diff_loss_tn(x::Any)
return ContinuousNormalizingFlows.loss(
icnf,
ContinuousNormalizingFlows.TrainMode(),
ContinuousNormalizingFlows.TrainMode{true}(),
r,
x,
st,
Expand All @@ -79,7 +79,7 @@ end
function diff_loss_tt(x::Any)
return ContinuousNormalizingFlows.loss(
icnf,
ContinuousNormalizingFlows.TestMode(),
ContinuousNormalizingFlows.TestMode{true}(),
r,
x,
st,
Expand All @@ -89,7 +89,7 @@ end
function diff_loss_tn2(x::Any)
return ContinuousNormalizingFlows.loss(
icnf2,
ContinuousNormalizingFlows.TrainMode(),
ContinuousNormalizingFlows.TrainMode{true}(),
r,
x,
st,
Expand All @@ -98,7 +98,7 @@ end
function diff_loss_tt2(x::Any)
return ContinuousNormalizingFlows.loss(
icnf2,
ContinuousNormalizingFlows.TestMode(),
ContinuousNormalizingFlows.TestMode{true}(),
r,
x,
st,
Expand Down
18 changes: 9 additions & 9 deletions src/core/base_icnf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ end

function steer_tspan(
icnf::AbstractICNF{<:AbstractFloat, <:ComputeMode, INPLACE, COND, AUGMENTED, true},
::TrainMode,
::TrainMode{true},
) where {INPLACE, COND, AUGMENTED}
t₀, t₁ = icnf.tspan
Δt = abs(t₁ - t₀)
Expand Down Expand Up @@ -124,17 +124,17 @@ end

function inference_sol(
icnf::AbstractICNF{T, <:VectorMode, INPLACE, COND, AUGMENTED, STEER, NORM_Z_AUG},
mode::Mode,
mode::Mode{REG},
prob::SciMLBase.AbstractODEProblem{<:AbstractVector{<:Real}, NTuple{2, T}, INPLACE},
) where {T <: AbstractFloat, INPLACE, COND, AUGMENTED, STEER, NORM_Z_AUG}
) where {T <: AbstractFloat, INPLACE, COND, AUGMENTED, STEER, NORM_Z_AUG, REG}
n_aug = n_augment(icnf, mode)
fsol = base_sol(icnf, prob)
z = fsol[begin:(end - n_aug - 1)]
Δlogp = fsol[(end - n_aug)]
augs = fsol[(end - n_aug + 1):end]
logpz = oftype(Δlogp, Distributions.logpdf(icnf.basedist, z))
logp̂x = logpz - Δlogp
Ȧ = if (NORM_Z_AUG && AUGMENTED)
Ȧ = if NORM_Z_AUG && AUGMENTED && REG
n_aug_input = n_augment_input(icnf)
z_aug = z[(end - n_aug_input + 1):end]
LinearAlgebra.norm(z_aug)
Expand All @@ -146,17 +146,17 @@ end

function inference_sol(
icnf::AbstractICNF{T, <:MatrixMode, INPLACE, COND, AUGMENTED, STEER, NORM_Z_AUG},
mode::Mode,
mode::Mode{REG},
prob::SciMLBase.AbstractODEProblem{<:AbstractMatrix{<:Real}, NTuple{2, T}, INPLACE},
) where {T <: AbstractFloat, INPLACE, COND, AUGMENTED, STEER, NORM_Z_AUG}
) where {T <: AbstractFloat, INPLACE, COND, AUGMENTED, STEER, NORM_Z_AUG, REG}
n_aug = n_augment(icnf, mode)
fsol = base_sol(icnf, prob)
z = fsol[begin:(end - n_aug - 1), :]
Δlogp = fsol[(end - n_aug), :]
augs = fsol[(end - n_aug + 1):end, :]
logpz = oftype(Δlogp, Distributions.logpdf(icnf.basedist, z))
logp̂x = logpz - Δlogp
Ȧ = transpose(if (NORM_Z_AUG && AUGMENTED)
Ȧ = transpose(if NORM_Z_AUG && AUGMENTED && REG
n_aug_input = n_augment_input(icnf)
z_aug = z[(end - n_aug_input + 1):end, :]
LinearAlgebra.norm.(eachcol(z_aug))
Expand Down Expand Up @@ -526,7 +526,7 @@ function (icnf::AbstractICNF{<:AbstractFloat, <:ComputeMode, INPLACE, false})(
ps::Any,
st::NamedTuple,
) where {INPLACE}
return first(inference(icnf, TrainMode(), xs, ps, st)), st
return first(inference(icnf, TrainMode{false}(), xs, ps, st)), st
end

function (icnf::AbstractICNF{<:AbstractFloat, <:ComputeMode, INPLACE, true})(
Expand All @@ -535,5 +535,5 @@ function (icnf::AbstractICNF{<:AbstractFloat, <:ComputeMode, INPLACE, true})(
st::NamedTuple,
) where {INPLACE}
xs, ys = xs_ys
return first(inference(icnf, TrainMode(), xs, ys, ps, st)), st
return first(inference(icnf, TrainMode{false}(), xs, ys, ps, st)), st
end
Loading
Loading