stan-dev / stan-dev/stan

Merge Transformed Parameters and Model Blocks

Open
#2,662 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature language
Dominant language
C++
Stars
2.8k
Forks
388
Avg merge
2d 17h
Merged PRs (30d)
15

Description

Summary:

The point of this feature request is to merge the transformed parameters and model blocks, as the added complexity of having them be separate entities seems unnecessary.

Description:

The idea will be to make the following changes to the language:

  • Make global variables in model block be in scope in generated quantities block, as would be the case for transformed parameters;
  • Write them to your sample, as you would for transformed parameters;
  • At this point, there is not more distinction between the transformed parameters and model blocks except that target is in scope in model but not transformed parameters, so we might as well merge the two blocks.

Observe that the current behaviour can be reproduced by using a local scope, to ensure that variables do not get written to the sample or are in scope in generated quantities.

Reproducible Steps:

Run

model { real x = 1; } generated quantities { print(x); }

Current Output:

This throws an error as x is not in scope in generated quantities. Nor does it get written to the sample.
This is confusing.

Expected Output:

No error. A program that prints 1 in the generated quantities phase and writes 1 to the sample.

Additional Information:

People I have spoken to have been confused about the distinction between transformed parameters and model and have been confused that model level global vars are not in scope in the generated quantities block.

The scoping mechanism should moreover control whether a variable ends up in the sample.

Current Version:

v2.18.0

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

The issue provides no implementation files or tests to begin with. Start by reviewing Stan's current transformed parameters and model scoping and sample-output behavior, using the supplied model/generated quantities example as the acceptance case. Done means model-block variables are available in generated quantities, written to the sample, and the two blocks are merged without removing model access to target.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.