primarycensored
Loading...
Searching...
No Matches
nonparametric.stan File Reference

Functions in this File

real pstep_lcdf (real t, vector boundaries, vector pmf)
 
vector hazards_to_pmf (vector hazards)
 
real phazard_lcdf (real t, vector boundaries, vector hazards)
 
vector primary_lcdf_vec (vector p, int primary_id, array[] real primary_params, data real pwindow)
 
real discretestep_lcdf (data real d, vector boundaries, vector pmf, int primary_id, array[] real primary_params, data real pwindow)
 
real discretehazard_lcdf (data real d, vector boundaries, vector hazards, int primary_id, array[] real primary_params, data real pwindow)
 

Function Documentation

◆ discretehazard_lcdf()

real discretehazard_lcdf ( data real d,
vector boundaries,
vector hazards,
int primary_id,
array[]real primary_params,
data real pwindow )

Primary event censored log CDF for a discrete-hazard delay

Wrapper that converts hazards to a PMF and delegates to discretestep_lcdf. Provides the analytic CDF for dist_id == 27.

Parameters
dDelay (observation point)
boundariesVector of K+1 step boundaries
hazardsVector of K hazards in [0, 1] with hazards[K] = 1
primary_idPrimary distribution identifier
primary_paramsPrimary distribution parameters
pwindowPrimary event window width
Returns
log(F_obs(d)) under convolution with the given primary

Definition at line 211 of file nonparametric.stan.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ discretestep_lcdf()

real discretestep_lcdf ( data real d,
vector boundaries,
vector pmf,
int primary_id,
array[]real primary_params,
data real pwindow )

Primary event censored log CDF for a step delay (vectorised analytic)

Computes log(F_obs(d)) where F_obs(d) = integral_q^d F_step(u) f_primary(d - u) du, q = d - pwindow. Using f_primary(d - u) du = -d F_primary(d - u), the integral on each sub-interval [lo, hi] where F_step is constant becomes cumulative * (F_primary(d - lo) - F_primary(d - hi)). The lo/hi/cumulative vectors are built in one pass; f_lo and f_hi come from two vectorised primary_lcdf_vec calls; an active mask zeros out empty sub-intervals; the per-bin contributions are reduced via dot_product. The tail [boundaries[K+1], d] (where F_step = 1) is added in a single closed-form term, no loop.

Boundary case: when the integration support lies entirely at or below boundaries[2] the only sub-interval that overlaps is bin 1 (with cum_before = 0) and the tail is empty, so the integral is structurally zero. We return negative_infinity() directly to keep log(0) off the autodiff tape; the value has no parameter dependence in this regime so the gradient is zero, and downstream log_diff_exp(a, -inf) evaluates cleanly to a.

Parameters
dDelay (observation point)
boundariesVector of K+1 step boundaries
pmfStep PMF of length K
primary_idPrimary distribution identifier
primary_paramsPrimary distribution parameters
pwindowPrimary event window width
Returns
log(F_obs(d)) under convolution with the given primary

Definition at line 137 of file nonparametric.stan.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hazards_to_pmf()

vector hazards_to_pmf ( vector hazards)

Convert discrete hazards to a PMF

Each entry satisfies pmf[i] = hazards[i] * prod_{j < i} (1 - hazards[j]). The last hazard must equal 1 so the PMF sums to 1 (caller's responsibility). One log1m, one cumulative_sum, one exp – no per-bin loop on the autodiff tape.

Parameters
hazardsVector of K hazards in [0, 1], with hazards[K] = 1
Returns
PMF vector of length K

Definition at line 55 of file nonparametric.stan.

Here is the caller graph for this function:

◆ phazard_lcdf()

real phazard_lcdf ( real t,
vector boundaries,
vector hazards )

Log CDF of a discrete-hazard distribution

Sibling of pstep_lcdf for the hazard parameterisation; converts hazards to the implied PMF then dispatches to pstep_lcdf.

Parameters
tEvaluation point
boundariesVector of K+1 boundaries (strictly increasing)
hazardsVector of K hazards in [0, 1] with hazards[K] = 1
Returns
log(F_step(t)) under the implied PMF.

Definition at line 77 of file nonparametric.stan.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ primary_lcdf_vec()

vector primary_lcdf_vec ( vector p,
int primary_id,
array[]real primary_params,
data real pwindow )

Vectorised primary log CDF

Element-wise wrapper around primary_lcdf. Lets the analytic step convolution pull f_lo and f_hi out of one pair of vector calls without per-bin branching at the reduction site.

Parameters
pVector of primary event times in [0, pwindow]
primary_idPrimary distribution identifier
primary_paramsDistribution parameters
pwindowPrimary event window width
Returns
Vector of log(F_primary(p))

Definition at line 95 of file nonparametric.stan.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pstep_lcdf()

real pstep_lcdf ( real t,
vector boundaries,
vector pmf )

Non-parametric step CDF and hazard conversion utilities.

The step CDF is defined by K intervals and a PMF over those intervals. boundaries is a vector of length K+1 giving interval endpoints [boundaries[1], boundaries[2]), ..., [boundaries[K], boundaries[K+1]). pmf is a simplex of length K giving the probability mass in each interval. The hazard parameterisation replaces pmf with discrete hazards in [0, 1] whose final entry is 1 so the implied PMF sums to 1. Log CDF of a piecewise-constant (step) distribution

Vectorised PMF reduction via cumulative_sum. The bin-search index runs on data-level inputs (t, boundaries) and never appears on the autodiff tape, so a small data-only loop is kept here.

Parameters
tEvaluation point
boundariesVector of K+1 interval endpoints (strictly increasing)
pmfSimplex of K probabilities, one per interval (must sum to 1)
Returns
log(F_step(t)): negative_infinity() if t < boundaries[1], 0 if t >= boundaries[K + 1], log of the cumulative mass through the bin containing t otherwise.

Definition at line 28 of file nonparametric.stan.

Here is the caller graph for this function: