stan-dev / stan-dev/rstan

Broken constraint in transformed parameters block should generate a warning

Open
#521 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

From @martinmodrak on May 1, 2018 19:58

Summary:

The manual suggests that constraints in transformed parameters are designed for error checking. If this is really the case, unsatisfied constraints should not cause a silent rejection, but also a clear warning message.

Description:

Stan manual, section 6.6 (on transformed parameters block) says

Like the constraints on data, the constraints on transformed parameters is meant
to catch programming errors as well as convey programmer intent. They are not
automatically transformed in such a way as to be satisfied. What will happen if a
transformed parameter does not match its constraint is that the current parameter
values will be rejected.

However, when constraints in the transformed parameters block are not met, the sampler silently rejects and causes a divergence, which may be hard to understand for users (see eg. this discourse thread: http://discourse.mc-stan.org/t/imposing-constraint-in-transformed-parameters-block/3921). Instead, the sampler should generate a clear warning message.

Reproducible Steps:

A small reproducible example:

library(rstan)

model_code <- "
parameters {
  real a;
}

transformed parameters {
  real<lower=0> b = a;
}

model {
  b ~ normal(0,1);
}
"

fit <- stan(model_code = model_code)
Current Output:
<<SAMPLING PROGRESS>>
Warning messages:
1: There were 2008 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup 
2: Examine the pairs() plot to diagnose sampling problems
Expected Output:

A clear warning message, something like:

Warning: Attempt to assign out-of-bounds value to transformed parameter "real<lower=0> b"  Count: 2008.
Current Version:

v2.17.3

Copied from original issue: stan-dev/stan#2521

Contributor guide

No contributing guide indexed for this repository

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 with the reproducible RStan model in the issue, focusing on the transformed parameters block and its lower-bound constraint. Reproduce the silent rejection and compare it with the requested warning that identifies the constrained parameter and count. Done means the sampler reports a clear warning instead of only divergent-transition warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.