train | R Documentation |
Update model parameters using a list of training sequences, with either the Viterbi training or Baum-Welch algorithm.
train(x, y, ...) ## S3 method for class 'PHMM' train( x, y, method = "Viterbi", seqweights = "Henikoff", wfactor = 1, k = 5, logspace = "autodetect", maxiter = 100, limit = 1, deltaLL = 1e-07, pseudocounts = "background", gap = "-", fixqa = FALSE, fixqe = FALSE, maxsize = NULL, inserts = "map", threshold = 0.5, lambda = 0, alignment = FALSE, cores = 1, quiet = FALSE, ... ) ## S3 method for class 'HMM' train( x, y, method = "Viterbi", seqweights = NULL, wfactor = 1, maxiter = 100, deltaLL = 1e-07, logspace = "autodetect", quiet = FALSE, modelend = FALSE, pseudocounts = "Laplace", ... )
x |
an object of class |
y |
a list of training sequences whose hidden states are unknown. Accepted modes are "character" and "raw" (for "DNAbin" and "AAbin" objects). |
... |
aditional arguments to be passed to |
method |
a character string specifying the iterative model training
method to use. Accepted methods are |
seqweights |
either NULL (all sequences are given weights
of 1), a numeric vector the same length as |
wfactor |
numeric. The factor to multiply the sequence weights by. Defaults to 1. |
k |
integer representing the k-mer size to be used in tree-based sequence weighting (if applicable). Defaults to 5. Note that higher values of k may be slow to compute and use excessive memory due to the large numbers of calculations required. |
logspace |
logical indicating whether the emission and transition
probabilities of x are logged. If |
maxiter |
the maximum number of EM iterations or Viterbi training iterations to carry out before the cycling process is terminated and the partially trained model is returned. Defaults to 100. |
limit |
the proportion of alignment rows that must be identical between subsequent iterations for the Viterbi training algorithm to terminate. Defaults to 1. |
deltaLL |
numeric, the maximum change in log likelihood between EM
iterations before the cycling procedure is terminated (signifying model
convergence). Defaults to 1E-07. Only applicable if
|
pseudocounts |
character string, either "background", Laplace"
or "none". Used to account for the possible absence of certain
transition and/or emission types in the input sequences.
If |
gap |
the character used to represent gaps in the alignment matrix
(if applicable). Ignored for |
fixqa |
logical. Should the background transition probabilities
be fixed (TRUE), or allowed to vary between iterations (FALSE)?
Defaults to FALSE. Only applicable if |
fixqe |
logical. Should the background emission probabilities
be fixed (TRUE), or allowed to vary between iterations (FALSE)?
Defaults to FALSE. Only applicable if |
maxsize |
integer giving the upper bound on the number of modules in the PHMM. If NULL (default) no maximum size is enforced. |
inserts |
character string giving the model construction method
by which alignment columns
are marked as either match or insert states. Accepted methods include
|
threshold |
the maximum proportion of gaps for an alignment column
to be considered for a match state in the PHMM (defaults to 0.5).
Only applicable when |
lambda |
penalty parameter used to favour models with fewer match
states. Equivalent to the log of the prior probability of marking each
column (Durbin et al 1998, chapter 5.7). Only applicable when
|
alignment |
logical indicating whether the alignment used to derive the final model (if applicable) should be included as an element of the returned PHMM object. Defaults to FALSE. |
cores |
integer giving the number of CPUs to parallelize the operation
over. Defaults to 1, and reverts to 1 if x is not a list.
This argument may alternatively be a 'cluster' object,
in which case it is the user's responsibility to close the socket
connection at the conclusion of the operation,
for example by running |
quiet |
logical indicating whether feedback should be printed to the console. |
modelend |
logical indicating whether transition probabilites to the end state of the standard hidden Markov model should be modeled (if applicable). Defaults to FALSE. |
This function optimizes the parameters of a hidden Markov model
(object class: "HMM"
) or profile hidden Markov model
(object class: "PHMM"
) using the methods described in
Durbin et al (1998) chapters 3.3 and 6.5, respectively.
For standard HMMs, the function assumes the state sequence is unknown
(as opposed to the deriveHMM
function, which is used
when the state sequence is known).
For profile HMMs, the input object is generally a list of non-aligned
sequences rather than an alignment (for which the derivePHMM
function may be more suitable).
This function offers a choice of two model training methods, Viterbi training (also known as the segmental K-means algorithm (Juang & Rabiner 1990)), and the Baum Welch algorithm, a special case of the expectation-maximization (EM) algorithm that iteratively finds the locally (but not necessarily globally) optimal parameters of a HMM or PHMM.
The Viterbi training method is generally much faster, particularly for
profile HMMs and when the multi-threading option is used
(see the "cores"
argument). The comparison in accuracy will depend
on the nature of the problem, but personal experience suggests that
the methods are comparable for training profile HMMs for DNA and
amino acid sequences.
an object of class "HMM"
or "PHMM"
, depending
on the input model x
.
Shaun Wilkinson
Durbin R, Eddy SR, Krogh A, Mitchison G (1998) Biological sequence analysis: probabilistic models of proteins and nucleic acids. Cambridge University Press, Cambridge, United Kingdom.
Juang B-H, Rabiner LR (1990) The segmental K-means algorithm for estimating parameters of hidden Markov models. IEEE Transactions on Acoustics, Speech, and Signal Processing, 38, 1639-1641.
deriveHMM
and derivePHMM
for
maximum-likelihood parameter estimation when the training sequence states
are known.
## Baum Welch training for standard HMMs: ## The dishonest casino example from Durbin et al (1998) chapter 3.2 states <- c("Begin", "Fair", "Loaded") residues <- paste(1:6) ### Define the transition probability matrix A <- matrix(c(0, 0, 0, 0.99, 0.95, 0.1, 0.01, 0.05, 0.9), nrow = 3) dimnames(A) <- list(from = states, to = states) ### Define the emission probability matrix E <- matrix(c(rep(1/6, 6), rep(1/10, 5), 1/2), nrow = 2, byrow = TRUE) dimnames(E) <- list(states = states[-1], residues = residues) ### Build and plot the HMM object x <- structure(list(A = A, E = E), class = "HMM") op <- par(no.readonly = TRUE) par(mfrow = c(2, 1)) plot(x, main = "Dishonest casino HMM before training") data(casino) x <- train(x, list(casino), method = "BaumWelch", deltaLL = 0.001) plot(x, main = "Dishonest casino HMM after training") par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.