Skip to content

Commit 1b80ba7

Browse files
author
albcab
committed
initial, index fix
1 parent 1962751 commit 1b80ba7

File tree

6 files changed

+37
-12
lines changed

6 files changed

+37
-12
lines changed

R/samplingBVS.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ samplingBVS <- function(y, #vector of observations
140140
output <- wTGS(as.matrix(X), as.vector(y), n, p, n_iter, burn_in, h1, h2, c, k_weight, weighted)
141141

142142
return(list(PIP = output[[1]],
143-
full_cond = output[[5]],
143+
# full_cond = output[[5]],
144+
# PIP_check = output[[6]],
145+
# z_check = output[[7]],
146+
# sumweight_check = output[[8]],
147+
# gamma_check = output[[9]],
144148
states = list(start = output[[2]],
145149
sample_weights = output[[3]],
146150
indices_sequence = output[[4]],

src/RcppExports.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
using namespace Rcpp;
88

9+
#ifdef RCPP_USE_GLOBAL_ROSTREAM
10+
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
11+
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
12+
#endif
13+
914
// wTGS
1015
List wTGS(SEXP X_, SEXP y_, SEXP n_, SEXP p_, SEXP n_iter, SEXP burnin_, SEXP h1_, SEXP h2_, SEXP c_, SEXP k_, SEXP weighted);
1116
RcppExport SEXP _scaleBVS_wTGS(SEXP X_SEXP, SEXP y_SEXP, SEXP n_SEXP, SEXP p_SEXP, SEXP n_iterSEXP, SEXP burnin_SEXP, SEXP h1_SEXP, SEXP h2_SEXP, SEXP c_SEXP, SEXP k_SEXP, SEXP weightedSEXP) {

src/RcppExports.o

-581 KB
Binary file not shown.

src/scaleBVS.so

223 KB
Binary file not shown.

src/wTGS.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ List wTGS(SEXP X_, SEXP y_, SEXP n_, SEXP p_, SEXP n_iter, SEXP burnin_, SEXP h1
113113
NumericVector start(p);
114114
NumericVector sample_weights(n_it);
115115
NumericVector indices_sequence(n_it);
116-
NumericMatrix full_cond(n_it, p);
116+
// NumericMatrix full_cond(n_it, p);
117+
// NumericMatrix PIP_check(n_it, p);
118+
// NumericVector z_check(n_it);
119+
// NumericVector sumweight_check(n_it);
120+
// NumericMatrix gamma_check(n_it, p);
117121

118122
Gamma main(X, y, n, p, h1, h2, c, k, w);
119123

@@ -123,7 +127,7 @@ List wTGS(SEXP X_, SEXP y_, SEXP n_, SEXP p_, SEXP n_iter, SEXP burnin_, SEXP h1
123127
//if (i < burnin)
124128
//cout << "\r\t(Burn in) Iteration " << i;
125129
//else
126-
if (i == burnin)
130+
if ((i-1) == burnin)
127131
{
128132
//cout << "\r\t(Burn in) Iteration " << i << endl;
129133
for (int j = 0; j < p; j++)
@@ -139,29 +143,41 @@ List wTGS(SEXP X_, SEXP y_, SEXP n_, SEXP p_, SEXP n_iter, SEXP burnin_, SEXP h1
139143
main.calculateH();
140144
main.calculateFullCond();
141145
main.calculateFlipRates();
146+
if (i > burnin)
147+
indices_sequence[i-burnin-1] = main.j+1;
142148
double z = main.calculateWeight();
143149
// main.updatePIP(z);
144150

145151
if (i > burnin)
146152
{
147153
main.updatePIP(z);
148154
sample_weights[i-burnin-1] = z;
149-
indices_sequence[i-burnin-1] = main.j+1;
150-
for (int j=0; j<p; j++)
151-
full_cond(i-burnin-1, j) = main.full_cond[j];
155+
// for (int j=0; j<p; j++)
156+
// {
157+
// full_cond(i-burnin-1, j) = main.full_cond[j];
158+
// PIP_check(i-burnin-1, j) = main.PIP[j]/main.sumweight;
159+
// gamma_check(i-burnin-1, j) = main.gamma[j];
160+
// }
161+
// z_check(i-burnin-1) = z;
162+
// sumweight_check(i-burnin-1) = main.sumweight;
152163
}
153164
}
154165

155166
//cout << endl << "DONE" << endl;
156167
for (int i = 0; i < p; i++)
157168
PIP[i] = main.PIP[i]/main.sumweight;
158169

159-
List output(5);
170+
// List output(9);
171+
List output(4);
160172
output[0] = PIP;
161173
output[1] = start;
162174
output[2] = sample_weights/main.sumweight;
163175
output[3] = indices_sequence;
164-
output[4] = full_cond;
176+
// output[4] = full_cond;
177+
// output[5] = PIP_check;
178+
// output[6] = z_check;
179+
// output[7] = sumweight_check;
180+
// output[8] = gamma_check;
165181
return output;
166182
}
167183

@@ -435,12 +451,12 @@ void Gamma::calculateFlipRates()
435451
if (w)
436452
{
437453
if (gamma[i] == 0)
438-
flip_rates[i] = (1-full_cond[i]+k/p)/full_cond[i];
454+
flip_rates[i] = (1.0-full_cond[i]+k/p)/full_cond[i];
439455
else
440-
flip_rates[i] = 1 + (k/p)/full_cond[i];
456+
flip_rates[i] = 1.0 + (k/p)/full_cond[i];
441457
}
442458
else
443-
flip_rates[i] = 1/full_cond[i];
459+
flip_rates[i] = 1.0/full_cond[i];
444460
}
445461
}
446462

@@ -470,6 +486,6 @@ void Gamma::updatePIP(double z)
470486
sumweight += z;
471487
for (int i = 0; i < p; i++)
472488
{
473-
PIP[i] += z*(gamma[i]*full_cond[i] + (1-gamma[i])*(1-full_cond[i]));
489+
PIP[i] += z*(gamma[i]*full_cond[i] + (1.0-gamma[i])*(1.0-full_cond[i]));
474490
}
475491
}

src/wTGS.o

16.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)