Skip to content

Commit b2de9d9

Browse files
wrapper for conditional density
1 parent e8a94ef commit b2de9d9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

selectiveInference/src/Rcpp-randomized.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,28 @@ Rcpp::NumericVector log_density_gaussian_(double noise_scale,
3838

3939
return(result);
4040
}
41+
42+
// [[Rcpp::export]]
43+
Rcpp::NumericVector log_density_gaussian_conditional_(double noise_scale, // Scale of randomization
44+
Rcpp::NumericMatrix optimization_linear, // A_O -- linear part for optimization variables
45+
Rcpp::NumericMatrix optimization_state, // O -- optimization state -- matrix of shape (ninternal, npts)
46+
Rcpp::NumericMatrix offset) { // h -- offset in affine transform -- "p" dimensional
47+
48+
int npt = optimization_state.ncol(); // Function is vectorized
49+
int ndim = optimization_linear.nrow();
50+
int noptimization = optimization_linear.ncol();
51+
52+
Rcpp::NumericVector result(npt);
53+
54+
int ipt;
55+
for (ipt=0; ipt<npt; ipt++) {
56+
result[ipt] = log_density_gaussian_conditional(noise_scale,
57+
ndim,
58+
noptimization,
59+
(double *) optimization_linear.begin(),
60+
((double *) optimization_state.begin() + ipt * noptimization),
61+
(double *) offset.begin());
62+
}
63+
64+
return(result);
65+
}
File renamed without changes.

0 commit comments

Comments
 (0)