QR decomposition question

Hello all,

I model theta with the following:

lt += normal_lpdf(theta | C * to_vector(X[w,]),sigma_r);

where both C and X are both parameters matrices.

Now I am interested to orthogonalize C with the QR decompositions and I do the following:

parameters {
    .
    .
    real X[W,Xdim];
    matrix[num_par, Xdim] C;  
}

transformed parameters {
    .
    .
    matrix[num_par, Xdim] C_Q;       // declare the Q component of C
    matrix[Xdim, Xdim] C_R;            // declare the R component of C

    C_Q = qr_thin_Q(C) * sqrt(num_par - 1); 
    C_R = qr_thin_R(C) / sqrt(num_par - 1);
}

model {
       lt += normal_lpdf(theta | C_Q * C_R * to_vector(Xl[w,]),sigma_r); 
}

So I have two questions:

  1. Is it even correct? All examples for the QR decomposition are on data matrices and not on parameters, so I am unsure if I can use the QR decomposition as if my parameters were data.
  2. After sampling, all vales of C_R are nans. So obviously something is wrong. What am I missing?

Thanks!

I’m not sure about the theoretical justification for what you’re doing. But if you want the orthogonal components just use C_Q. Multiplying Q and R together just gets you back to C.

1 Like