stan-dev / stan-dev/math

Feature request: vectorized phi()

Open
#3,383 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

distributions feature good first issue
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Stan has a vectorized $\Phi(x)$ (standard cumulative distribution function) but lacks a corresponding vectorized $\varphi(x)$ (standard normal density). You can't get this using std_normal_lpdf(), as it sums the log density values; I'm asking for something that returns a vectorized result.

One use case for a vectorized $\Phi(x)$ is in computing a quasi-hinge function based on $\Phi(x)$:

$h(x) = x \Phi(x) + \varphi(x)$.

This function has range $(0,\infty)$ with $h(x) \to 0$ as $x\to -\infty$, $h(x)/x \to 1$ as $x\to \infty$, and $h'(x) = \Phi(x)$.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing vectorized Phi() implementation and std_normal_lpdf(), focusing on how vectorized values and summed log densities differ. Define done as a vectorized varphi() that returns one standard-normal density value per input rather than a summed log density, and compare its behavior with the requested quasi-hinge use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.