1#ifndef STAN_MATH_OPENCL_PRIM_PARETO_TYPE_2_LPDF_HPP
2#define STAN_MATH_OPENCL_PRIM_PARETO_TYPE_2_LPDF_HPP
33template <
bool propto,
typename T_y_cl,
typename T_loc_cl,
typename T_scale_cl,
36 T_y_cl, T_loc_cl, T_scale_cl, T_shape_cl>* =
nullptr,
38 T_shape_cl>* =
nullptr>
40 const T_y_cl& y,
const T_loc_cl& mu,
const T_scale_cl& lambda,
41 const T_shape_cl& alpha) {
42 static constexpr const char* function =
"pareto_type_2_lpdf(OpenCL)";
43 using T_partials_return
49 mu,
"Scale parameter", alpha,
"Shape parameter",
51 const size_t N =
max_size(y, mu, lambda, alpha);
66 const auto& mu_val =
value_of(mu_col);
67 const auto& lambda_val =
value_of(lambda_col);
68 const auto& alpha_val =
value_of(alpha_col);
70 auto y_minus_mu = y_val - mu_val;
72 =
check_cl(function,
"Random variable minus location parameter",
73 y_minus_mu,
"greater or equal than zero");
74 auto y_ge_mu = y_minus_mu >= 0;
75 auto check_lambda_positive_finite
76 =
check_cl(function,
"Scale parameter", lambda_val,
"positive finite");
77 auto lambda_positive_finite =
isfinite(lambda_val) && lambda_val > 0;
78 auto check_alpha_positive_finite
79 =
check_cl(function,
"Shape parameter", alpha_val,
"positive finite");
80 auto alpha_positive_finite =
isfinite(alpha_val) && alpha_val > 0;
84 auto logp1 = static_select<include_summand<propto, T_shape_cl>::value>(
86 auto logp2 = static_select<include_summand<propto, T_scale_cl>::value>(
87 logp1 -
log(lambda_val), logp1);
91 logp2 -
elt_multiply(alpha_val + 1.0, log1p_scaled_diff), logp2));
93 auto inv_sum =
elt_divide(1.0, lambda_val + y_minus_mu);
96 auto deriv_y_mu = inv_sum + alpha_div_sum;
100 auto deriv_alpha =
elt_divide(1.0, alpha_val) - log1p_scaled_diff;
108 results(check_y_ge_mu, check_lambda_positive_finite,
109 check_alpha_positive_finite, logp_cl, y_deriv_cl, mu_deriv_cl,
110 lambda_deriv_cl, alpha_deriv_cl)
111 =
expressions(y_ge_mu, lambda_positive_finite, alpha_positive_finite,
123 partials<0>(ops_partials) = std::move(y_deriv_cl);
126 partials<1>(ops_partials) = std::move(mu_deriv_cl);
129 partials<2>(ops_partials) = std::move(lambda_deriv_cl);
132 partials<3>(ops_partials) = std::move(alpha_deriv_cl);
134 return ops_partials.build(logp);
Represents an arithmetic matrix on the OpenCL device.
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
isfinite_< as_operation_cl_t< T > > isfinite(T &&a)
auto check_cl(const char *function, const char *var_name, T &&y, const char *must_be)
Constructs a check on opencl matrix or expression.
results_cl< T_results... > results(T_results &&... results)
Deduces types for constructing results_cl object.
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
elt_divide_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_divide(T_a &&a, T_b &&b)
auto constant(const T a, int rows, int cols)
Matrix of repeated values in kernel generator expressions.
calc_if_< true, as_operation_cl_t< T > > calc_if(T &&a)
auto colwise_sum(T &&a)
Column wise sum - reduction of a kernel generator expression.
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
return_type_t< T_y_cl, T_loc_cl, T_scale_cl, T_shape_cl > pareto_type_2_lpdf(const T_y_cl &y, const T_loc_cl &mu, const T_scale_cl &lambda, const T_shape_cl &alpha)
Returns the log PMF of the Pareto type 2 distribution.
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
require_all_t< is_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_prim_or_rev_kernel_expression_t
Require type satisfies is_prim_or_rev_kernel_expression.
require_any_not_t< is_stan_scalar< std::decay_t< Types > >... > require_any_not_stan_scalar_t
Require at least one of the types do not satisfy is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
T1 static_select(T1 &&a, T2 &&b)
Returns one of the arguments that can be of different type, depending on the compile time condition.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
fvar< T > log1p(const fvar< T > &x)
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
typename partials_return_type< Args... >::type partials_return_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
bool isnan(const stan::math::var &a)
Checks if the given number is NaN.
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...