LazStats: Some refactoring of HierarchUnit. Some clean-up elsewhere.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7888 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-11-16 14:40:24 +00:00
parent eb017ea8b7
commit 5b9d42bcba
4 changed files with 36 additions and 69 deletions

View File

@ -1,7 +1,4 @@
// Sample file for testing: cansas.laz, use all variiables.
// WARNING: THE OUTPUT OF THIS FORM DOES NOT AGREE WITH THE SAME FORM OF
// OPENSTAT OR STATS4U
// Sample file for testing: cansas.laz, use all variables.
unit HierarchUnit;
@ -70,7 +67,7 @@ implementation
uses
TAChartUtils, TACustomSeries,
Utils, GridProcs, DataProcs, ChartFrameUnit;
Utils, GridProcs, ChartFrameUnit;
{ THierarchForm }
@ -87,11 +84,6 @@ begin
FStatsReportFrame.Align := alClient;
StatsPage.PageIndex := 1;
{$IFDEF OLD_PLOTS}
if GraphFrm = nil then
Application.CreateForm(TGraphFrm, GraphFrm);
{$ENDIF}
PageControl.ActivePageIndex := 0;
end;
@ -108,7 +100,7 @@ end;
procedure THierarchForm.Compute;
label next1;
//label next1;
var
varLabels: StrDyneVec = nil;
rowLabels: StrDyneVec = nil;
@ -150,27 +142,13 @@ begin
SetLength(ColSelected,NoSelected);
nCols := NoSelected;
nRows := NoCases;
for i := 0 to nCols-1 do // nCols = NoSelected!
begin
varLabels[i] := PredList.Items[i];
colSelected[i] := GetVariableIndex(OS3MainFrm.DataGrid, varLabels[i]);
end;
{
for i := 0 to nCols - 1 do
begin
cellstring := PredList.Items.Strings[i];
for j := 1 to NoVariables do
begin
if (cellstring = OS3MainFrm.DataGrid.Cells[j,0]) then
begin
varlabels[i] := cellstring;
ColSelected[i] := j;
end;
end;
end;
}
for i := 0 to NoCases-1 do rowLabels[i] := OS3MainFrm.DataGrid.Cells[0, i+1]; //IntToStr(i);
for i := 0 to NoCases-1 do
rowLabels[i] := OS3MainFrm.DataGrid.Cells[0, i+1]; //IntToStr(i);
end else
begin
SetLength(w2,NoSelected);
@ -195,20 +173,6 @@ begin
rowLabels[i] := PredList.Items[i];
colSelected[i] := GetVariableIndex(OS3MainFrm.DataGrid, rowLabels[i]);
end;
{
for i := 0 to nRows - 1 do
begin
cellstring := PredList.Items.Strings[i];
for j := 1 to NoVariables do
begin
if (cellstring = OS3MainFrm.DataGrid.Cells[j,0]) then
begin
ColSelected[i] := j;
rowlabels[i] := cellstring;
end;
end;
end;
}
for i := 0 to NoCases-1 do
varlabels[i] := OS3MainFrm.DataGrid.Cells[0, i+1]; //IntToStr(i);
end;
@ -237,7 +201,7 @@ begin
count := 0;
for i := 1 to nRows do
begin
if (not GoodRecord(i,NoSelected,ColSelected)) then continue;
if (not GoodRecord(OS3MainFrm.DataGrid, i, ColSelected)) then continue;
count := count + 1;
for j := 1 to Ncols do
begin
@ -259,10 +223,10 @@ begin
begin
// if (not GoodRecord(i,NoSelected,ColSelected)) then continue;
count := count + 1;
col := ColSelected[i];
for j := 0 to Ncols-1 do // actually grid rows in this case
begin
// if (not GoodRecord(j,NoSelected,ColSelected)) then continue;
col := ColSelected[i];
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[col, j+1]));
means[j] := means[j] + X;
variances[j] := variances[j] + (X * X);
@ -308,7 +272,7 @@ begin
begin
for i := 0 to nRows-1 do
begin
if not GoodRecord(i+1, NoSelected, ColSelected) then continue;
if not GoodRecord(OS3MainFrm.DataGrid, i+1, ColSelected) then continue;
for j := 0 to nCols-1 do
begin
col := ColSelected[j];
@ -318,12 +282,12 @@ begin
end;
// Convert data matrix to initial matrix of error potentials
for i := 1 to Nrows do
for i := 1 to nRows do
begin
// if (not GoodRecord(i,NoSelected,ColSelected)) then continue;
for j := 1 to Ncols do
W[j-1] := Distance[i-1,j-1];
for j := i to Nrows do
for j := 0 to nCols-1 do
W[j] := Distance[i-1, j];
for j := i to nRows do
begin
// if (not GoodRecord(i,NoSelected,ColSelected)) then continue;
Distance[i-1,j-1] := 0.0;
@ -332,8 +296,8 @@ begin
Distance[i-1,j-1] := Distance[i-1,j-1] / 2.0;
end;
end;
for i := 1 to Nrows do
for j := i to Nrows do Distance[j-1,i-1] := 0.0;
for i := 1 to nRows do
for j := i to nRows do Distance[j-1,i-1] := 0.0;
// Now, group the cases for maximum groups down
if MaxGrpsChk.Checked then
@ -351,22 +315,22 @@ begin
end;
// Locate optimal combination, if more than 2 groups remain
{
next1:
n3 := n3 - 1;
if (n3 > 1) then
begin
}
repeat;
n3 := n3 - 1;
//repeat;
// n3 := n3 - 1;
x1 := 100000000000.0;
for i := 1 to Nrows do
x1 := MAX_FLOAT;
for i := 1 to nRows do
begin
if (k5[i-1] = i) then
begin
for j := i to Nrows do
for j := i to nRows do
begin
if ((i <> j) and (k5[j-1] = j)) then
begin
@ -395,9 +359,9 @@ next1:
x1 := Distance[L-1,M-1] * w3;
Y := Distance[L-1,L-1] * w2[L-1] + Distance[M-1,M-1] * w2[M-1];
Distance[L-1,L-1] := Distance[L-1,M-1];
for i := 1 to Nrows do
if (k5[i-1] = M) then k5[i-1] := L;
for i := 1 to Nrows do
for i := 0 to nRows-1 do
if (k5[i] = M) then k5[i] := L;
for i := 1 to nRows do
begin
if ((i <> L) and (k5[i-1] = i)) then
begin
@ -418,8 +382,7 @@ next1:
end;
w2[L-1] := w3;
if (n3 > k1) then
//Continue;
goto next1;
Continue;
// Print group memberships of all objects, if optioned
if MembersChk.Checked then
@ -430,7 +393,7 @@ next1:
if (k5[i-1] = i) then
begin
L := 0;
for j := 1 to Nrows do
for j := 1 to nRows do
begin
if (k5[j-1] = i) then
begin
@ -449,9 +412,9 @@ next1:
end; // next i
lReport.Add('');
end;
goto next1;
//until n3 = 2;
end; // end if
//goto next1;
until n3 = 2;
//end; // end if
FReportFrame.DisplayReport(lReport);

View File

@ -667,7 +667,8 @@ procedure TSelectIfFrm.parse(var Expression: string; var ExprList: StrDyneVec;
var NoExpr: integer; var Ops: StrDyneVec; var LeftValue: StrDyneVec;
var RightValue: StrDyneVec; var JoinOps: StrDyneVec);
var
OpPos, i, OpLong : integer;
OpLong: Integer = -1;
OpPos, i: integer;
tempstr: String;
tempstr2: string = '';
chr: string = '';

View File

@ -115,7 +115,8 @@ end;
procedure TTransFrm.ComputeBtnClick(Sender: TObject);
var
i, TIndex, v1col, v2col, gridcol : integer;
index, pcntile : DblDyneVec;
index: DblDyneVec = nil;
pcntile: DblDyneVec = nil;
cellstring : string;
TwoArgs : boolean;
constant, mean, stddev, N, X, Y, Z : double;

View File

@ -71,6 +71,8 @@ const
TOL = 0.0005;
MAX_FLOAT: Double = 1E308;
DEFAULT_CONFIDENCE_LEVEL_PERCENT = 95.0;
DEFAULT_ALPHA_LEVEL = 0.05;
DEFAULT_BETA_LEVEL = 0.20;