Teradata R Package Function Reference | 17.00 - 17.00 - HMMEvaluator - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

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,
      init.state.prob.order.column = NULL,
      state.transition.prob.order.column = NULL,
      emission.prob.order.column = NULL
  )

Arguments

init.state.prob

Required Argument.
Specifies a tbl_teradata that contains the initial state information.

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 partition.
Types: character OR vector of Strings (character)

init.state.prob.order.column

Optional Argument.
Specifies the Order By columns for "init.state.prob".
Values to this argument can be provided as vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

state.transition.prob

Required Argument.
Specifies a tbl_teradata that contains the state transition information.

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 partition.
Types: character OR vector of Strings (character)

state.transition.prob.order.column

Optional Argument.
Specifies the Order By columns for "state.transition.prob".
Values to this argument can be provided as vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

emission.prob

Required Argument.
Specifies a tbl_teradata that contains the emission probability information.

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 partition.
Types: character OR vector of Strings (character)

emission.prob.order.column

Optional Argument.
Specifies the Order By columns for "emission.prob".
Values to this argument can be provided as vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

observation

Required Argument.
Specifies a tbl_teradata that contains the observation information 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 partition.
Types: character OR vector of Strings (character)

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.
Types: character OR vector of Strings (character)

state.model.key

Required Argument.
Specifies the name of the model attribute column in the "init.state.prob" tbl_teradata.
Types: character OR vector of Strings (character)

state.key

Required Argument.
Specifies the name of the state attribute column in the "init.state.prob" tbl_teradata.
Types: character OR vector of Strings (character)

state.prob.key

Required Argument.
Specifies the name of the initial probability column in the "init.state.prob" tbl_teradata.
Types: character OR vector of Strings (character)

trans.model.key

Required Argument.
Specifies the name of the model attribute column in the "state.transition.prob" tbl_teradata.
Types: character OR vector of Strings (character)

trans.from.key

Required Argument.
Specifies the name of the source state transition column in the "state.transition.prob" tbl_teradata.
Types: character OR vector of Strings (character)

trans.to.key

Required Argument.
Specifies the name of the target state transition column in the "state.transition.prob" tbl_teradata.
Types: character OR vector of Strings (character)

trans.prob.key

Required Argument.
Specifies the name of the state transition probability column in the "state.transition.prob" tbl_teradata.
Types: character OR vector of Strings (character)

emit.model.key

Required Argument.
Specifies the name of the model attribute column in the "emission.prob" tbl_teradata.
Types: character OR vector of Strings (character)

emit.state.key

Required Argument.
Specifies the name of the state attribute in the "emission.prob" tbl_teradata.
Types: character OR vector of Strings (character)

emit.observed.key

Required Argument.
Specifies the name of the observation attribute column in the "emission.prob" tbl_teradata.
Types: character OR vector of Strings (character)

emit.prob.key

Required Argument.
Specifies the name of the emission probability in the "emission.prob" tbl_teradata.
Types: character OR vector of Strings (character)

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.
Types: character

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.
Types: character

observed.key

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

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 tbl_teradata are treated as new.
Default Value: TRUE
Types: logical

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
Types: logical

seq.prob.key

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

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.
Types: character

accumulate

Optional Argument.
Specifies the names of the columns in "observation" tbl_teradata that the function copies to the output tbl_teradata.
Types: character OR vector of Strings (character)

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.
Types: character OR vector of Strings (character)

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.
Types: character OR vector of Strings (character)

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.
Types: character OR vector of Strings (character)

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.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_hmm_evaluator_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("hmmunsupervised_example", "loan_prediction")
    loadExampleData("hmmevaluator_example", "Pi_loan", "A_loan", "B_loan", "test_loan_prediction")

    # Create object(s) of class "tbl_teradata".
    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 td_hmm_unsupervised_mle() function 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 td_hmm_supervised_mle() function 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"
                                             )