Skip to content

Commit

Permalink
more notes
Browse files Browse the repository at this point in the history
  • Loading branch information
cscherrer committed Oct 5, 2021
1 parent e21b904 commit 870bd51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/approximations/gausslaguerre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function log_approximate(approximation::GaussLaguerreQuadrature, fn::Function)
# calculate the ln(wi) + logf(xi) terms
logresult = Vector{T}(undef, p)
for i = 1:p
# TODO: Can this have @inbounds?
logresult[i] = logw[i] + fn(x[i])
end

Expand All @@ -58,4 +59,4 @@ end

function Base.:(==)(left::GaussLaguerreQuadrature{R}, right::GaussLaguerreQuadrature{R}) where R
return getlength(left) == getlength(right)
end
end
7 changes: 5 additions & 2 deletions src/approximations/importance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export ImportanceSamplingApproximation
using Random
using StatsBase

# TODO: Document other fields
"""
ImportanceSamplingApproximation
Expand Down Expand Up @@ -33,6 +34,8 @@ end
getsamples(approximation::ImportanceSamplingApproximation, distribution) = getsamples(approximation, distribution, approximation.nsamples)
getsamples(approximation::ImportanceSamplingApproximation, distribution, nsamples) = rand(approximation.rng, distribution, nsamples)

# TODO: What's the type of `distribution`? Generic is fine, but at least a
# comment would be helpful
function approximate_meancov(approximation::ImportanceSamplingApproximation, g::Function, distribution)

# We use preallocated arrays to sample and compute transformed samples and weightd
Expand Down Expand Up @@ -76,7 +79,7 @@ function approximate_meancov(approximation::ImportanceSamplingApproximation, g::
if isnan(m) || isnan(v) || isinf(m) || iszero(v)
return mean(distribution), var(distribution)
end

return m, v

end
end

1 comment on commit 870bd51

@bvdmitri
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, the whole approximation/ folder is outdated and we don't really use anything from that, but GaussHermite approximation for GCV node. I even have a very old issue about that #27 . I think its a good place for improvement, the main method that needs to be supported is approximate_meancov. Maybe there is a package for all of these methods that do support smith like approximate_meancov. approximate_meancov computes mean and cov of point wise multiplication of some Function and some distribution.

Please sign in to comment.