-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move routines into BBS.Numerical namespace and add some simple statis…
…tics.
- Loading branch information
1 parent
85f3e96
commit 7d2a313
Showing
10 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
with "..\BBS-Ada\bbs.gpr"; | ||
with "../BBS-Ada/bbs.gpr"; | ||
|
||
library project Numerical is | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--with Ada.Text_IO; | ||
--with Ada.Float_Text_IO; | ||
with Ada.Numerics.Generic_Elementary_Functions; | ||
package body BBS.Numerical.Statistics is | ||
-- | ||
-- Compute the mean of an array of data | ||
-- | ||
function mean(d : data_array) return F is | ||
sum : F := 0.0; | ||
begin | ||
for i in d'Range loop | ||
sum := sum + d(i); | ||
end loop; | ||
return sum/F(d'Length); | ||
end; | ||
-- | ||
-- Compute the limits of an array of data | ||
-- | ||
procedure limits(d : data_array; min : out F; max : out F) is | ||
begin | ||
min := d(d'First); | ||
max := d(d'First); | ||
for i in (d'First + 1) .. d'Last loop | ||
if d(i) > max then | ||
max := d(i); | ||
end if; | ||
if d(i) < min then | ||
min := d(i); | ||
end if; | ||
end loop; | ||
end; | ||
-- | ||
-- Compute the variance (and mean) of an array of data. Use this, | ||
-- instead of mean() if you need both values. | ||
-- | ||
procedure variance(d : data_array; var : out F; mean : out F) is | ||
sum2 : F := 0.0; | ||
sum : F := 0.0; | ||
begin | ||
for i in d'Range loop | ||
sum := sum + d(i); | ||
sum2 := sum2 + (d(i)*d(i)); | ||
end loop; | ||
mean := sum/F(d'Length); | ||
var := (sum2 - sum*sum/F(d'Length))/F(d'Length - 1); | ||
end; | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
generic | ||
type F is digits <>; | ||
package BBS.Numerical.statistics is | ||
type data_array is array (Integer range <>) of F; | ||
-- | ||
-- Compute the mean of an array of data | ||
-- | ||
function mean(d : data_array) return F; | ||
-- | ||
-- Compute the median of an array of data | ||
-- | ||
procedure limits(d : data_array; min : out F; max : out F); | ||
-- | ||
-- Compute the variance (and mean) of an array of data. Use this, | ||
-- instead of mean() if you need both values. | ||
-- | ||
procedure variance(d : data_array; var : out F; mean : out F); | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/bbs-integration_real.adb → src/BBS-Numerical-integration_real.adb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/bbs-integration_real.ads → src/BBS-Numerical-integration_real.ads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- | ||
-- Empty package to create a namespace. Common items may be added here | ||
-- later. | ||
-- | ||
package BBS.Numerical is | ||
-- Currently empty. | ||
end; |