Modus_weighted

Aggregation functions modus_weighted

syntax

  • modus_weighted(a, weight)
  • modus_weighted(a, weight, relation)

definition

  • modus_weighted(a, weight) results in the parameter with the value of attribute a for the maximum sum of the values of the weight Attribute.
  • modus_weighted(a, weight, relation) results in an attribute with the values of attribute a for the maximum sum of the values of the weight attribute, grouped by relation. The Domain unit of the resulting attribute is the Values unit of the relation.

description

The weights are summed per value of a, and per group with relation, as floating point numbers, and the sums are compared as such. When several values share the largest sum, the lowest of them is the result. A group in which no value has a positive sum results in null (in 0 for bool, uint2 and uint4, which have no null). Null values of a are skipped; values outside the range of the values unit of a are summed like any other value and can be the result, as for Modus.

applies to

  • attribute a with uint2, uint4, uint8, uint16, uint32 or bool Value type
  • attribute weight with Numeric value type
  • relation with value type of the group CanBeDomainUnit

A Null weight is skipped, with and without relation: values [1, 1, 2] with weights [5, null, 1] result in 1.

conditions

  1. The values unit of the resulting Data item should match with regard to value type and Metric with the values unit of attribute a.
  2. The domain unit of arguments a, weight and relation must match, also without relation: pairing attributes of two different domain units is an error.

performance

  • The weights are summed in a table with a sum for each value in the range of the values unit of a, for each group with relation, when the table has no more sums than a has elements: O(n + v·p) time and O(v·p) memory, with n the number of elements of a, v the number of values in that range and p the number of groups (1 without relation). A values unit without a range of its own, such as uint8 or uint32 itself, has a sum for every non-null value of its value type. The weights of values outside the range are summed apart, per distinct value. bool, uint2 and uint4 values are always summed in a table.
  • Otherwise the sums are kept per distinct value in sorted order: O(n·log(k)) time, with k the number of distinct values (per group).

example

1. parameter<uint32> modus_wLifeStyleCode                := 
    modus_weighted(City/LifeStyleCode, City/NrInhabitants); result = 0
2. attribute<uint32> modus_wLifeStyleCodeRegion (Region) :=
    modus_weighted(
       City/LifeStyleCode
     , City/NrInhabitants
     , City/Region_rel
  );
City/LifeStyleCode City/NrInhabitants City/Region_rel
2 550 0
0 525 1
1 300 2
0 500 1
1 200 3
1 175 null
null null 3

domain City, nr of rows = 7

modus_wLifeStyleCodeRegion
2
0
1
1
null

domain Region, nr of rows = 5

see also