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

View File

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

View File

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