Teradata R Package Function Reference - HMMEvaluator - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The HMMEvaluator function measures the probabilities of sequences, with respect to each trained HMM.

Usage

  td_hmm_evaluator_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,
      incremental = TRUE,
      show.rate.change = TRUE,
      seq.prob.key = NULL,
      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
  )

Arguments

init.state.prob

Required Argument.
Specifies the initial state table.

init.state.prob.partition.column

Required Argument.
Specifies the Partition By columns for "init.state.prob". Values to this argument can be provided as vector, if multiple columns are used for ordering.

state.transition.prob

Required Argument.
Specifies the state transition table.

state.transition.prob.partition.column

Required Argument.
Specifies the Partition By columns for "state.transition.prob". Values to this argument can be provided as vector, if multiple columns are used for ordering.

emission.prob

Required Argument.
Specifies the emission probability table.

emission.prob.partition.column

Required Argument.
Specifies the Partition By columns for "emission.prob". Values to this argument can be provided as vector, if multiple columns are used for ordering.

observation

Required Argument.
Specifies the observation table for which the probabilities of sequences are to be found.

observation.partition.column

Required Argument.
Specifies the Partition By columns for "observation". Values to this argument can be provided as vector, if multiple columns are used for ordering.

observation.order.column

Required Argument.
Specifies the Order By columns for "observation". Values to this argument can be provided as vector, if multiple columns are used for ordering.

state.model.key

Required Argument.
Specifies the name of the model attribute column in the "init.state.prob" table.

state.key

Required Argument.
Specifies the name of the state attribute column in the "init.state.prob" table.

state.prob.key

Required Argument.
Specifies the name of the initial probability column in the "init.state.prob" table.

trans.model.key

Required Argument.
Specifies the name of the model attribute column in the "state.transition.prob" table.

trans.from.key

Required Argument.
Specifies the name of the source state transition column in the "state.transition.prob" table.

trans.to.key

Required Argument.
Specifies the name of the target state transition column in the "state.transition.prob" table.

trans.prob.key

Required Argument. Specifies the name of the state transition probability column in the "state.transition.prob" table.

emit.model.key

Required Argument.
Specifies the name of the model attribute column in the "emission.prob" table.

emit.state.key

Required Argument.
Specifies the name of the state attribute in the "emission.prob" table.

emit.observed.key

Required Argument.
Specifies the name of the observation attribute column in the "emission.prob" table.

emit.prob.key

Required Argument.
Specifies the name of the emission probability in the "emission.prob" table.

model.key

Required Argument.
Specifies the name of the column that contains the model attribute. It must match a column in the "observation.partition.column" argument.

sequence.key

Required Argument.
Specifies the name of the column that contains the sequence attribute. It must be a sequence attribute in the "observation.partition.column" argument.

observed.key

Required Argument.
Specifies the name of the column that contains the observed symbols.
Note: Observed symbols are case-sensitive.

incremental

Optional Argument.
Specifies whether only new sequence probabilities are computed. If TRUE, only new sequence probabilities are computed. If FALSE, all probabilities are computed.
Note: If the "seq.prob.key" argument is not specified, the function cannot determine whether the observed sequence is new; therefore, all model sequences in the input tables are treated as new. Default Value: TRUE

show.rate.change

Optional Argument.
If TRUE, the function shows the percentage change that corresponds to the applied model with the difference from previous predicted probability. Default Value: TRUE

seq.prob.key

Optional Argument.
The function uses the previous value under the column to calculate the change rate.

skip.key

Optional Argument.
The name of the column whose values determine whether the function skips the row. The function skips the row if the value is "true", "yes", "y", or "1". The function does not skip the row if the value is "false", "f", "no", "n", "0", or NULL.

accumulate

Optional Argument.
Specifies the names of the columns in "observation" tibble that the function copies to the output table.

observation.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "observation". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

init.state.prob.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "init.state.prob". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

state.transition.prob.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "state.transition.prob". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

emission.prob.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "emission.prob". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_hmm_evaluator_mle" which is a named list containing Teradata tbl object.
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("hmmunsupervised_example", "loan_prediction")
    loadExampleData("hmmevaluator_example", "Pi_loan", "A_loan", "B_loan", "test_loan_prediction")
    
    # Create remote tibble objects.
    pi_loan <- tbl(con, "Pi_loan")
    A_loan <- tbl(con, "A_loan")
    B_loan <- tbl(con, "B_loan")
    test_loan_prediction <- tbl(con, "test_loan_prediction")
    loan_prediction <- tbl(con, "loan_prediction")
    
    # Train a HMM Unsupervised model on the loan prediction dataset
    td_hmm_unsupervised_out <- td_hmm_unsupervised_mle(vertices = loan_prediction,
                                                   vertices.partition.column = c("model_id", "seq_id"),
                                                   vertices.order.column = c("seq_vertex_id"),
                                                   model.key = "model_id",
                                                   sequence.key = "seq_id",
                                                   observed.key = "observed_id",
                                                   hidden.states.num = 3,
                                                   init.methods = c("random")
                                                   )
                                                   
    # Use the output of the trained model to make the evaluation for probabilities of sequences.
    # Note: Similarly, output of a trained supervised HMM model can also be used to make evaluation.
    td_hmm_evaluator_out <- td_hmm_evaluator_mle(init.state.prob = td_hmm_unsupervised_out$output.initialstate.table,
                                             init.state.prob.partition.column = c("model_id"),
                                             state.transition.prob = td_hmm_unsupervised_out$output.statetransition.table,
                                             state.transition.prob.partition.column = c("model_id"),
                                             emission.prob = td_hmm_unsupervised_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("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"
                                             )
                                             
    # Alternatively, load the trained model data from the Vantage Advanced SQL Engine tables 
    # to make the evaluations.
    td_hmm_evaluator_out1 <- td_hmm_evaluator_mle(init.state.prob = pi_loan,
                                             init.state.prob.partition.column = c("model_id"),
                                             state.transition.prob = A_loan,
                                             state.transition.prob.partition.column = c("model_id"),
                                             emission.prob = B_loan,
                                             emission.prob.partition.column = c("model_id"),
                                             observation = test_loan_prediction,
                                             observation.partition.column = c("model_id "),
                                             observation.order.column = c("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"
                                             )