stan-dev / stan-dev/stan

gaussian_dlm_obs should allow nonnegative-definite matrices

Open
#2,658 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary:

Although it is not specified in the manual, gaussian_dlm_obs() gives an error if the C0 argument is nonnegative definite instead of positive definite.

Description:

The C0 argument is the prior covariance matrix for the latent state vector. It is perfectly legitimate, and sometimes useful, for C0 (likewise W) to be merely nonnegative-definite instead of positive definite.

Not sure if this should be a bug or an enhancement request, but at a minimum the manual should make it clear when nonnegative-definite is not good enough.

Reproducible Steps:

Program:

data {
  int<lower = 1> N;
  vector[N] y;
  real<lower = 0.0, upper = 1.0> rho_;
  real mu_;
  real<lower = 0.0> sigma_;
  real<lower = 0.0> sigma_h_scale_;
}
transformed data {
  matrix[1, N] yy = to_matrix(y');
  vector[2] Z_0_ = to_vector({1.0, 1.0});
  vector[2] a1_0_ = to_vector({0.0, mu_});
  matrix[2, 2] P1_0_ = diag_matrix(to_vector({square(sigma_), 0.0}));
}
parameters {
  real<lower = 0.0> raw_0_;
}
transformed parameters {
}
model {
  real sigma_h_ = raw_0_ * sigma_h_scale_;
  real phi_ = sqrt(1.0 - square(rho_));
  real H_0_ = square(sigma_h_);
  matrix[2, 2] T_0_ = diag_matrix(to_vector({phi_, 1.0}));
  matrix[2, 2] Q_0_ = diag_matrix(to_vector({square(rho_ * sigma_), 0.0}));
  raw_0_ ~ normal(0.0, 1.0) T[0.0, ];
  yy ~ gaussian_dlm_obs(to_matrix(Z_0_), T_0_, rep_matrix(H_0_, 1, 1), Q_0_, a1_0_, P1_0_);
}

data:

list(
  N=100,
  y=c(118, 123, 123, 125, 131, 103, 103, 112, 89, 99, 96, 100, 107, 80, 91, 110, 98, 115, 98, 81, 86, 82, 74, 81, 72, 95, 94, 120, 83, 59, 79, 60, 79, 81, 100, 111, 50, 112, 103, 86, 93, 106, 91, 114, 122, 82, 113, 92, 102, 99, 100, 128, 113, 96, 116, 116, 93, 123, 104, 107, 120, 114, 136, 95, 136, 140, 132, 145, 151, 139, 136, 123, 148, 115, 117, 143, 132, 118, 101, 106, 122, 119, 78, 98, 133, 109, 117, 129, 125, 112, 133, 113, 80, 128, 135, 137, 150, 141, 142, 131),
  rho_=0.1,
  mu_=100,
  sigma_=50,
  sigma_h_scale_=30)
Current Output:
Rejecting initial value:
  Error evaluating the log probability at the initial value.
Exception: gaussian_dlm_obs_lpdf: C0 is not positive definite.
Current Version:

v2.17

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 at the gaussian_dlm_obs entry point and reproduce the reported rejection with the supplied program, focusing on the C0 and W matrix arguments. Check the manual's stated requirements and the validation that produces “C0 is not positive definite”; done means the accepted behavior and documentation clearly match the intended nonnegative-definite support.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.