Skip to content

Commit

Permalink
Merge pull request #73 from Vaibhavdixit02/editbranch2
Browse files Browse the repository at this point in the history
Added first difference likelihood for Monte Carlo method
  • Loading branch information
ChrisRackauckas authored Apr 6, 2018
2 parents 943421b + a18db88 commit 96c9801
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/cost_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function (f::LogLikeLoss)(sol::DESolution)
end

function (f::LogLikeLoss)(sol::AbstractMonteCarloSolution)
distributions = f.distributions
distributions = f.data_distributions
for s in sol
fill_length = length(f.t)-length(s)
for i in 1:fill_length
Expand All @@ -141,16 +141,34 @@ function (f::LogLikeLoss)(sol::AbstractMonteCarloSolution)
# j is the size of the system
# corresponds to distributions[i,j]
vals = [s[i,j] for s in sol]
ll -= loglikelihood(f.distributions[i,j],vals)
ll -= loglikelihood(distributions[i,j],vals)
end
else
for j in 1:length(f.t)
# i is the number of time points
# j is the size of the system
# corresponds to distributions[i,j]
vals = [s[i,j] for i in 1:length(sol[1][1]), s in sol]
ll -= loglikelihood(f.distributions[j],vals)
ll -= loglikelihood(distributions[j],vals)
end
end

if f.diff_distributions != nothing
distributions = f.diff_distributions
fdll = 0
if eltype(distributions) <: UnivariateDistribution
for j in 2:length(f.t), i in 1:length(sol[1][1])
vals = [s[i,j] - s[i,j-1] for s in sol]
fdll -= logpdf(distributions[j-1,i],vals)[1]
end
else
for j in 2:length(f.t)
vals = [s[i,j] - s[i,j-1] for i in 1:length(sol[1][1]), s in sol]
fdll -= logpdf(distributions[j-1],vals)[1]
end
end
ll += f.weight*fdll
end

ll
end

0 comments on commit 96c9801

Please sign in to comment.