Skip to content

Modus_weighted

MaartenHilferink edited this page Oct 7, 2026 · 21 revisions

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

Since GeoDMS 20.23.1 a null weight is skipped also in modus_weighted(a, weight) without relation, as it already was with one. Before, a null weight made the total of its value undefined, and the result was then decided by the order of the values: values [1, 1, 2] with weights [5, null, 1] resulted in 2 instead of 1. Results of such data calculated with an older version have to be recalculated.

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. Since GeoDMS 20.23.1 this is also checked for modus_weighted(a, weight) without relation, as it already was with one: a configuration that pairs attributes of two different domain units now stops with an error. Before, weight was read element by element along a, beyond its end when its domain was smaller, and the result was meaningless.

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

Clone this wiki locally