MarkLogic Server 11.0 Product Documentation
cts:covariance

cts:covariance(
   $value1 as cts:reference,
   $value2 as cts:reference,
   [$options as xs:string*],
   [$query as cts:query?],
   [$forest-ids as xs:unsignedLong*]
) as xs:double?

Summary

Returns the frequency-weighted sample covariance given a 2-way co-occurrence. The co-occurrence is formed from the specified value lexicons. This function works like math:covariance except each pair in the co-occurrence is counted cts:frequency times. This function performs the calculation in parallel in all data nodes then aggregates the values.

Parameters
value1 Reference to a range index. The type of the range index must be numeric.
value2 Reference to a range index. The type of the range index must be numeric.
options Same as the "options" parameter in cts:aggregate.
query Same as the "query" parameter in cts:aggregate.
forest-ids Same as the "forest-ids" parameter in cts:aggregate.

Example

  xquery version "1.0-ml";

  (:
     This query assumes range indexes with positions are
     configured in the database for both xval and yval. It
     generates some sample data and then performs the
     aggregation in a separate transaction.
  :)
  for $i in 1 to 10
  let $j := 2 * $i
  return
    xdmp:document-insert(fn:concat($i, ".xml"),
      <a><xval>{$i}</xval>{
        for $a in 1 to $i
        return <yval>{$j}</yval>
      }</a>
    );

  cts:covariance(
    cts:element-reference(xs:QName("yval")),
    cts:element-reference(xs:QName("xval")),
    ("item-frequency"))

  => 12.2222222222222
Powered by MarkLogic Server | Terms of Use | Privacy Policy