Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add function to normalise a set of weight values so that they sum to 1 #44

Closed
Assignees
Labels
completedIssue completed and committed to develop. To be closed on next release enhancementNew feature or request
@delphidabbler

Description

The following routine is proposed:

function NormaliseByWeight(const Weights: array of Double):
 Types.TDoubleDynArray;
var
 Weight: Double;
 WeightSum: Double;
 Idx: Integer;
begin
 if (System.Length(Weights) = 0) then
 raise SysUtils.EArgumentException.Create('Array of weights is empty');
 WeightSum := 0.0;
 for Weight in Weights do
 begin
 if Math.Sign(Weight) = Math.NegativeValue then
 raise SysUtils.EArgumentException.Create('Weights must all be >= 0');
 WeightSum := WeightSum + Weight;
 end;
 if Math.IsZero(WeightSum) then
 raise SysUtils.EArgumentException.Create('Sum of weights can''t be zero');
 System.SetLength(Result, System.Length(Weights));
 for Idx := 0 to Pred(System.Length(Weights)) do
 Result[Idx] := Weights[Idx] / WeightSum;
end;

Metadata

Metadata

Labels

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

Projects

Status

Completed

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /