Skip to content

Add power mean functions #33

Closed
Closed
@delphidabbler

Description

@delphidabbler

Power mean

A power mean (or generalised mean) is a mean of the form

image

where all x are >= 0.

Source: Statistics How To & Wolfram MathWorld

function PowerMean(const A: array of Extended; Lambda: Extended): Extended;
begin
  Assert(not IsZero(Lambda));
  Assert(Length(A) > 0);
  var Sum: Extended := 0.0;
  for var X in A do
  begin
    Assert(Sign(X) <> NegativeValue);
    Sum := Sum + Power(X, Lambda);
  end;
  Result := Power(Sum / Length(A), 1 / Lambda);
end;

Weighted power mean

There's also the weighted power mean:

Screenshot_20230719-204835_Chrome~2

When all weights w sum to 1 then denominator is 1 and can be ignored.

Source: Statistics How To and Wikipedia


This issue was extracted from issue #16

Metadata

Metadata

Assignees

Labels

completedIssue completed and committed to develop. To be closed on next releaseenhancementNew feature or request

Projects

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions