Loading TOC...

cts.correlation

cts.correlation(
   $value1 as cts.reference,
   $value2 as cts.reference,
   [$options as String[]],
   [$query as cts.query?],
   [$forest-ids as String[]]
) as Number?

Summary

Returns the frequency-weighted correlation given a 2-way co-occurrence. The co-occurence is formed from the specified value lexicons. This function works like math:correlation except each pair in the input lexicons 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

//   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.

//  Generate data:
declareUpdate();

for (x=1; x<11; x++) {
  var j = 2 * x;
  var o = new Object();
  o.xval = x;
  o.yval = [];
  for (y=0; y<x; y++) {
    o.yval.push(j);
  };
  xdmp.documentInsert(("cov" + x + ".json"), o);
};

*******
// Run the query:
cts.correlation(
  cts.jsonPropertyReference("xval","type=int"),
  cts.jsonPropertyReference("yval","type=int"),
    ["item-frequency"]);
=>
1

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy