* Re: Incremental statistics functions
2004-01-26 22:59 OT: Incremental statistics functions Mats Karlssohn
` (3 preceding siblings ...)
2004-01-27 3:39 ` Steve
@ 2004-01-27 15:48 ` Joachim Schr�er
2004-01-28 0:22 ` tmoran
2004-01-27 23:44 ` OT: " Mats Karlssohn
5 siblings, 1 reply; 12+ messages in thread
From: Joachim Schr�er @ 2004-01-27 15:48 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 29558 bytes --]
Maybe the following package is of some help:
--$Id: math-generic_numerics-generic_statistics.ads,v 1.2 2003/07/11
08:50:32 schroeer Exp $
--==========================================================================
===
-- Copyright (C) EADS Dornier GmbH, Friedrichshafen
--==========================================================================
===
--
-- Filename : math-generic_numerics-generic_statistics.ads
-- Type : package spec
-- Language : Ada 95
-- Author : J. Schr�er
-- Created On : 28-Mai-2003 <13:50>
-- Last Modified By : $Author: schroeer $
-- Last Modified On : $Date: 2003/07/11 08:50:32 $
-- Update Count : $Revision: 1.2 $
-- Status :
--==========================================================================
===
-- Description : Package for simple statistics and error calculation.
with Ada.Strings.Unbounded;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_Io;
with Interfaces;
with Math.Generic_Arrays;
generic
with package Text_Io is new Ada.Text_Io.Float_Io(Float_Type);
with package Elementary_Functions is new
Ada.Numerics.Generic_Elementary_Functions(Float_Type);
with package Arrays is new Math.Generic_Arrays
(Element_Type => Float_Type, Zero => 0.0);
package Math.Generic_Numerics.Generic_Statistics is
-- Types and procedures for calculation of some statistic parameters.
--
-- See e.g.: J.S. Bendat and A.G. Piersol,
-- Engineering Applications of Correlation and Spectral
Analysis.
-- Paragraph 2.2.3 Data Averaging Operations.
--
-- x(t) : "signal" to calculate statistics parameters of.
-- x(ti) : sample at "time" ti, (ti in general an independent
variable).
-- Mean = E[x(t)] = lim(N->inf) 1/N Sum(i=1..N) x(ti)
-- Variance = E[(x(ti)-Mean)**2] = lim(N->inf) 1/N Sum(i=1..N)
(x(ti)-Mean)**2
-- Rms = Sqrt(Variance)
--
-- In general t must not be the time. You may also analyze one or two
dimensional
-- arrays of data. In the latter case you have x(t1,t2).
type Index_Array_Type is array(1 .. 2) of Integer;
subtype Delta_Array_Type is Arrays.Vector(Index_Array_Type'range);
type Statistics_Type is record
Name : Ada.Strings.Unbounded.String_Access;
-- For documentation in put.
Min : Float_type := Float_type'Last;
Max : Float_type := Float_type'First;
Min_Index : Interfaces.Unsigned_64 := 0;
Max_Index : Interfaces.Unsigned_64 := 0;
Difference : Float_type := 0.0; -- Max - Min
-- Indices incremented in each version of Update below, starting with 0.
Mean : Float_type := 0.0;
Rms : Float_Type := 0.0;
Count : Interfaces.Unsigned_64 := 0; -- Number of samples.
Float_Count : Float_type := 0.0; -- used if count overflows.
Min_Indices,
Max_Indices : Index_Array_Type := (others => Integer'First);
-- See different Update procedures below.
-- If Update with parameter Values : vector is called then
-- Min_Indices(1) is the real index of the minimum value in values,
-- dito. Max_Indices(1). If Update with parameter Values : matrix is
called
-- then Min_Indices(1..2) and Max_Indices(1..2) are the row/col indices
of the
-- min and max values.
Deltas : Delta_Array_Type := (others => 0.0);
-- Used in put to calculate values of t (or t1, t2 in case of 2-dim data
x)
-- for min_index/max_index. Minimum of x(t) at t=Deltas(1)*Min_Index(1).
-- Minimum of x(t1,t2) at t1=Deltas(1)*Min_Index(1),
t2=Deltas(2)*Min_Index(2).
-- Dito Maximum.
end record;
--------------------------------------------------------------------------
---
-- Data types for simple error analysis.
-- Used to statistically investigate the precision of algorithms.
-- A "correct" Value is compared to the algorithm output reference Ref
-- See update procedure below.
-- Absolute: Statistic parameters of "signal" x = |Value - Ref|
-- Relative: Statistic parameters of "signal" x = |Value - Ref| / Value
-- (Only used when Value /= 0)
type String_Array is array(Positive range <>) of
Ada.Strings.Unbounded.String_Access;
No_String_Array : constant String_Array(1 .. 0) := (others => null);
type Statistics_Array is array(Positive range <>) of Statistics_Type;
type Error_Type is record
Absolute : Statistics_Type;
Relative : Statistics_Type;
end record;
type Error_Array is array(Positive range <>) of Error_Type;
--------------------------------------------------------------------------
---
procedure Initialize(Item : in out Statistics_Type;
Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0));
-- Resets Item components to values as given in type decl.
-- Item.Name is only altered if Name /= ""
function Statistics_With(Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0))
return Statistics_Type;
-- Returns initialized Statistics_Type.
No_Index : constant Integer := Integer'First;
procedure Update(Item : in out Statistics_Type;
Value : in Float_Type;
Index1,
Index2 : in Integer := No_Index;
Rms : in Boolean := True);
-- Calculate statistic parameters only from the current value xi without
storing
-- the whole data array.
-- Increments count, calculates min,max,mean,rms if Rms=True.
--
-- Iteration formulas:
-- Mean = (Mean * (count - 1) + Value) / count
-- Rms = (Rms**2 * (count - 1) + (value - mean) ** 2) / count
--
-- Rms only approximated because it is calculated with the actual Mean.
-- (The Mean calculated from x1 .. xi, xi = value.
-- The correct Mean value is known after the last call).
--
-- If you want the correct values of t for min(x(t)), max(x(t)) give
Deltas in
-- Initialize and/or Statistics_With and give Index1 ( and Index2 in case
x(t1,t2) ).
procedure Update(Item : in out Statistics_Type;
Values : in Arrays.Vector;
Rms : in Boolean := True);
-- Increments count, calculates
min,max,mean,rms,min_indices(1),max_indices(1).
-- Rms correct.
procedure Update(Item : in out Statistics_Type;
Values : in Arrays.Matrix;
Rms : in Boolean := True);
-- Increments count, calculates
min,max,mean,rms,min_indices(1..2),max_indices(1..2).
-- Rms correct.
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Statistics_Type;
Aft : in Ada.Text_Io.Field := Float_type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3;
Rms : in Boolean := True);
-- Writes item to file.
--------------------------------------------------------------------------
---
-- Versions for vector "signals" x.
procedure Initialize(Item : in out Statistics_Array;
Names : in String_Array := No_String_Array;
Deltas : in Delta_Array_Type := (others => 0.0));
-- Resets Item components to values as given in type decl.
-- If Names = No_String_Array:
-- Generated Names: Item(I).Name = Name_I.
-- Deltas used for all components of array.
function Statistics_With(Names : in String_Array;
Deltas : in Delta_Array_Type := (others => 0.0))
return Statistics_Array;
-- Returns initialized Statistics_array.
procedure Update(Item : in out Statistics_Array;
Value : in Arrays.Vector;
Index1,
Index2 : in Integer := No_Index;
Rms : in Boolean := True);
-- Increments count, calculates min,max,mean,rms.
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Statistics_Array;
Aft : in Ada.Text_Io.Field := Float_type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3;
Rms : in Boolean := True);
-- Writes item to file.
--------------------------------------------------------------------------
---
-- Procedures for simple error analysis.
procedure Initialize(Item : in out Error_Type;
Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0));
-- Resets Item components to values as given in type decl.
function Error_With(Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0))
return Error_Type;
-- Returns initialized error_type.
procedure Update(Item : in out Error_Type;
Value,
Ref : in Float_type;
Index1,
Index2 : in Integer := No_Index);
-- Increments count, calculates min,max,mean,rms of abs and relative
deviation
-- of Value and Ref.
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Error_Type;
Aft : in Ada.Text_Io.Field := Float_type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3);
-- Writes item to file.
--------------------------------------------------------------------------
---
-- Versions for vector "signals" x.
procedure Initialize(Item : in out Error_Array;
Names : in String_Array := No_String_Array;
Deltas : in Delta_Array_Type := (others => 0.0));
-- Resets Item components to values as given in type decl.
function Error_With(Names : in String_Array;
Deltas : in Delta_Array_Type := (others => 0.0))
return Error_Array;
-- Returns initialized error_array.
procedure Update(Item : in out Error_Array;
Value,
Ref : in Arrays.Vector;
Index1,
Index2 : in Integer := No_Index);
-- Increments count, calculates min,max,mean,rms.
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Error_Array;
Aft : in Ada.Text_Io.Field := Float_type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3);
-- Writes item to file.
--------------------------------------------------------------------------
---
-- For testing: To generate adjacent model-numbers around a critical
number.
type Adjacent_Numbers_Array is array(Positive range <>) of
Arrays.Vector_Access;
function Adjacent_Numbers(Number : in Float_type;
Count : in Positive := 1) return Arrays.Vector;
-- Returns an array with 2*count+1 values.
-- (.., float_type'pred(number), number, float_type'succ(number), ..).
function Adjacent_Numbers(Numbers : in Arrays.Vector;
Count : in Positive := 1)
return Adjacent_Numbers_Array;
-- Returns (.., float_type'pred(number), number, float_type'succ(number),
..) for all numbers.
end Math.Generic_Numerics.Generic_Statistics;
--======================================================================
-- -*- Mode: Ada -*-
-- Filename : math-generic_numerics-generic_statistics.ads
-- Description : Package for simple statistics calculation
-- Author : J. Schr�er
-- Created On : 23.01.2003
-- Last Modified By:
-- Last Modified On:
-- Update Count : 1
-- Status :
with Utilities.String_Utilities;
with Utilities.Logging;
package body Math.Generic_Numerics.Generic_Statistics is
package String_Utilities renames Utilities.String_Utilities;
package Logging renames Utilities.Logging;
use type Interfaces.Unsigned_64;
use type Arrays.Vector;
use type Ada.Strings.Unbounded.String_Access;
use Elementary_Functions;
--========================================================================
===
procedure Put(File : in Ada.Text_IO.File_Type;
Text : in String;
Item : in Float_Type;
Fore,
Aft,
Exp : in Ada.Text_io.Field) is
begin
Ada.Text_Io.Put(File, Text);
Ada.Text_Io.Set_Col(File, 10);
Ada.Text_Io.Put(File, ":");
Text_Io.Put(File, Item, Fore, Aft, Exp);
Ada.Text_Io.New_Line(File);
end Put;
--========================================================================
===
procedure Initialize(Item : in out Statistics_Type;
Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0))
is
begin
Item := (Name => null,
Min => Float_Type'Last,
Max => Float_Type'First,
Difference => 0.0,
Min_Index => 0,
Max_Index => 0,
Mean => 0.0,
Rms => 0.0,
Count => 0,
Float_Count => 0.0,
Min_Indices |
Max_Indices => (others => Integer'First),
Deltas => Item.Deltas);
if Name /= "" then
String_Utilities.Allocate(Item.Name, 1, Name'Length);
Item.Name.All := Name;
end if;
if Deltas /= (Deltas'range => 0.0) then
Item.Deltas := Deltas;
end if;
end Initialize;
--========================================================================
===
function Statistics_With(Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0))
return Statistics_Type is
Item : Statistics_Type;
begin
Initialize(Item, Name, Deltas);
return Item;
end Statistics_With;
--========================================================================
===
procedure Update(Item : in out Statistics_Type;
Value : in Float_Type;
Index1,
Index2 : in Integer := No_Index;
Rms : in Boolean := True) is
------------------------------------------------------------------------
---
function Average_Of(Average,
Value : in Float_Type;
Count : in Interfaces.Unsigned_64) return Float_Type
is
begin
return (Average * Float_Type(Count - 1) + Value) / Float_Type(Count);
end Average_Of;
------------------------------------------------------------------------
---
-- function Average_Of(Average, Value, Count : in Float_Type) return
Float_Type is
-- begin
-- return (Average * (Count - 1.0) + Value) / Count;
-- end Average_Of;
------------------------------------------------------------------------
---
Min_Max_Altered : Boolean := False;
begin
-- if Item.Count = Interfaces.Unsigned_64'Last then
-- Item.Float_Count := Item.Float_Count + 1.0;
-- else
Item.Count := Item.Count + 1;
-- end if;
-- Assign also No_Index values. Check done in Put below.
if Value < Item.Min then
Item.Min := Value;
Item.Min_Index := Item.Count;
Item.Min_Indices(1) := Index1;
Item.Min_Indices(2) := Index2;
Min_Max_Altered := True;
end if;
if Value > Item.Max then
Item.Max := Value;
Item.Max_Index := Item.Count;
Item.Max_Indices(1) := Index1;
Item.Max_Indices(2) := Index2;
Min_Max_Altered := True;
end if;
if Min_Max_Altered then
Item.Difference := Item.Max - Item.Min;
end if;
Item.Mean := Average_Of(Average => Item.Mean,
Value => Value,
Count => Item.Count);
if Rms then
Item.Rms := Sqrt(Average_Of(Average => Item.Rms ** 2,
Value => (Item.Mean - Value) ** 2,
Count => Item.Count));
end if;
end Update;
--========================================================================
===
procedure Update(Item : in out Statistics_Type;
Values : in Arrays.Vector;
Rms : in Boolean := True) is
begin
if Values'Length = 0 then
return;
end if;
for I in Values'range loop
Item.Count := Item.Count + 1;
Item.Mean := Item.Mean + Values(I);
if Values(I) < Item.Min then
Item.Min := Values(I);
Item.Min_Index := Item.Count;
Item.Min_Indices(1) := I;
end if;
if Values(I) > Item.Max then
Item.Max := Values(I);
Item.Max_Index := Item.Count;
Item.Max_Indices(1) := I;
end if;
end loop;
Item.Difference := Item.Max - Item.Min;
Item.Mean := Item.Mean / Float_Type(Item.Count);
if Rms then
for I in Values'range loop
Item.Rms := Item.Rms + (Item.Mean - Values(I)) ** 2;
end loop;
Item.Rms := Sqrt(Item.Rms / Float_Type(Item.Count));
end if;
end Update;
--========================================================================
===
procedure Update(Item : in out Statistics_Type;
Values : in Arrays.Matrix;
Rms : in Boolean := True) is
begin
if Values'Length(1) = 0 or else Values'Length(2) = 0 then
return;
end if;
for I in Values'range(1) loop
for J in Values'range(2) loop
Item.Count := Item.Count + 1;
Item.Mean := Item.Mean + Values(I, J);
if Values(I, J) < Item.Min then
Item.Min := Values(I, J);
Item.Min_Index := Item.Count;
Item.Min_Indices(1) := I;
Item.Min_Indices(2) := J;
end if;
if Values(I, J) > Item.Max then
Item.Max := Values(I, J);
Item.Max_Index := Item.Count;
Item.Max_Indices(1) := I;
Item.Max_Indices(2) := J;
end if;
end loop;
end loop;
Item.Difference := Item.Max - Item.Min;
Item.Mean := Item.Mean / Float_Type(Item.Count);
if Rms then
for I in Values'range(1) loop
for J in Values'range(2) loop
Item.Rms := Item.Rms + (Item.Mean - Values(I, J)) ** 2;
end loop;
end loop;
Item.Rms := Sqrt(Item.Rms / Float_Type(Item.Count));
end if;
end Update;
--========================================================================
===
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Statistics_Type;
Aft : in Ada.Text_Io.Field := Float_Type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3;
Rms : in Boolean := True) is
Fore : Ada.Text_Io.Field := Text_Io.Default_Fore;
Dim : Natural := 0;
------------------------------------------------------------------------
---
procedure Put(Index : in Interfaces.Unsigned_64;
Text : in String) is
begin
Ada.Text_Io.Put(File, Text);
Ada.Text_Io.Put(File, Interfaces.Unsigned_64'Image(Index));
if Item.Deltas(1) /= 0.0 then
Ada.Text_Io.Put(File, " -> ");
Text_Io.Put(File, Float_Type(Index) * Item.Deltas(1),
Fore, Aft, Exp);
end if;
Ada.Text_Io.New_Line(File);
end Put;
------------------------------------------------------------------------
---
procedure Put(Indices : in Index_Array_Type;
Text : in String) is
begin
Ada.Text_Io.Put(File, Text);
for I in 1 .. Dim loop
Ada.Text_Io.Put(File, Integer'Image(Indices(I)));
if Item.Deltas(I) /= 0.0 then
Ada.Text_Io.Put(File, " -> ");
Text_Io.Put(File, Float_Type(Indices(I)) * Item.Deltas(I),
Fore, Aft, Exp);
end if;
if I < Dim then
Ada.Text_Io.Put(File, ",");
end if;
end loop;
Ada.Text_Io.New_Line(File);
end Put;
------------------------------------------------------------------------
---
begin
if Exp = 0 then
Fore := Float_Type'digits - 1;
end if;
if Item.Name /= null then
Ada.Text_Io.Put_Line(File, Item.Name.All);
end if;
Put(File, "Min", Item.Min, Fore, Aft, Exp);
Put(File, "Max", Item.Max, Fore, Aft, Exp);
Put(Item.Min_Index, "Min_Index:");
Put(Item.Max_Index, "Max_Index:");
Put(File, "Diff",Item.Difference, Fore, Aft, Exp);
Put(File, "Mean",Item.Mean, Fore, Aft, Exp);
if Rms then
Put(File, "Rms", Item.Rms, Fore, Aft, Exp);
end if;
Ada.Text_Io.Put_Line(File, "Count :" &
Interfaces.Unsigned_64'Image(Item.Count));
if Item.Float_Count > 0.0 then
Put(File, "Float_Count", Item.Float_Count, Fore, Aft, Exp);
end if;
for I in reverse Item.Min_Indices'range loop
if Item.Min_Indices(1) /= No_Index then
Dim := I;
exit;
end if;
end loop;
if Dim > 0 then
Ada.Text_Io.Put_Line(File, "Min-Max-Indices in array");
Put(Item.Min_Indices, "Min_Index:");
Put(Item.Max_Indices, "Max_Index:");
end if;
end Put;
--========================================================================
===
procedure Initialize(Item : in out Statistics_Array;
Names : in String_Array := No_String_Array;
Deltas : in Delta_Array_Type := (others => 0.0))
is
begin
for I in Item'range loop
if I in Names'range and then Names(I) /= null then
Initialize(Item(I), Names(I).all, Deltas);
else
Initialize(Item(I), Natural'Image(I), Deltas);
end if;
end loop;
end Initialize;
--========================================================================
===
function Statistics_With(Names : in String_Array;
Deltas : in Delta_Array_Type := (others => 0.0))
return Statistics_Array is
Item : Statistics_Array(Names'range);
begin
Initialize(Item, Names, Deltas);
return Item;
end Statistics_With;
--========================================================================
===
procedure Update(Item : in out Statistics_Array;
Value : in Arrays.Vector;
Index1,
Index2 : in Integer := No_Index;
Rms : in Boolean := True) is
begin
for I in Item'range loop
Update(Item(I), Value(I), Index1, Index2, Rms);
end loop;
end Update;
--========================================================================
===
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Statistics_Array;
Aft : in Ada.Text_Io.Field := Float_Type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3;
Rms : in Boolean := True) is
begin
for I in Item'range loop
Put(File, Item(I), Aft, Exp, Rms);
Ada.Text_Io.Put_Line(File,
"-------------------------------------------");
end loop;
end Put;
--========================================================================
===
procedure Initialize(Item : in out Error_Type;
Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0))
is
begin
Initialize(Item.Absolute, "abs-Error " & Name, Deltas);
Initialize(Item.Relative, "rel-Error " & Name, Deltas);
end Initialize;
--========================================================================
===
function Error_With(Name : in String := "";
Deltas : in Delta_Array_Type := (others => 0.0))
return Error_Type is
Item : Error_Type;
begin
Initialize(Item, Name, Deltas);
return Item;
end Error_With;
--========================================================================
===
procedure Update(Item : in out Error_Type;
Value,
Ref : in Float_Type;
Index1,
Index2 : in Integer := No_Index) is
Err : constant Float_Type := abs(Value - Ref);
Rel : Float_Type;
------------------------------------------------------------------------
---
procedure Put(File : in Ada.Text_Io.File_Type) is
begin
Ada.Text_Io.New_Line(File);
Ada.Text_Io.Put_Line(File,
"*** Statistics.Update, Abs_Err=|Value-Ref|,
Rel_Err=Abs_Err/|Value|, Value = 0");
Ada.Text_Io.Put(File, "Ref = " & Float_Type'Image(Ref));
if Index1 /= No_Index then
Ada.Text_Io.Put(File, ", Index1=" & Integer'Image(Index1));
if Index2 /= No_Index then
Ada.Text_Io.Put(File, ", Index2=" & Integer'Image(Index2));
end if;
end if;
Ada.Text_Io.New_Line(File);
end Put;
------------------------------------------------------------------------
---
begin
Update(Item.Absolute, Err, Index1, Index2);
if Value /= 0.0 then
Rel := Err / abs Value;
Update(Item.Relative, Rel, Index1, Index2);
elsif Ada.Text_Io.Is_Open(Logging.Log_File) then
Put(Logging.Log_File);
else
Put(Ada.Text_Io.Standard_Output);
end if;
end Update;
--========================================================================
===
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Error_Type;
Aft : in Ada.Text_Io.Field := Float_Type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3) is
Fore : Ada.Text_Io.Field := Text_Io.Default_Fore;
begin
if Exp = 0 then
Fore := Float_Type'digits - 1;
end if;
Put(File, Item.Absolute, Aft, Exp);
Ada.Text_Io.New_Line(File);
Put(File, Item.Relative, Aft, Exp);
end Put;
--========================================================================
===
procedure Initialize(Item : in out Error_Array;
Names : in String_Array := No_String_Array;
Deltas : in Delta_Array_Type := (others => 0.0))
is
begin
for I in Item'range loop
if I in Names'range and then Names(I) /= null then
Initialize(Item(I), Names(I).all, Deltas);
else
Initialize(Item(I), Natural'Image(I), Deltas);
end if;
end loop;
end Initialize;
--========================================================================
===
function Error_With(Names : in String_Array;
Deltas : in Delta_Array_Type := (others => 0.0))
return Error_Array is
Item : Error_Array(Names'Range);
begin
Initialize(Item, Names, Deltas);
return Item;
end Error_With;
--========================================================================
===
procedure Update(Item : in out Error_Array;
Value,
Ref : in Arrays.Vector;
Index1,
Index2 : in Integer := No_Index) is
begin
for I in Item'range loop
Update(Item(I), Value(I), Ref(I), Index1, Index2);
end loop;
end Update;
--========================================================================
===
procedure Put(File : in Ada.Text_Io.File_Type;
Item : in Error_Array;
Aft : in Ada.Text_Io.Field := Float_Type'Digits - 1;
Exp : in Ada.Text_Io.Field := 3) is
begin
for I in Item'range loop
Ada.Text_Io.Put_Line(File,
"-------------------------------------------");
Put(File, Item(I), Aft, Exp);
end loop;
Ada.Text_Io.Put_Line(File,
"-------------------------------------------");
end Put;
--========================================================================
===
function Adjacent_Numbers(Number : in Float_Type;
Count : in Positive := 1) return Arrays.Vector
is
A : Arrays.Vector(-Count .. Count);
begin
A(0) := Number;
for I in reverse -Count .. -1 loop
A(I) := Float_Type'Pred(A(I + 1));
end loop;
for I in 1 .. Count loop
A(I) := Float_Type'Succ(A(I - 1));
end loop;
return A;
end Adjacent_Numbers;
--========================================================================
===
function Adjacent_Numbers(Numbers : in Arrays.Vector;
Count : in Positive := 1)
return Adjacent_Numbers_Array is
A : Adjacent_Numbers_Array(1 .. Numbers'Length);
begin
for I in A'range loop
A(I) := new Arrays.Vector'
(Adjacent_Numbers(Number => Numbers(Numbers'First + I - 1),
Count => Count));
end loop;
return A;
end Adjacent_Numbers;
--========================================================================
===
end Math.Generic_Numerics.Generic_Statistics;
"Mats Karlssohn" <sm5tfx@telia.com> schrieb im Newsbeitrag
news:86k73e9uzk.fsf@lucretia.kaos...
> Hi
>
> I'm trying to find algorithms to calculate standard-deviation and variance
> _without_ keeping a buffer of the samples. I'm not really shure if I'm
right
> to call them incremental algorithms but I couldn't find a better
expression.
> Basically I don't want to keep a (limited) buffer of samples but would
like
> to add the values one at a time when they are calculated.
>
> Probably I googled bad, since I didn't find anything I could understand.
>
> Any suggestions please?
>
> --
> Mats Karlssohn (SM5TFX), sm5tfx@telia.com
> "Without mistakes there is no forgiving, without forgiving there is no
love"
^ permalink raw reply [flat|nested] 12+ messages in thread