Description
The HMMDecoder function finds the state sequence with the highest probability, given the learned model and observed sequences.
Usage
td_hmm_decoder_mle (
init.state.prob = NULL,
state.transition.prob = NULL,
emission.prob = NULL,
observation = NULL,
state.model.key = NULL,
state.key = NULL,
state.prob.key = NULL,
trans.model.key = NULL,
trans.from.key = NULL,
trans.to.key = NULL,
trans.prob.key = NULL,
emit.model.key = NULL,
emit.state.key = NULL,
emit.observed.key = NULL,
emit.prob.key = NULL,
model.key = NULL,
sequence.key = NULL,
observed.key = NULL,
sequence.max.size = 2147483647,
skip.key = NULL,
accumulate = NULL,
observation.sequence.column = NULL,
init.state.prob.sequence.column = NULL,
state.transition.prob.sequence.column = NULL,
emission.prob.sequence.column = NULL,
observation.partition.column = NULL,
init.state.prob.partition.column = NULL,
state.transition.prob.partition.column = NULL,
emission.prob.partition.column = NULL,
observation.order.column = NULL,
init.state.prob.order.column = NULL,
state.transition.prob.order.column = NULL,
emission.prob.order.column = NULL
)
Arguments
init.state.prob |
Required Argument. |
init.state.prob.partition.column |
Required Argument. |
init.state.prob.order.column |
Optional Argument. |
state.transition.prob |
Required Argument. |
state.transition.prob.partition.column |
Required Argument. |
state.transition.prob.order.column |
Optional Argument. |
emission.prob |
Required Argument. |
emission.prob.partition.column |
Required Argument. |
emission.prob.order.column |
Optional Argument. |
observation |
Required Argument. |
observation.partition.column |
Required Argument. |
observation.order.column |
Required Argument. |
state.model.key |
Required Argument. |
state.key |
Required Argument. |
state.prob.key |
Required Argument. |
trans.model.key |
Required Argument. |
trans.from.key |
Required Argument. |
trans.to.key |
Required Argument. |
trans.prob.key |
Required Argument. |
emit.model.key |
Required Argument. |
emit.state.key |
Required Argument. |
emit.observed.key |
Required Argument. |
emit.prob.key |
Required Argument. |
model.key |
Required Argument. |
sequence.key |
Required Argument. |
observed.key |
Required Argument. |
sequence.max.size |
Optional Argument. |
skip.key |
Optional Argument. |
accumulate |
Optional Argument. |
observation.sequence.column |
Optional Argument. |
init.state.prob.sequence.column |
Optional Argument. |
state.transition.prob.sequence.column |
Optional Argument. |
emission.prob.sequence.column |
Optional Argument. |
Value
Function returns an object of class "td_hmm_decoder_mle" which is a named
list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator
using name: result.
Examples
# Get the current context/connection
con <- td_get_context()$connection
# Load example data.
loadExampleData("hmmsupervised_example", "customer_loyalty")
loadExampleData("hmmunsupervised_example", "loan_prediction")
# Example 1 - This example uses loan status updates to build a td_hmm_supervised_mle()
# function and then predict loan defaults.
loadExampleData("hmmdecoder_example", "test_loan_prediction")
# Create object(s) of class "tbl_teradata".
loan_prediction <- tbl(con, "loan_prediction")
td_hmm_unsup_out <- td_hmm_unsupervised_mle(vertices=loan_prediction,
vertices.partition.column=c('model_id','seq_id'),
vertices.order.column='seq_vertex_id',
sequence.key='seq_id',
observed.key='observed_id',
model.key='model_id',
hidden.states.num=3
)
test_loan_prediction <- tbl(con, "test_loan_prediction")
td_hmm_decoder_out1 <- td_hmm_decoder_mle(
init.state.prob = td_hmm_unsup_out$output.initialstate.table,
init.state.prob.partition.column = c("model_id"),
state.transition.prob = td_hmm_unsup_out$output.statetransition.table,
state.transition.prob.partition.column = c("model_id"),
emission.prob = td_hmm_unsup_out$output.emission.table,
emission.prob.partition.column = c("model_id"),
observation = test_loan_prediction,
observation.partition.column = c("model_id "),
observation.order.column = c("model_id", "seq_id", "seq_vertex_id"),
state.model.key = "model_id",
state.key = "state",
state.prob.key = "probability",
trans.model.key = "model_id",
trans.from.key = "from_state",
trans.to.key = "to_state",
trans.prob.key = "probability",
emit.model.key = "model_id",
emit.state.key = "state",
emit.observed.key = "observed",
emit.prob.key = "probability",
model.key = "model_id",
sequence.key = "seq_id",
observed.key = "observed_id",
accumulate = c("seq_vertex_id")
)
# Example 2 - This example uses the output of a td_hmm_supervised_mle() function with the
# input to determine the loyalty levels of customers from the new sequence of purchases.
loadExampleData("hmmdecoder_example", "customer_loyalty_newseq")
customer_loyalty <- tbl(con, "customer_loyalty")
td_hmm_sup_out <- td_hmm_supervised_mle(vertices=customer_loyalty,
vertices.partition.column=c('user_id','seq_id'),
vertices.order.column=c('user_id','seq_id','purchase_date'),
state.key='loyalty_level',
observed.key='observation',
sequence.key='seq_id',
model.key='user_id'
)
customer_loyalty_newseq <- tbl(con, "customer_loyalty_newseq")
td_hmm_decoder_out2 <- td_hmm_decoder_mle(
init.state.prob = td_hmm_sup_out$output.initialstate.table,
init.state.prob.partition.column = c("user_id"),
state.transition.prob = td_hmm_sup_out$output.statetransition.table,
state.transition.prob.partition.column = c("user_id"),
emission.prob = td_hmm_sup_out$output.emission.table,
emission.prob.partition.column = c("user_id"),
observation = customer_loyalty_newseq,
observation.partition.column = c("user_id"),
observation.order.column = c("user_id", "seq_id", "purchase_date"),
state.model.key = "user_id",
state.key = "state",
state.prob.key = "probability",
trans.model.key = "user_id",
trans.from.key = "from_state",
trans.to.key = "to_state",
trans.prob.key = "probability",
emit.model.key = "user_id",
emit.state.key = "state",
emit.observed.key = "observed",
emit.prob.key = "probability",
model.key = "user_id",
sequence.key = "seq_id",
observed.key = "observation",
accumulate = "purchase_date"
)
# Example 3 - Part of Speech Tagging example
loadExampleData("hmmdecoder_example", "initial", "state_transition", "emission", "phrases")
initial <- tbl(con, "initial")
state_transition <- tbl(con, "state_transition")
emission <- tbl(con, "emission")
phrases <- tbl(con, "phrases")
td_hmm_decoder_out3 <- td_hmm_decoder_mle(init.state.prob = initial,
init.state.prob.partition.column = c("model"),
state.transition.prob = state_transition,
state.transition.prob.partition.column = c("model"),
emission.prob = emission,
emission.prob.partition.column = c("model"),
observation = phrases,
observation.partition.column = c("model"),
observation.order.column = c("model", "phrase_id"),
state.model.key = "model",
state.key = "tag",
state.prob.key = "probability",
trans.model.key = "model",
trans.from.key = "from_tag",
trans.to.key = "to_tag",
trans.prob.key = "probability",
emit.model.key = "model",
emit.state.key = "tag",
emit.observed.key = "word",
emit.prob.key = "probability",
model.key = "model",
sequence.key = "phrase_id",
observed.key = "word"
)
# Example 4 - This example uses td_hmm_supervised_mle() function to find the propensity
# of customer churn,
# given the actions or transactions of a bank customer.
loadExampleData("hmmdecoder_example", "churn_initial", "churn_state_transition",
"churn_emission", "churn_data")
churn_initial <- tbl(con, "churn_initial")
churn_state_transition <- tbl(con, "churn_state_transition")
churn_emission <- tbl(con, "churn_emission")
churn_data <- tbl(con, "churn_data")
td_hmm_decoder_out4 <- td_hmm_decoder_mle(init.state.prob = churn_initial,
init.state.prob.partition.column = c("model"),
state.transition.prob = churn_state_transition,
state.transition.prob.partition.column = c("model"),
emission.prob = churn_emission,
emission.prob.partition.column = c("model"),
observation = churn_data,
observation.partition.column = c("model"),
observation.order.column = c("model","id", "path_id"),
state.model.key = "model",
state.key = "tag",
state.prob.key = "probability",
trans.model.key = "model",
trans.from.key = "from_tag",
trans.to.key = "to_tag",
trans.prob.key = "probability",
emit.model.key = "model",
emit.state.key = "state",
emit.observed.key = "observed",
emit.prob.key = "probability",
model.key = "model",
sequence.key = "id",
observed.key = "action",
accumulate = c("path_id")
)