Skip to content

Commit 6c1a123

Browse files
author
Jelena Markovic
committed
added mean and cov of a gaussian
1 parent 690f0ea commit 6c1a123

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

selectiveInference/R/RcppExports.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
solve_QP <- function(Sigma, bound, maxiter, theta, linear_func, gradient, ever_active, nactive, kkt_tol, objective_tol, parameter_tol, max_active, kkt_stop, objective_stop, param_stop) {
5+
.Call('selectiveInference_solve_QP', PACKAGE = 'selectiveInference', Sigma, bound, maxiter, theta, linear_func, gradient, ever_active, nactive, kkt_tol, objective_tol, parameter_tol, max_active, kkt_stop, objective_stop, param_stop)
6+
}
7+
8+
solve_QP_wide <- function(X, bound, ridge_term, maxiter, theta, linear_func, gradient, X_theta, ever_active, nactive, kkt_tol, objective_tol, parameter_tol, max_active, kkt_stop, objective_stop, param_stop) {
9+
.Call('selectiveInference_solve_QP_wide', PACKAGE = 'selectiveInference', X, bound, ridge_term, maxiter, theta, linear_func, gradient, X_theta, ever_active, nactive, kkt_tol, objective_tol, parameter_tol, max_active, kkt_stop, objective_stop, param_stop)
10+
}
11+
12+
update1_ <- function(Q2, w, m, k) {
13+
.Call('selectiveInference_update1_', PACKAGE = 'selectiveInference', Q2, w, m, k)
14+
}
15+
16+
downdate1_ <- function(Q1, R, j0, m, n) {
17+
.Call('selectiveInference_downdate1_', PACKAGE = 'selectiveInference', Q1, R, j0, m, n)
18+
}
19+
20+
log_density_gaussian_ <- function(noise_scale, internal_linear, internal_state, optimization_linear, optimization_state, offset) {
21+
.Call('selectiveInference_log_density_gaussian_', PACKAGE = 'selectiveInference', noise_scale, internal_linear, internal_state, optimization_linear, optimization_state, offset)
22+
}
23+
24+
log_density_gaussian_conditional_ <- function(noise_scale, optimization_linear, optimization_state, offset) {
25+
.Call('selectiveInference_log_density_gaussian_conditional_', PACKAGE = 'selectiveInference', noise_scale, optimization_linear, optimization_state, offset)
26+
}
27+
28+
log_density_laplace_ <- function(noise_scale, internal_linear, internal_state, optimization_linear, optimization_state, offset) {
29+
.Call('selectiveInference_log_density_laplace_', PACKAGE = 'selectiveInference', noise_scale, internal_linear, internal_state, optimization_linear, optimization_state, offset)
30+
}
31+
32+
log_density_laplace_conditional_ <- function(noise_scale, optimization_linear, optimization_state, offset) {
33+
.Call('selectiveInference_log_density_laplace_conditional_', PACKAGE = 'selectiveInference', noise_scale, optimization_linear, optimization_state, offset)
34+
}
35+

selectiveInference/R/funs.randomized.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ importance_weight = function(noise_scale,
239239
A = apply(A, 2, function(x) {return(x + target_transform$offset_term + opt_transform$offset_term)})
240240
log_num = -apply(A^2, 2, sum) / noise_scale^2
241241
} else {
242-
243242
log_num = log_density_gaussian_(noise_scale,
244243
target_transform$linear_term,
245244
as.matrix(target_sample),
@@ -262,6 +261,15 @@ importance_weight = function(noise_scale,
262261
W = W - max(W)
263262
return(exp(W))
264263
}
264+
265+
get_mean_cov = function(noise_scale, linear_term, offset_term){
266+
temp = solve(t(linear_term) %*% linear_term)
267+
cov = noise_scale^2*temp
268+
mean = temp %*% linear_term %*% offset_term
269+
return(list(mean=mean, cov=cov))
270+
}
271+
272+
265273

266274
conditional_density = function(noise_scale, lasso_soln) {
267275

0 commit comments

Comments
 (0)