VectorDistance
Description
The td_vector_distance_sqle()
function accepts a tbl_teradata of target vectors and a tbl_teradata of reference vectors and
returns output containing the distance between target-reference pairs.
The function computes the distance between the target pair and the reference pair from the same input
if you provide only one input.
You must have the same column order in the "target.feature.columns" argument and the "ref.feature.columns"
argument. The function ignores the feature values during distance computation if the value is either
NULL, NAN, or INF.
The function returns N*N output if you use the "topk" value as -1 because the function includes
all reference vectors in the output.
Notes:
The algorithm used in this function is of the order of N*N (where N is the number of rows). Hence, expect the function to run significantly longer as the number of rows increases in either the "target.data" or the "reference.data".
Because the reference data is copied to the spool for each AMP before running the query, the user spool limits the size and scalability of the input.
This function requires the UTF8 client character set for UNICODE data.
This function does not support Pass Through Characters (PTCs). For information about PTCs, see Teradata Vantage™ - Analytics Database International Character Set Support.
This function does not support KanjiSJIS or Graphic data types.
Usage
td_vector_distance_sqle (
target.data = NULL,
reference.data = NULL,
target.id.column = NULL,
target.feature.columns = NULL,
ref.id.column = NULL,
ref.feature.columns = NULL,
distance.measure = "COSINE",
topk = 10,
...
)
Arguments
target.data |
Required Argument. |
reference.data |
Optional Argument. |
target.id.column |
Required Argument. |
target.feature.columns |
Required Argument. |
ref.id.column |
Optional Argument. |
ref.feature.columns |
Optional Argument. |
distance.measure |
Optional Argument.
Types: character OR vector of Strings (character) |
topk |
Optional Argument. |
... |
Specifies the generic keyword arguments SQLE functions accept. Below
are the generic keyword arguments: volatile: Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:
Note: |
Value
Function returns an object of class "td_vector_distance_sqle"
which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator
using the name(s):result
Examples
# Get the current context/connection.
con <- td_get_context()$connection
# Load the example data.
loadExampleData("tdplyr_example", "target_mobile_data_dense",
"ref_mobile_data_dense")
# Create tbl_teradata object.
target_mobile_data_dense <- tbl(con, "target_mobile_data_dense")
ref_mobile_data_dense <- tbl(con, "ref_mobile_data_dense")
# Check the list of available analytic functions.
display_analytic_functions()
# Example 1 : Compute the cosine, euclidean, manhattan distance
# between the target and reference vectors.
VectorDistance_out <- td_vector_distance_sqle(
target.id.column="userid",
target.feature.columns=c('CallDuration',
'DataCounter',
'SMS'),
ref.id.column="userid",
ref.feature.columns=c('CallDuration',
'DataCounter',
'SMS'),
distance.measure=c('Cosine', 'Euclidean',
'Manhattan'),
topk=2,
target.data=target_mobile_data_dense,
reference.data=ref_mobile_data_dense)
# Print the result.
print(VectorDistance_out$result)