Skip to content

Commit

Permalink
added loglikelihood_lognormal, precompilation true
Browse files Browse the repository at this point in the history
  • Loading branch information
vboussange committed Mar 15, 2024
1 parent c151b81 commit ab05c8d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/PiecewiseInference.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__precompile__(false)
__precompile__()
"""
$(DocStringExtensions.README)
"""
Expand Down Expand Up @@ -52,5 +52,6 @@ module PiecewiseInference
export piecewise_loss
export inference, piecewise_ML_indep_TS, iterative_inference, get_ranges
export plot_convergence
export FIM_strouwen, FIM_yazdani, loglikelihood, estimate_σ, RSS, R2, pretty_print, loss_param_prior_from_dict, get_evidence
export FIM_strouwen, FIM_yazdani, loglikelihood, estimate_σ, RSS, R2, pretty_print, loss_param_prior_from_dict, get_evidence,
loglikelihood_lognormal
end # module
2 changes: 1 addition & 1 deletion src/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function inference(infprob;
u0s_init = _init_u0s(data, ranges)
end
# build θ, which is the parameter vector containing u0s, in the parameter space
θ = _build_θ(get_p(infprob), u0s_init, infprob)
θ = _build_θ(p0, u0s_init, infprob)

# piecewise loss
function _loss(θ, idx_rngs)
Expand Down
37 changes: 37 additions & 0 deletions src/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@ function RSS(res::InferenceResult, data_set::Array, noisedistrib::T) where T <:
return rss
end

"""
$(SIGNATURES)
calculates the log-likelihood of `data` under the assumption that it follows a Log-Normal distribution.
The Log-Normal parameters are derived from `preds`, which represents predicted values, and `σ`, which is the standard deviation.
# Arguments
- `preds::Array`: A 2D array of predicted values.
- `data::Array`: A 2D array of observed data, corresponding to the predictions.
- `σ::Number`: The standard deviation of the Log-Normal distribution, which variance-covariance matrix is assumed as `σ^2 I`
# Returns
- `Number`: The log-likelihood of the data.
# Notes
- The function only computes log-likelihood for elements where both predicted and observed data are positive.
# Example
```julia
preds = [1.0 2.0; 3.0 4.0]
data = [1.1 1.9; 2.9 4.1]
σ = [0.5, 0.5]
log_likelihood = loglikelihood_lognormal(preds, data, σ)
"""
function loglikelihood_lognormal(preds::Array, data::Array, σ::Number)
l = 0.
for i in 1:size(preds,2)
for j in 1:size(preds,1)
if preds[j,i] > 0. && data[j,i] > 0.
l += logpdf(LogNormal(log.(preds[j,i]), σ), data[j,i])
end
end
end
return l
# NOTE: pdf(MvNormal(zeros(2), σ^2 * diagm(ones(2))), [0.,0.]) ≈ pdf(Normal(0.,σ),0.)^2
end

# """
# $(SIGNATURES)

Expand Down

0 comments on commit ab05c8d

Please sign in to comment.