Hi - I am trying to fit a weibull model on some data, but it fails. If I remove the exponent on t
and fit an exponential function it does not fail. I have looked at the simulated data from both models and it looks the way it should, so model mis-specification is not a problem. Is this NaN gradient a bug or am I doing something wrong?
Code is attached below. I have tested this code on Pumas Desktop 2.0 and also Pumas 2.2.1 on the cloud and the result is same in both.
Code with exponent - doesn't work :
using Pumas, PumasUtilities
weibull_model = @model begin
@param begin
PEmax ∈ RealDomain()
TD ∈ RealDomain(lower = 0)
POW ∈ RealDomain()
Ω ∈ PDiagDomain(3)
σ_add ∈ RealDomain(lower=0.001)
end
@random η ~ MvNormal(Ω)
@covariates BASE_SCORE
@pre begin
PEmax_i = PEmax + η[1]
TD_i = TD * exp(η[2])
POW_i = POW + η[3]
bsl_i = BASE_SCORE
end
@vars begin
score_i_t := bsl_i * (1 - PEmax_i * (1 - exp( - (t/TD_i)^POW_i )))
end
@derived begin
score_out ~ @. Normal(score_i_t, σ_add)
end
end
weibull_params = (PEmax = 0.45, TD = 4, POW = 0.1, Ω = Diagonal(fill(0.09, 3)), σ_add = 4)
weibull_sims = simobs(
weibull_model,
[Subject(id = i, covariates = (BASE_SCORE = 50, )) for i in 1:20],
weibull_params,
obstimes = [0,1,2,4,6,8,10]
)
weibull_refit_pop = Subject.(weibull_sims)
weibull_refit = fit(weibull_model, weibull_refit_pop, weibull_params, Pumas.FOCE())
Code without exponent - works :
using Pumas, PumasUtilities
weibull_model = @model begin
@param begin
PEmax ∈ RealDomain()
TD ∈ RealDomain(lower = 0)
Ω ∈ PDiagDomain(2)
σ_add ∈ RealDomain(lower=0.001)
end
@random η ~ MvNormal(Ω)
@covariates BASE_SCORE
@pre begin
PEmax_i = PEmax + η[1]
TD_i = TD * exp(η[2])
bsl_i = BASE_SCORE
end
@vars begin
score_i_t := bsl_i * (1 - PEmax_i * (1 - exp( - (t/TD_i) )))
end
@derived begin
score_out ~ @. Normal(score_i_t, σ_add)
end
end
weibull_params = (PEmax = 0.45, TD = 4, Ω = Diagonal(fill(0.09, 2)), σ_add = 4)
weibull_sims = simobs(
weibull_model,
[Subject(id = i, covariates = (BASE_SCORE = 50, )) for i in 1:20],
weibull_params,
obstimes = [0,1,2,4,6,8,10]
)
weibull_refit_pop = Subject.(weibull_sims)
weibull_refit = fit(weibull_model, weibull_refit_pop, weibull_params, Pumas.FOCE())