Last data update: 2014.03.03

R: Merge several states into one
merge_statesR Documentation

Merge several states into one

Description

This function merges states i_1, …, 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} + … + mathbf{W}_{i_j}) and removing columns i_2, …, i_j.

Usage

merge_states(states, weight.matrix)

Arguments

states

vector of length 1 ≤q j ≤q K with the states i_1, …, i_j subset lbrace 1, …, K brace that should be merged; no repeating state labels allowed.

weight.matrix

N \times K weight matrix

Examples

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

## End(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)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(LICORS)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LICORS/merge_states.Rd_%03d_medium.png", width=480, height=480)
> ### Name: merge_states
> ### Title: Merge several states into one
> ### Aliases: merge_states
> ### Keywords: array manip
> 
> ### ** Examples
> 
> 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: 
> ##D merge_states(c(1, 1, 5), WW)  # error since states were repeated
> ## End(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)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>