     // Cholesky factor of proposal distribution for each data point, used by the Metropolis algorithm. The proposal
     // covariance matrix for each data point is Covar_i = PropChol_i * transpose(PropChol_i).
     dim_cholfactor = p * p - ((p - 1) * p) / 2; // cholesky factor is a lower-diagonal matrix
-    thrust::host_vector<double> h_prop_cholfact(n * dim_chol_factor);
+    thrust::host_vector<double> h_prop_cholfact(n * dim_cholfactor);
     thrust::fill(h_prop_cholfact.begin(), h_prop_cholfact.end(), 0.0);
     
 	// Create simulated characteristics and data

// Function to compute the conditional log-density of the chi values given theta
__device__ __host__
double logdensity_pop(double* chi, double* theta) {
    // right now this is just an independent p-dimensional gaussian distribution, for simplicity
    double logdensity = 0.0;
    for (int j=0; j<c_p; j++) {
        double mu_j = theta[j];
        double var_j = theta[j + c_p];
        double centered_chi_j = chi[j] - mu_j;
        logdensity += -0.5 * log(var_j) - 0.5 * centered_chi_j * centered_chi_j / var_j;
    }
    return logdensity;
}

// Initialize the random number generator state


        // Finally, adapt the Cholesky factor of the proposal distribution
        // TODO: check that the ratio is finite before doing this step
        double unit_norm = 0.0;
        for (int j=0; j<c_p; j++) {
            unit_norm += snorm_deviate[j] * snorm_deviate[j];
        }
        unit_norm = sqrt(unitnorm);
        double decay_sequence = 1.0 / pow(current_iter, c_decay_rate);
        scaled_coef = sqrt(decay_sequence * fabs(ratio - c_target_rate)) / unit_norm;
        for (int j=0; j<c_p; j++) {
            scaled_proposal[j] *= scaled_coef;
        }
        bool downdate = (ratio < c_target_rate);
        CholUpdateR1(cholfactor, scaled_proposal, downdate);
        
        // copy cholesky factor for this data point back to global memory
        cholfact_index = 0
        for (int j=0; j<dim_cholfactor; j++) {
            prop_cholfact[n * j + i] = cholfactor[j];
        }
	}
}

