FinallyExplained: Array;
FinallyExplained: System.Array;
The FinallyExplained property returns summary classification of the objects.
The number of classes is returned by the ISmDiscriminantAnalysis.ClassCount property.
To execute the example, add links to the MathFin, Stat system assemblies.
// Main procedure
Sub UserDiscrAn;
Var
DA: SmDiscriminantAnalysis;
y: Array[60] Of Integer;
x1, x2, x3, x4, x5, x6, x7, x8: Array[60] Of Double;
Ex: ISlSeries;
res, i, j: Integer;
indx0: Double;
resM: Array Of Integer;
str: String;
Begin
DA := New SmDiscriminantAnalysis.Create;
// Source data: sixty objects with eight attributes
For i := 0 To 59 Do
x1[i] := Math.RandBetween(95, 104);
x2[i] := Math.RandBetween(95, 104);
x3[i] := Math.RandBetween(95, 104);
x4[i] := Math.RandBetween(95, 104);
x5[i] := Math.RandBetween(95, 104);
x6[i] := Math.RandBetween(95, 104);
x7[i] := Math.RandBetween(95, 104);
x8[i] := Math.RandBetween(95, 104);
End For;
// explained series values
For i := 0 To 39 Do
y[i] := Math.RandBetweenI(1, 5);
End For;
For i := 40 To 59 Do
y[i] := -1;
End For;
// Set explained variable
DA.Explained := y;
// Set explanatory variables
Ex := DA.Explanatories;
Ex.Add.Value := x1; Ex.Add.Value := x5;
Ex.Add.Value := x2; Ex.Add.Value := x6;
Ex.Add.Value := x3; Ex.Add.Value := x7;
Ex.Add.Value := x4; Ex.Add.Value := x8;
// Run calculation and show results
If DA.Execute = 0 Then
Debug.WriteLine(" == Summary results of classification == ");
res := DA.ClassCount;
Debug.WriteLine("Number of classes: " + res.ToString);
resM := DA.ClassificationSummary;
For i := 0 To res - 1 Do
For j := 0 To res - 1 Do
str := str + " " + (resM[i, j] As Integer).ToString;
End For;
str := str + " | " + (resM[i, res] As Integer).ToString;
Debug.WriteLine(str);
str := "";
End For;
str := "- - - - - - - - ";
Debug.WriteLine(str);
str := "";
For j := 0 To DA.ClassCount - 1 Do
str := str + " " + (resM[res, j] As Integer).ToString;
End For;
str := str + " | " + (resM[res, res] As Integer).ToString;
Debug.WriteLine(str);
str := "===========================" + #13 + #10;
Debug.WriteLine(str + " == Grand average == ");
Print(DA.TotalAverage, DA.TotalAverage.Rank);
Debug.WriteLine(" == Intraclass average == ");
Print(DA.WithinAverage, DA.WithinAverage.Rank);
Debug.WriteLine(str + " == Common standard deviation == ");
Print(DA.TotalStdDev, DA.TotalStdDev.Rank);
Debug.WriteLine(" == Intraclass standard deviation == ");
Print(DA.WithinStdDev, DA.WithinStdDev.Rank);
Debug.WriteLine(str + " == Common correlation == ");
Print(DA.TotalCorrelation, DA.TotalCorrelation.Rank);
Debug.WriteLine(" == Intraclass correlation == ");
Print(DA.WithinCorrelation, DA.WithinCorrelation.Rank);
Debug.WriteLine(" == Averaged intraclass correlation == ");
Print(DA.PooledWithinCorrelation, DA.PooledWithinCorrelation.Rank);
Debug.WriteLine(str + " == Common covariance == ");
Print(DA.TotalCovariance, DA.TotalCovariance.Rank);
Debug.WriteLine(" == Intraclass covariance == ");
Print(DA.WithinCovariance, DA.WithinCovariance.Rank);
Debug.WriteLine(" == Averaged intraclass covariance == ");
Print(DA.PooledWithinCovariance, DA.PooledWithinCovariance.Rank);
Debug.WriteLine(str + " == Canonical discriminant function coefficients == ");
Debug.WriteLine(" = standardized = ");
Print(DA.StdDiscriminantFuncs, DA.StdDiscriminantFuncs.Rank);
Debug.WriteLine(" = non-standardized = ");
Print(DA.NonStdDiscriminantFuncs, DA.NonStdDiscriminantFuncs.Rank);
Debug.WriteLine(str+"==Wilkesstatistic=="); Print(DA.WilkesStatistics, DA.WilkesStatistics.Rank);
Debug.WriteLine(str + " == Fisher functions == ");
Print(DA.FishersFuncs, DA.FishersFuncs.Rank);
Debug.WriteLine(str + " == Structure matrix == ");
Print(DA.StructuralMatrix, DA.StructuralMatrix.Rank);
Debug.WriteLine(str + " == Eigenvalues == ");
Print(DA.EigenValues, DA.EigenValues.Rank);
Debug.WriteLine(str + " == Classification of variables == ");
For i := 0 To DA.FinallyExplained.Length - 1 Do
indx0 := DA.FinallyExplained[i];
Debug.WriteLine(i.ToString + ". " + indx0.ToString);
End For;
End If;
End Sub UserDiscrAn;
// Data output procedure
Sub Print(a: Array Of Double; d2: integer);
Var
ci: ICultureInfo;
i, j: integer;
s: string;
Begin
ci := CultureInfo.Current;
If d2 = 2 Then
For i := 0 To a.GetUpperBound(2) Do
s := "";
For j := 0 To a.GetUpperBound(1) Do
If Double.IsNan(a[j, i]) Then
s := s + " " + " - ";
Else
s := s + " " + ci.FormatDoublePrec(a[j, i], 2);
End If;
End For;
Debug.WriteLine(s);
End For;
Else
For i := 0 To a.GetUpperBound(1) Do
If Double.IsNan(a[i]) Then
s := s + " " + " - ";
Else
s := s + " " + ci.FormatDoublePrec(a[i], 2);
End If;
End For;
Debug.WriteLine(s);
End If;
End Sub Print;
Result of executing the main procedure: discriminatory analysis is performed for the specified data, analysis results are displayed to the console window.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
// Main procedure
Public Shared Sub UserDiscrAn();
Var
DA: SmDiscriminantAnalysis;
y: Array[60] Of Integer;
x1, x2, x3, x4, x5, x6, x7, x8: Array[60] Of Double;
Ex: ISlSeries;
res, i, j: Integer;
indx0: integer;
resM: System.Array;
str: String;
m: Prognoz.Platform.Interop.MathFin.MathClass;
Begin
DA := New SmDiscriminantAnalysis.Create();
m := New Prognoz.Platform.Interop.MathFin.MathClass.Create();
// Source data: sixty objects with eight attributes
For i := 0 To 59 Do
x1[i] := m.RandBetween(95, 104);
x2[i] := m.RandBetween(95, 104);
x3[i] := m.RandBetween(95, 104);
x4[i] := m.RandBetween(95, 104);
x5[i] := m.RandBetween(95, 104);
x6[i] := m.RandBetween(95, 104);
x7[i] := m.RandBetween(95, 104);
x8[i] := m.RandBetween(95, 104);
End For;
// explained series values
For i := 0 To 39 Do
y[i] := m.RandBetweenI(1, 5);
End For;
For i := 40 To 59 Do
y[i] := -1;
End For;
// Set explained variable
DA.Explained := y;
// Set explanatory variables
Ex := DA.Explanatories;
Ex.Add().Value := x1; Ex.Add().Value := x5;
Ex.Add().Value := x2; Ex.Add().Value := x6;
Ex.Add().Value := x3; Ex.Add().Value := x7;
Ex.Add().Value := x4; Ex.Add().Value := x8;
// Run calculation and show results
If DA.Execute() = 0 Then
res := DA.ClassCount;
System.Diagnostics.Debug.WriteLine("Number of classes: " + res.ToString());
resM := DA.ClassificationSummary;
For i := 0 To res - 1 Do
For j := 0 To res - 1 Do
str := str + " " + (m.Int(resM[i, j] As integer)).ToString();
End For;
str := str + " | " + (m.Int(resM[i, res] As integer)).ToString();
System.Diagnostics.Debug.WriteLine(str);
str := "";
End For;
str := "- - - - - - - - ";
System.Diagnostics.Debug.WriteLine(str);
str := "";
For j := 0 To res - 1 Do
str := str + " " + (m.Int(resM[res, j] As integer)).ToString();
End For;
str := str + " | " + (m.Int(resM[res, res] As integer)).ToString();
System.Diagnostics.Debug.WriteLine(str);
str := "==========================="; System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Grand average == ");
Print(DA.TotalAverage, DA.TotalAverage.Rank);
System.Diagnostics.Debug.WriteLine(" == Intraclass average == ");
Print(DA.WithinAverage, DA.WithinAverage.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Common standard deviation == ");
Print(DA.TotalStdDev, DA.TotalStdDev.Rank);
System.Diagnostics.Debug.WriteLine(" == Intraclass standard deviation == ");
Print(DA.WithinStdDev, DA.WithinStdDev.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Common correlation == ");
Print(DA.TotalCorrelation, DA.TotalCorrelation.Rank);
System.Diagnostics.Debug.WriteLine(" == Intraclass correlation == ");
Print(DA.WithinCorrelation, DA.WithinCorrelation.Rank);
System.Diagnostics.Debug.WriteLine(" == Averaged intraclass correlation == ");
Print(DA.PooledWithinCorrelation, DA.PooledWithinCorrelation.Rank);
System.Diagnostics.Debug.WriteLine(str + " == Common covariance == ");
Print(DA.TotalCovariance, DA.TotalCovariance.Rank);
System.Diagnostics.Debug.WriteLine(" == Intraclass covariance == ");
Print(DA.WithinCovariance, DA.WithinCovariance.Rank);
System.Diagnostics.Debug.WriteLine(" == Averaged intraclass covariance == ");
Print(DA.PooledWithinCovariance, DA.PooledWithinCovariance.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Canonical discriminant function coefficients == ");
System.Diagnostics.Debug.WriteLine(" = standardized = ");
Print(DA.StdDiscriminantFuncs, DA.StdDiscriminantFuncs.Rank);
System.Diagnostics.Debug.WriteLine(" = non-standardized = ");
Print(DA.NonStdDiscriminantFuncs, DA.NonStdDiscriminantFuncs.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine("==Wilkesstatistic=="); Print(DA.WilkesStatistics, DA.WilkesStatistics.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Fisher functions == ");
Print(DA.FishersFuncs, DA.FishersFuncs.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Structure matrix == ");
Print(DA.StructuralMatrix, DA.StructuralMatrix.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Eigenvalues == ");
Print(DA.EigenValues, DA.EigenValues.Rank);
System.Diagnostics.Debug.WriteLine(str);
System.Diagnostics.Debug.WriteLine(" == Classification of variables == ");
resM := DA.FinallyExplained;
For i := 0 To resM.Length - 1 Do
indx0 := resM[i] As integer;
System.Diagnostics.Debug.WriteLine(i.ToString() + ". " + indx0.ToString());
End For;
End If;
End Sub UserDiscrAn;
// Data output procedure
Public Shared Sub Print(a: System.Array; d2: integer);
Var
cc: CultureInfoClassClass;
ci: iCultureInfo;
i, j: integer;
s: string;
Begin
cc := New CultureInfoClassClass.Create();
ci := cc.Current;
If d2 = 2 Then
For i := 0 To a.GetUpperBound(1) Do
s := "";
For j := 0 To a.GetUpperBound(0) Do
If Double.IsNan(a[j, i] As double) Then
s := s + " " + " - ";
Else
s := s + " " + ci.FormatDoublePrec(a[j, i] As double, 2);
End If;
End For;
System.Diagnostics.Debug.WriteLine(s);
End For;
Else
For i := 0 To a.GetUpperBound(0) Do
If Double.IsNan(a[i] As double) Then
s := s + " " + " - ";
Else
s := s + " " + ci.FormatDoublePrec(a[i] As double, 2);
End If;
End For;
System.Diagnostics.Debug.WriteLine(s);
End If;
End Sub Print;
See also: