Skip to content

Commit

Permalink
alpha, stats::, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Sep 25, 2024
1 parent 37e00a3 commit fb3fa6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
16 changes: 9 additions & 7 deletions R/simulate_pars.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@ simulate_initial_probs <- function(n_states, n_clusters = 1, alpha = 1) {
n_states <- rep(n_states, length = n_clusters)

if (n_clusters == 1) {
x <- rgamma(n_states, alpha)
x <- stats::rgamma(n_states, alpha)
x / sum(x)
} else {
probs <- vector("list", n_clusters)
for (i in 1:n_clusters) {
x <- rgamma(n_states[i], alpha)
x <- stats::rgamma(n_states[i], alpha)
probs[[i]] <- x / sum(x)
}
probs
}
}
#' @export
#' @rdname simulate_pars
simulate_transition_probs <- function(n_states, n_clusters = 1, left_right = FALSE, diag_c = 0, alpha = 1) {
simulate_transition_probs <- function(n_states, n_clusters = 1,
left_right = FALSE, diag_c = 0, alpha = 1) {
n_states <- rep(n_states, length = n_clusters)
if (n_clusters == 1) {
x <- matrix(rgamma(n_states^2, alpha), n_states, n_states, TRUE) +
x <- matrix(stats::rgamma(n_states^2, alpha), n_states, n_states, TRUE) +
diag(diag_c, n_states)
if (left_right) x[lower.tri(x)] <- 0
probs <- x / rowSums(x)
} else {
probs <- vector("list", n_clusters)
for (i in seq_len(n_clusters)) {
x <- matrix(
rgamma(n_states[i]^2, alpha), n_states[i], n_states[i], TRUE
stats::rgamma(n_states[i]^2, alpha), n_states[i], n_states[i], TRUE
) + diag(diag_c, n_states[i])
if (left_right) x[lower.tri(x)] <- 0
probs[[i]] <- x / rowSums(x)
Expand All @@ -64,15 +65,16 @@ simulate_emission_probs <- function(n_states, n_symbols, n_clusters = 1,
emiss[[i]] <- vector("list", n_channels)
for (j in seq_len(n_channels)) {
emiss[[i]][[j]] <- matrix(
rgamma(n_states[i] * n_symbols[j], alpha), n_states[i], n_symbols[j],
stats::rgamma(n_states[i] * n_symbols[j], alpha), n_states[i], n_symbols[j],
TRUE)
emiss[[i]][[j]] <- emiss[[i]][[j]] / rowSums(emiss[[i]][[j]])
}
}
} else {
for (i in seq_len(n_clusters)) {
emiss[[i]] <- matrix(
rgamma(n_states[i] * n_symbols), n_states[i], n_symbols, TRUE
stats::rgamma(n_states[i] * n_symbols, alpha), n_states[i], n_symbols,
TRUE
)
emiss[[i]] <- emiss[[i]] / rowSums(emiss[[i]])
}
Expand Down
16 changes: 8 additions & 8 deletions man/simulate_pars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb3fa6d

Please sign in to comment.