Skip to content

Commit

Permalink
use seq_len instead of 1:x
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstaab committed May 9, 2016
1 parent 1ec85d4 commit b9da5db
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,5 +1,5 @@
Package: jaatha
Version: 3.1.1.9007
Version: 3.1.1.9008
License: GPL (>= 3)
Title: Simulation-Based Maximum Likelihood Parameter Estimation
Authors@R: c(
Expand Down
2 changes: 1 addition & 1 deletion R/block.R
Expand Up @@ -31,7 +31,7 @@ block_class <- R6::R6Class("Block",
m
},
get_corners = function() {
corners <- expand.grid(lapply(1:nrow(private$border), function(i) {
corners <- expand.grid(lapply(seq_len(nrow(private$border)), function(i) {
private$border[i, , drop = FALSE] #nolint
}), KEEP.OUT.ATTRS = FALSE) #nolint
colnames(corners) <- rownames(private$border)
Expand Down
2 changes: 1 addition & 1 deletion R/fit_glm.R
Expand Up @@ -18,7 +18,7 @@ fit_glm.jaatha_stat_basic <- function(x, sim_data, ...) {
X <- cbind(1,
do.call(rbind, lapply(sim_data, function(data) data$pars_normal)))

glms <- lapply(1:ncol(Y), function(i) {
glms <- lapply(seq_len(ncol(Y)), function(i) {
suppressWarnings(
stats::glm.fit(X, Y[, i], family = stats::poisson("log"),
control = list(maxit = 100))[c("coefficients",
Expand Down
2 changes: 1 addition & 1 deletion R/initialization.R
Expand Up @@ -102,7 +102,7 @@ do_zoom_in_search <- function(model, data, reps, sim, cores, sim_cache,
block_width, n_steps = 3) {
"Starts with estimating parameters in the complete parameter space, an then
iteratively deceases the size of the block"
best_est <- vapply(1:reps, function(i) {
best_est <- vapply(seq_len(reps), function(i) {
middle <- rep(.5, model$get_par_number())
block_widths <- utils::head(seq(1, block_width,
length.out = n_steps + 1), -1)
Expand Down
2 changes: 1 addition & 1 deletion R/jaatha_log.R
Expand Up @@ -17,7 +17,7 @@ jaatha_log_class <- R6::R6Class("jaatha_log",
initialize = function(model, data, reps, max_steps, verbose = TRUE) {
par_number <- model$get_par_number()
par_names <- model$get_par_ranges()$get_par_names()
private$estimates <- lapply(1:reps, function(i) {
private$estimates <- lapply(seq_len(reps), function(i) {
estimates <- matrix(NA, max_steps, par_number + 3)
colnames(estimates) <- c("rep", "step", "llh", par_names)
as.data.frame(estimates)
Expand Down
9 changes: 6 additions & 3 deletions R/jaatha_model.R
Expand Up @@ -36,15 +36,18 @@ jaatha_model_class <- R6::R6Class("jaatha_model",
"conducts a simulation for each parameter combination in pars"
assert_that(is.matrix(pars))
assert_that(ncol(pars) == private$par_ranges$get_par_number())
assert_that(nrow(pars) >= 1)
assert_that(all(0 - 1e-5 <= pars & pars <= 1 + 1e-5))
assert_that(is_jaatha_data(data))
assert_that(is.count(cores))

# Generate a seed for each simulation
seeds <- sample_seed(length(pars) + 1)
n_pars <- nrow(pars)
seeds <- sample_seed(n_pars + 1)

# Simulate
sim_data <- mclapply(1:nrow(pars), function(i) {
sim_data <- mclapply(seq_len(n_pars), function(i) {
assert_that(is.count(i))
set.seed(seeds[i])
sim_pars <- private$par_ranges$denormalize(pars[i, ])

Expand Down Expand Up @@ -80,7 +83,7 @@ jaatha_model_class <- R6::R6Class("jaatha_model",
stop("Simulations failed, check your model.")
}

set.seed(seeds[length(seeds)])
set.seed(tail(seeds, 1))
sim_data
},
get_par_ranges = function() private$par_ranges,
Expand Down
2 changes: 1 addition & 1 deletion R/stat_cube.R
Expand Up @@ -58,7 +58,7 @@ stat_cube_class <- R6::R6Class("stat_cube", inherit = stat_basic_class,
data_matrix <- private$calculate_matrix(data)
assert_that(is.numeric(data_matrix))
if (!is.matrix(data_matrix)) data_matrix <- matrix(data_matrix, ncol = 1)
list(break_values = lapply(1:ncol(data_matrix), function(i) {
list(break_values = lapply(seq_len(ncol(data_matrix)), function(i) {
private$calc_break_values(data_matrix[, i], private$break_values)
}))
}
Expand Down

0 comments on commit b9da5db

Please sign in to comment.