# Row_vector multiplication

Hi,

I have found the following piece of Stan code and I’m struggling to understand how the following multiplication can work.

So, here,

1. beta_delta is a row_vector[p+q]
2. temp_delta is also a row_vector[p+q] and
3. sigma_delta is a matrix[N,N]
sigma_delta[i, j] = beta_delta .* temp_delta * temp_delta';

How the multiplication of some row_vector can produce a single value to fit in a matrix?

I was looking here but I couldn’t find the way.

The whole loop is below and the code comes from the “Guidelines for the Bayesian calibration of building energy models”

// diagonal elements of sigma_eta
sigma_eta = diag_matrix(rep_vector((1 / lambda_eta), N));

// off-diagonal elements of sigma_eta
for (i in 1:(N-1)) {
for (j in (i+1):N) {
temp_eta = xt[i] - xt[j];
sigma_eta[i, j] = beta_eta .* temp_eta * temp_eta';  // row_vector .* row_vector  * row_vector'
sigma_eta[i, j] = exp(-sigma_eta[i, j]) / lambda_eta;
sigma_eta[j, i] = sigma_eta[i, j];
}
}

Thanks

This is a multiplication of a row_vector with a vector (the second argument has a ' sign which is a transpose operation). So this is essentially a dot product that produces a single value.

3 Likes