stanc3 icon indicating copy to clipboard operation
stanc3 copied to clipboard

Expose additional `normal_id_glm` pointwise signatures

Open andrjohns opened this issue 2 years ago • 4 comments

The current normal_id_glm signatures for use with a univariate outcome y only support matrix type inputs for x, for example:

real normal_id_glm_lpdf(real y | matrix x, real alpha, vector beta, real sigma)

For pointwise usage, it would be great to add corresponding row_vector signatures:

real normal_id_glm_lpdf(real y | row_vector x, real alpha, vector beta, real sigma)

As the current signatures require calling to_matrix() at each iteration:

generated quantities {
  vector[N] log_lik;

  for (n in 1:N) {
    log_lik[n] = normal_id_glm_lpdf(y[n] | to_matrix(x[n]), alpha, beta, sigma);
  }
}

andrjohns avatar Aug 31 '23 09:08 andrjohns

Is this just for convenience or do we expect different performance? I thought to_matrix was essentially free for eigen types

WardBrian avatar Aug 31 '23 12:08 WardBrian

Mostly convenience, since the majority of use-cases with a univariate outcome would be a single set of predictors (e.g., pointwise log-likelihood), so a real y and row_vector x combo would be more common than a real y and matrix x

andrjohns avatar Aug 31 '23 13:08 andrjohns