Skip to content

Commit 3f0b2a6

Browse files
authored
Merge pull request #1426 from stan-dev/rename-sampling-distribution
Rename sampling statement to distribution statement
2 parents ac04021 + 9f9f557 commit 3f0b2a6

File tree

6 files changed

+82
-71
lines changed

6 files changed

+82
-71
lines changed

src/analysis_and_optimization/Pedantic_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ let maybe_jacobian_adjustment_warnings (mir : Program.Typed.t) =
388388
Set.Poly.map
389389
~f:(fun loc ->
390390
( loc
391-
, "Left-hand side of sampling statement (~) may contain a non-linear \
391+
, "Left-hand side of distribution statement (~) may contain a non-linear \
392392
transform of a parameter or local variable. If it does, you need to \
393393
include a target += statement with the log absolute determinant of \
394394
the Jacobian of the transform." ))

src/frontend/Semantic_error.ml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ module StatementError = struct
369369
| LValueMultiIndexing
370370
| LValueTupleUnpackDuplicates of Ast.untyped_lval list
371371
| LValueTupleReadAndWrite of string list
372-
| InvalidSamplingPDForPMF
373-
| InvalidSamplingCDForCCDF of string
374-
| InvalidSamplingNoSuchDistribution of string * bool
372+
| InvalidTildePDForPMF
373+
| InvalidTildeCDForCCDF of string
374+
| InvalidTildeNoSuchDistribution of string * bool
375375
| TargetPlusEqualsOutsideModelOrLogProb
376376
| InvalidTruncationCDForCCDF of
377377
(UnsizedType.autodifftype * UnsizedType.t) list
@@ -431,23 +431,24 @@ module StatementError = struct
431431
Fmt.pf ppf
432432
"Target can only be accessed in the model block or in definitions of \
433433
functions with the suffix _lp."
434-
| InvalidSamplingPDForPMF ->
434+
| InvalidTildePDForPMF ->
435435
Fmt.pf ppf
436436
"~ statement should refer to a distribution without its \
437437
\"_lpdf/_lupdf\" or \"_lpmf/_lupmf\" suffix.\n\
438438
For example, \"target += normal_lpdf(y, 0, 1)\" should become \"y ~ \
439439
normal(0, 1).\""
440-
| InvalidSamplingCDForCCDF name ->
440+
| InvalidTildeCDForCCDF name ->
441441
Fmt.pf ppf
442-
"CDF and CCDF functions may not be used with sampling notation. Use \
443-
target += %s_log(...) instead."
442+
"CDF and CCDF functions may not be used with distribution notation \
443+
(~). Use target += %s_log(...) instead."
444444
name
445-
| InvalidSamplingNoSuchDistribution (name, true) ->
445+
| InvalidTildeNoSuchDistribution (name, true) ->
446446
Fmt.pf ppf
447-
"Ill-typed arguments to '~' statement. No function '%s_lpmf' or \
448-
'%s_lpdf' was found when looking for distribution '%s'."
447+
"Ill-typed arguments to distribution statement (~). No function \
448+
'%s_lpmf' or '%s_lpdf' was found when looking for distribution \
449+
'%s'."
449450
name name name
450-
| InvalidSamplingNoSuchDistribution (name, false) ->
451+
| InvalidTildeNoSuchDistribution (name, false) ->
451452
Fmt.pf ppf
452453
"Ill-typed arguments to '~' statement. No function '%s_lpdf' was \
453454
found when looking for distribution '%s'."
@@ -708,15 +709,15 @@ let cannot_assign_duplicate_unpacking loc names =
708709
let cannot_access_assigning_var loc names =
709710
StatementError (loc, StatementError.LValueTupleReadAndWrite names)
710711

711-
let invalid_sampling_pdf_or_pmf loc =
712-
StatementError (loc, StatementError.InvalidSamplingPDForPMF)
712+
let invalid_tilde_pdf_or_pmf loc =
713+
StatementError (loc, StatementError.InvalidTildePDForPMF)
713714

714-
let invalid_sampling_cdf_or_ccdf loc name =
715-
StatementError (loc, StatementError.InvalidSamplingCDForCCDF name)
715+
let invalid_tilde_cdf_or_ccdf loc name =
716+
StatementError (loc, StatementError.InvalidTildeCDForCCDF name)
716717

717-
let invalid_sampling_no_such_dist loc name is_int =
718+
let invalid_tilde_no_such_dist loc name is_int =
718719
StatementError
719-
(loc, StatementError.InvalidSamplingNoSuchDistribution (name, is_int))
720+
(loc, StatementError.InvalidTildeNoSuchDistribution (name, is_int))
720721

721722
let target_plusequals_outside_model_or_logprob loc =
722723
StatementError (loc, StatementError.TargetPlusEqualsOutsideModelOrLogProb)

src/frontend/Semantic_error.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ val cannot_assign_duplicate_unpacking :
114114
Location_span.t -> Ast.untyped_lval list -> t
115115

116116
val cannot_access_assigning_var : Location_span.t -> string list -> t
117-
val invalid_sampling_pdf_or_pmf : Location_span.t -> t
118-
val invalid_sampling_cdf_or_ccdf : Location_span.t -> string -> t
119-
val invalid_sampling_no_such_dist : Location_span.t -> string -> bool -> t
117+
val invalid_tilde_pdf_or_pmf : Location_span.t -> t
118+
val invalid_tilde_cdf_or_ccdf : Location_span.t -> string -> t
119+
val invalid_tilde_no_such_dist : Location_span.t -> string -> bool -> t
120120
val target_plusequals_outside_model_or_logprob : Location_span.t -> t
121121

122122
val invalid_truncation_cdf_or_ccdf :

src/frontend/Typechecker.ml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,43 +1220,43 @@ let check_target_pe loc cf tenv e =
12201220
verify_target_pe_expr_type loc te;
12211221
mk_typed_statement ~stmt:(TargetPE te) ~return_type:Incomplete ~loc
12221222

1223-
(* tilde/sampling notation*)
1224-
let verify_sampling_pdf_pmf id =
1223+
(* tilde/distribution notation*)
1224+
let verify_distribution_pdf_pmf id =
12251225
if
12261226
String.(
12271227
is_suffix id.name ~suffix:"_lpdf"
12281228
|| is_suffix id.name ~suffix:"_lpmf"
12291229
|| is_suffix id.name ~suffix:"_lupdf"
12301230
|| is_suffix id.name ~suffix:"_lupmf")
1231-
then Semantic_error.invalid_sampling_pdf_or_pmf id.id_loc |> error
1231+
then Semantic_error.invalid_tilde_pdf_or_pmf id.id_loc |> error
12321232

1233-
let verify_sampling_cdf_ccdf loc id =
1233+
let verify_distribution_cdf_ccdf loc id =
12341234
if
12351235
String.(
12361236
is_suffix id.name ~suffix:"_cdf" || is_suffix id.name ~suffix:"_ccdf")
1237-
then Semantic_error.invalid_sampling_cdf_or_ccdf loc id.name |> error
1237+
then Semantic_error.invalid_tilde_cdf_or_ccdf loc id.name |> error
12381238

12391239
(* Target+= can only be used in model and functions with right suffix (same for tilde etc) *)
1240-
let verify_valid_sampling_pos loc cf =
1240+
let verify_valid_distribution_pos loc cf =
12411241
if in_lp_function cf || cf.current_block = Model then ()
12421242
else Semantic_error.target_plusequals_outside_model_or_logprob loc |> error
12431243

1244-
let check_sampling_distribution loc tenv id arguments =
1244+
let check_tilde_distribution loc tenv id arguments =
12451245
let name = id.name in
12461246
let argumenttypes = List.map ~f:arg_type arguments in
1247-
let name_w_suffix_sampling_dist suffix =
1247+
let name_w_suffix_dist suffix =
12481248
SignatureMismatch.matching_function tenv (name ^ suffix) argumenttypes in
1249-
let sampling_dists =
1250-
List.map ~f:name_w_suffix_sampling_dist Utils.distribution_suffices in
1249+
let distributions =
1250+
List.map ~f:name_w_suffix_dist Utils.distribution_suffices in
12511251
match
1252-
List.min_elt sampling_dists ~compare:SignatureMismatch.compare_match_results
1252+
List.min_elt distributions ~compare:SignatureMismatch.compare_match_results
12531253
with
12541254
| Some (UniqueMatch (_, _, p)) ->
12551255
Promotion.promote_list arguments p
12561256
(* real return type is enforced by [verify_fundef_dist_rt] *)
12571257
| None | Some (SignatureErrors ([], _)) ->
12581258
(* Function is non existent *)
1259-
Semantic_error.invalid_sampling_no_such_dist loc name
1259+
Semantic_error.invalid_tilde_no_such_dist loc name
12601260
(List.hd_exn argumenttypes |> snd |> UnsizedType.is_int_type)
12611261
|> error
12621262
| Some (AmbiguousMatch sigs) ->
@@ -1281,7 +1281,7 @@ let is_cumulative_density_defined tenv id arguments =
12811281
| _ -> false in
12821282
valid_arg_types_for_suffix "_lcdf" && valid_arg_types_for_suffix "_lccdf"
12831283

1284-
let verify_sampling_cdf_defined loc tenv id truncation args =
1284+
let verify_distribution_cdf_defined loc tenv id truncation args =
12851285
let check e =
12861286
if not (is_cumulative_density_defined tenv id (e :: args)) then
12871287
Semantic_error.invalid_truncation_cdf_or_ccdf loc
@@ -1308,13 +1308,13 @@ let check_tilde loc cf tenv distribution truncation arg args =
13081308
let tes = List.map ~f:(check_expression cf tenv) args in
13091309
let ttrunc = check_truncation cf tenv truncation in
13101310
verify_identifier distribution;
1311-
verify_sampling_pdf_pmf distribution;
1312-
verify_valid_sampling_pos loc cf;
1313-
verify_sampling_cdf_ccdf loc distribution;
1311+
verify_distribution_pdf_pmf distribution;
1312+
verify_valid_distribution_pos loc cf;
1313+
verify_distribution_cdf_ccdf loc distribution;
13141314
let promoted_args =
1315-
check_sampling_distribution loc tenv distribution (te :: tes) in
1315+
check_tilde_distribution loc tenv distribution (te :: tes) in
13161316
let te, tes = (List.hd_exn promoted_args, List.tl_exn promoted_args) in
1317-
verify_sampling_cdf_defined loc tenv distribution ttrunc tes;
1317+
verify_distribution_cdf_defined loc tenv distribution ttrunc tes;
13181318
let stmt = Tilde {arg= te; distribution; args= tes; truncation= ttrunc} in
13191319
mk_typed_statement ~stmt ~loc ~return_type:Incomplete
13201320

test/integration/bad/stanc.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ Semantic error in 'ccdf-sample.stan', line 5, column 2 to column 24:
429429
6: }
430430
-------------------------------------------------
431431

432-
CDF and CCDF functions may not be used with sampling notation. Use target += weibull_ccdf_log(...) instead.
432+
CDF and CCDF functions may not be used with distribution notation (~). Use target += weibull_ccdf_log(...) instead.
433433
$ ../../../../install/default/bin/stanc cdf-sample.stan
434434
Semantic error in 'cdf-sample.stan', line 5, column 2 to column 23:
435435
-------------------------------------------------
@@ -440,7 +440,7 @@ Semantic error in 'cdf-sample.stan', line 5, column 2 to column 23:
440440
6: }
441441
-------------------------------------------------
442442

443-
CDF and CCDF functions may not be used with sampling notation. Use target += normal_cdf_log(...) instead.
443+
CDF and CCDF functions may not be used with distribution notation (~). Use target += normal_cdf_log(...) instead.
444444
$ ../../../../install/default/bin/stanc complex_mat_bad.stan
445445
Semantic error in 'complex_mat_bad.stan', line 7, column 2 to column 18:
446446
-------------------------------------------------

test/integration/cli-args/warn-pedantic/stanc.expected

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -463,54 +463,64 @@ Warning: The parameter m has 12 priors.
463463
Warning: The parameter a has 2 priors.
464464
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning1.stan
465465
Warning in 'jacobian_warning1.stan', line 7, column 2: Left-hand side of
466-
sampling statement (~) may contain a non-linear transform of a parameter
467-
or local variable. If it does, you need to include a target += statement
468-
with the log absolute determinant of the Jacobian of the transform.
466+
distribution statement (~) may contain a non-linear transform of a
467+
parameter or local variable. If it does, you need to include a target +=
468+
statement with the log absolute determinant of the Jacobian of the
469+
transform.
469470
Warning in 'jacobian_warning1.stan', line 5, column 2: Left-hand side of
470-
sampling statement (~) may contain a non-linear transform of a parameter
471-
or local variable. If it does, you need to include a target += statement
472-
with the log absolute determinant of the Jacobian of the transform.
471+
distribution statement (~) may contain a non-linear transform of a
472+
parameter or local variable. If it does, you need to include a target +=
473+
statement with the log absolute determinant of the Jacobian of the
474+
transform.
473475
Warning: The parameter y has 2 priors.
474476
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning2.stan
475477
Warning in 'jacobian_warning2.stan', line 5, column 2: Left-hand side of
476-
sampling statement (~) may contain a non-linear transform of a parameter
477-
or local variable. If it does, you need to include a target += statement
478-
with the log absolute determinant of the Jacobian of the transform.
478+
distribution statement (~) may contain a non-linear transform of a
479+
parameter or local variable. If it does, you need to include a target +=
480+
statement with the log absolute determinant of the Jacobian of the
481+
transform.
479482
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning3.stan
480483
Warning in 'jacobian_warning3.stan', line 5, column 2: Left-hand side of
481-
sampling statement (~) may contain a non-linear transform of a parameter
482-
or local variable. If it does, you need to include a target += statement
483-
with the log absolute determinant of the Jacobian of the transform.
484+
distribution statement (~) may contain a non-linear transform of a
485+
parameter or local variable. If it does, you need to include a target +=
486+
statement with the log absolute determinant of the Jacobian of the
487+
transform.
484488
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning4.stan
485489
Warning in 'jacobian_warning4.stan', line 5, column 2: Left-hand side of
486-
sampling statement (~) may contain a non-linear transform of a parameter
487-
or local variable. If it does, you need to include a target += statement
488-
with the log absolute determinant of the Jacobian of the transform.
490+
distribution statement (~) may contain a non-linear transform of a
491+
parameter or local variable. If it does, you need to include a target +=
492+
statement with the log absolute determinant of the Jacobian of the
493+
transform.
489494
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning5.stan
490495
Warning in 'jacobian_warning5.stan', line 5, column 2: Left-hand side of
491-
sampling statement (~) may contain a non-linear transform of a parameter
492-
or local variable. If it does, you need to include a target += statement
493-
with the log absolute determinant of the Jacobian of the transform.
496+
distribution statement (~) may contain a non-linear transform of a
497+
parameter or local variable. If it does, you need to include a target +=
498+
statement with the log absolute determinant of the Jacobian of the
499+
transform.
494500
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning6.stan
495501
Warning in 'jacobian_warning6.stan', line 5, column 2: Left-hand side of
496-
sampling statement (~) may contain a non-linear transform of a parameter
497-
or local variable. If it does, you need to include a target += statement
498-
with the log absolute determinant of the Jacobian of the transform.
502+
distribution statement (~) may contain a non-linear transform of a
503+
parameter or local variable. If it does, you need to include a target +=
504+
statement with the log absolute determinant of the Jacobian of the
505+
transform.
499506
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning7.stan
500507
Warning in 'jacobian_warning7.stan', line 6, column 2: Left-hand side of
501-
sampling statement (~) may contain a non-linear transform of a parameter
502-
or local variable. If it does, you need to include a target += statement
503-
with the log absolute determinant of the Jacobian of the transform.
508+
distribution statement (~) may contain a non-linear transform of a
509+
parameter or local variable. If it does, you need to include a target +=
510+
statement with the log absolute determinant of the Jacobian of the
511+
transform.
504512
Warning in 'jacobian_warning7.stan', line 5, column 2: Left-hand side of
505-
sampling statement (~) may contain a non-linear transform of a parameter
506-
or local variable. If it does, you need to include a target += statement
507-
with the log absolute determinant of the Jacobian of the transform.
513+
distribution statement (~) may contain a non-linear transform of a
514+
parameter or local variable. If it does, you need to include a target +=
515+
statement with the log absolute determinant of the Jacobian of the
516+
transform.
508517
Warning: The parameter y has 2 priors.
509518
$ ../../../../../install/default/bin/stanc --warn-pedantic jacobian_warning_user.stan
510519
Warning in 'jacobian_warning_user.stan', line 5, column 2: Left-hand side of
511-
sampling statement (~) may contain a non-linear transform of a parameter
512-
or local variable. If it does, you need to include a target += statement
513-
with the log absolute determinant of the Jacobian of the transform.
520+
distribution statement (~) may contain a non-linear transform of a
521+
parameter or local variable. If it does, you need to include a target +=
522+
statement with the log absolute determinant of the Jacobian of the
523+
transform.
514524
$ ../../../../../install/default/bin/stanc --warn-pedantic lp_fun.stan
515525
Warning: The parameter y has 2 priors.
516526
$ ../../../../../install/default/bin/stanc --warn-pedantic missing-prior-false-alarm.stan

0 commit comments

Comments
 (0)