You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I've noticed some type instability when trying to use this (very nice) package. Can you please help me understand why?
Here’s a simple example: I define a model called GaussianModel which takes a single parameter as input. This model can also be evaluated to return the value of its parameter. Then, I'd like to differentiate the function logprob, which takes the model as input using implicit gradients.
using LinearAlgebra, Random, Zygote
abstract type Model end
mutable struct GaussianModel{T<:AbstractFloat} <: Model
σ::T
end
(model::GaussianModel)() = model.σ
function logprob(x::T, y::T, model::GaussianModel{T}) where {T<:AbstractFloat}
σ = model()
return -(y - x)^2 / (2σ^2) - log(2 * π * σ^2) / 2
end
Now, although this
x = 0.2
y = 0.1
mymodel = GaussianModel(0.5)
logprob(x, y, mymodel)
gradient(model -> logprob(x, y, model), mymodel)
gives the right result, this
@code_warntype gradient(model -> logprob(x, y, model), mymodel)
Hi,
I've noticed some type instability when trying to use this (very nice) package. Can you please help me understand why?
Here’s a simple example: I define a model called GaussianModel which takes a single parameter as input. This model can also be evaluated to return the value of its parameter. Then, I'd like to differentiate the function logprob, which takes the model as input using implicit gradients.
Now, although this
gives the right result, this
gives the following type instability
The text was updated successfully, but these errors were encountered: