Learn R Programming

LICORS (version 0.2.0)

merge_states: Merge several states into one

Description

This function merges states \(i_1, \ldots, i_j\) into a new, single state \(i_1\) by adding corresponding columns of the weight matrix (\(\mathbf{W}_{i_1} = \mathbf{W}_{i_1} + \ldots + \mathbf{W}_{i_j}\)) and removing columns \(i_2, \ldots, i_j\).

Usage

merge_states(states, weight.matrix)

Arguments

states

vector of length \(1 \leq j \leq K\) with the states \(i_1, \ldots, i_j \subset \lbrace 1, \ldots, K \rbrace\) that should be merged; no repeating state labels allowed.

weight.matrix

\(N \times K\) weight matrix

Examples

Run this code
# NOT RUN {
set.seed(10)
WW <- matrix(c(rexp(1000, 1/10), runif(1000)), ncol = 5, byrow = FALSE)
WW <- normalize(WW)
image2(WW, density = TRUE)
# }
# NOT RUN {
merge_states(c(1, 1, 5), WW)  # error since states were repeated
# }
# NOT RUN {
WW_new <- merge_states(c(1, 3, 5), WW)

par(mfrow = c(1, 2), mar = c(1, 1, 2, 1))
image2(WW, main = paste(ncol(WW), "states"), legend = FALSE)
image2(WW_new, main = paste(ncol(WW_new), "states"), legend = FALSE)
# }

Run the code above in your browser using DataLab