q_mv_gr2: q_mv_gr2

Description Usage Arguments Value Examples

Description

q_mv_gr2 calculates the gradient of q_mv2. q_mv_gr2 calculates the target function for each k instead of all k.

Usage

1
q_mv_gr2(pars, X, E, L, k)

Arguments

pars

a vector of length 2. c(v[k], m[k])

X

a list of vectors of observed states x

E

a vector of normalizing constant for each observed chain in X

L

a list of matrix L from computeL

k

a scalar indicating which state is calculated

Value

A vector of length 2, the gradient for q_mv2.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
df <- uORF[1:10]
X <- L <- list()
E <- c()
for (i in 1:length(df)){
  X[[i]] <- df[[i]]$x
  RNA[[i]] <- df[[i]]$RNA
  E[i]=df[[i]]$E;   trans=df[[i]]$trans;
  a=df[[i]]$v;      b=df[[i]]$v/df[[i]]$m
  la <- forwardAlg(X[[i]], RNA[[i]], trans, a, b, E[i])
  lb <- backwardAlg(X[[i]], RNA[[i]], trans, a, b, E[i])
  L[[i]] <- computeL(la, lb)
}
pars <- c(df[[1]]$v, df[[1]]$m)

# check by comparing with numeric approximation
require(numDeriv)
D1 <- rep(0,42)
for (k in 1:21){
  D1[c(k,21+k)] <- grad(function(u) q_mv2(u,X,E,L,k) , pars[c(k,21+k)])
}
D2 <- rep(0,42)
for (k in 1:21){
  D2[c(k,21+k)] <- q_mv_gr2(pars[c(k,21+k)], X, E, L, k)
}
print(round(D1-D2, 10))

shimlab/riboHMM2 documentation built on May 19, 2019, 6:23 p.m.