- Notifications
You must be signed in to change notification settings - Fork2
Closed
Description
The following routine is proposed:
functionNormaliseByWeight(const Weights:arrayof Double): Types.TDoubleDynArray;var Weight: Double; WeightSum: Double; Idx: Integer;beginif (System.Length(Weights) =0)then raise SysUtils.EArgumentException.Create('Array of weights is empty'); WeightSum :=0.0;for Weightin Weightsdobeginif Math.Sign(Weight) = Math.NegativeValuethen 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 :=0to Pred(System.Length(Weights))do Result[Idx] := Weights[Idx] / WeightSum;end;
Metadata
Metadata
Assignees
Labels
Projects
Status
Completed