Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logpdf support #762

Merged
merged 20 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions include/boost/math/distributions/arcsine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,34 @@ namespace boost
return result;
} // pdf

template <class RealType, class Policy>
inline RealType logpdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& xx)
{
BOOST_FPU_EXCEPTION_GUARD
BOOST_MATH_STD_USING // For ADL of std functions.

static const char* function = "boost::math::logpdf(arcsine_distribution<%1%> const&, %1%)";

RealType lo = dist.x_min();
RealType hi = dist.x_max();
RealType x = xx;

// Argument checks:
RealType result = 0;
if (false == arcsine_detail::check_dist_and_x(
function,
lo, hi, x,
&result, Policy()))
{
return result;
}

using boost::math::constants::pi;
using boost::math::constants::half;
result = -half<RealType>() * log(-(x - 1) * x) - log(pi<RealType>());
mborland marked this conversation as resolved.
Show resolved Hide resolved
return result;
} // logpdf

template <class RealType, class Policy>
inline RealType cdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& x)
{ // Cumulative Distribution Function arcsine.
Expand Down
6 changes: 6 additions & 0 deletions include/boost/math/distributions/detail/derived_accessors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ inline typename Distribution::value_type pdf(const Distribution& dist, const Rea
return pdf(dist, static_cast<value_type>(x));
}
template <class Distribution, class RealType>
inline typename Distribution::value_type logpdf(const Distribution& dist, const RealType& x)
{
typedef typename Distribution::value_type value_type;
return logpdf(dist, static_cast<value_type>(x));
}
template <class Distribution, class RealType>
inline typename Distribution::value_type cdf(const Distribution& dist, const RealType& x)
{
typedef typename Distribution::value_type value_type;
Expand Down