Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 5ab1f4f

Browse files
committed
Cosmetic changes
1 parent 8223a64 commit 5ab1f4f

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

analysis/R/decode.R

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ FitLasso <- function(X, Y, intercept = TRUE) {
8989
# Input:
9090
# X: a design matrix of size km by M (the number of candidate strings).
9191
# Y: a vector of size km with estimated counts from EstimateBloomCounts(),
92-
# representing constraints
92+
# representing constraints
9393
# intercept: whether to fit with intercept or not.
9494
#
9595
# Output:
9696
# a vector of size ncol(X) of coefficients.
9797

9898
# TODO(mironov): Test cv.glmnet instead of glmnet
9999

100-
# Cap the number of non-zero coefficients to 500 or 80% of the number of
101-
# constraints, whichever is less. The 500 cap is for performance reasons, 80%
102-
# is to avoid overfitting.
100+
# Cap the number of non-zero coefficients to 500 or 80% of the number of
101+
# constraints, whichever is less. The 500 cap is for performance reasons, 80%
102+
# is to avoid overfitting.
103103
cap <- min(500, nrow(X) * .8, ncol(X))
104104

105105
mod <- glmnet(X, Y, standardize = FALSE, intercept = intercept,
@@ -110,10 +110,10 @@ FitLasso <- function(X, Y, intercept = TRUE) {
110110
coefs <- coefs[-1, , drop = FALSE] # drop the intercept
111111
l1cap <- sum(colSums(coefs) <= 1.0) # find all columns with L1 norm <= 1
112112
if(l1cap > 0)
113-
coefs <- coefs[, l1cap] # return the last set of coefficients with L1 <= 1
113+
distr <- coefs[, l1cap] # return the last set of coefficients with L1 <= 1
114114
else
115-
coefs <- setNames(rep(0, ncol(X)), colnames(X))
116-
coefs
115+
distr <- setNames(rep(0, ncol(X)), colnames(X))
116+
distr
117117
}
118118

119119
PerformInference <- function(X, Y, N, mod, params, alpha, correction) {
@@ -230,17 +230,10 @@ FitDistribution <- function(estimates_stds, map, quiet = FALSE) {
230230
if(!quiet)
231231
cat("LASSO selected ", sum(lasso > 0), " non-zero coefficients.\n")
232232

233-
coefs <- setNames(lasso, colnames(map))
233+
names(lasso) <- colnames(map)
234234

235-
# if(length(support_coefs) > 0) { # LASSO may return an empty list
236-
# constrained_coefs <- ConstrainedLinModel(map[, support_coefs, drop = FALSE],
237-
# estimates_stds)
238-
#
239-
# coefs[support_coefs] <- constrained_coefs
240-
# }
241-
242-
coefs
243-
}
235+
lasso
236+
}
244237

245238
Resample <- function(e) {
246239
# Simulate resampling of the Bloom filter estimates by adding Gaussian noise
@@ -282,7 +275,7 @@ Decode <- function(counts, map, params, alpha = 0.05,
282275

283276
# Run the fitting procedure several times (5 seems to be sufficient and not
284277
# too many) to estimate standard deviation of the output.
285-
for(r in 1:5) {
278+
for(r in 1:10) {
286279
if(r > 1)
287280
e <- Resample(estimates_stds_filtered)
288281
else

0 commit comments

Comments
 (0)