FinalWeights: Array;
FinalWeights: System.Array;
The FinalWeights property returns the matrix of final synapse weights.
To determine the matrix of synapse weights, use the ISmSelfOrganizingMap.InitialWeights property.
To execute the example, add links to the Stat and MathFin system assemblies.
Sub UserProc;
Var
som: ISmSelfOrganizingMap;
x1, w, min, max: array Of double;
res, i, j, m, n: integer;
indx0: double;
Begin
som := New SmSelfOrganizingMap.Create;
m := 2; //object size
n := 4; //number of clusters
som.Objects.Clear;
x1 := New double[m];
//adding characteristics, in this case 12 objects with two characteristics
x1[0] := 27; x1[1] := 19;
som.Objects.Add.Value := x1;
x1[0] := Double.Nan; x1[1] := Double.Nan;
som.Objects.Add.Value := x1;
x1[0] := 25; x1[1] := 15;
som.Objects.Add.Value := x1;
x1[0] := 36; x1[1] := 27;
som.Objects.Add.Value := x1;
x1[0] := 35; x1[1] := 25;
som.Objects.Add.Value := x1;
x1[0] := 10; x1[1] := 43;
som.Objects.Add.Value := x1;
x1[0] := 11; x1[1] := 44;
som.Objects.Add.Value := x1;
x1[0] := 36; x1[1] := 24;
som.Objects.Add.Value := x1;
x1[0] := 26; x1[1] := 14;
som.Objects.Add.Value := x1;
x1[0] := 26; x1[1] := 14;
som.Objects.Add.Value := x1;
x1[0] := 9; x1[1] := 45;
som.Objects.Add.Value := x1;
x1[0] := 33; x1[1] := 23;
som.Objects.Add.Value := x1;
x1[0] := 27; x1[1] := 16;
som.Objects.Add.Value := x1;
x1[0] := 10; x1[1] := 47;
som.Objects.Add.Value := x1;
som.ClusterCount := 3;
som.Epoch := 10;
// network size
som.RowWidth := 2;
// Method of missing data treatment
som.MissingData.Method := MissingDataMethod.Casewise;
min := New Double[m];
max := New Double[m];
For j := 0 To m - 1 Do
min[j] := som.Objects.Item(0).Value[j];
max[j] := som.Objects.Item(0).Value[j];
End For;
For i := 1 To som.Objects.Count - 1 Do
For j := 0 To m - 1 Do
If som.Objects.Item(i).Value[j] < min[j] Then min[j] := som.Objects.Item(i).Value[j]; End If;
If som.Objects.Item(i).Value[j] > max[j] Then max[j] := som.Objects.Item(i).Value[j]; End If;
End For;
End For;
W := New double[som.ClusterCount, m];
For i := 0 To som.ClusterCount - 1 Do
For j := 0 To m - 1 Do
W[i, j] := 1 / math.Sqrt(m);
End For;
End For;
// specify weights
som.SynapsysWeights := SynapsysWeightsType.Manual;
som.InitialWeights := w;
res := som.Execute;
Debug.WriteLine(som.Errors);
Debug.WriteLine("Matrix of synapse weights");
Debug.Indent;
For i := 0 To som.ClusterCount - 1 Do // by clusters
Debug.WriteLine("Node # + i.ToString);
For j := 0 To som.Clusters.Item(i).Center.Length - 1 Do // by all objects in cluster
indx0 := som.InitialWeights[i, j];
Debug.WriteLine(indx0.ToString + ", ");
End For;
Debug.WriteLine("");
End For;
Debug.Unindent;
Debug.WriteLine("Total weights");
Debug.Indent;
For i := 0 To som.ClusterCount - 1 Do // by clusters
Debug.WriteLine("Node # + i.ToString);
For j := 0 To som.Clusters.Item(i).Center.Length - 1 Do // by all objects in cluster
indx0 := som.FinalWeights[i, j];
Debug.WriteLine(indx0.ToString + ", ");
End For;
Debug.WriteLine("");
End For;
Debug.Unindent;
End Sub UserProc;
After executing the example the console window displays the matrix of weights and total weights.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.MathFin;
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
som: ISmSelfOrganizingMap;
InitialWeights, FinalWeights, W, Value: System.Array;
x1, min, max: Array Of double;
res, i, j, m, n: integer;
indx0: double;
Begin
som := New SmSelfOrganizingMap.Create();
m := 2; //object size
n := 4; //number of clusters
som.Objects.Clear();
x1 := New double[m];
//adding characteristics, in this case 12 objects with two characteristics
x1[0] := 27; x1[1] := 19;
som.Objects.Add().Value := x1;
x1[0] := Double.Nan; x1[1] := Double.Nan;
som.Objects.Add().Value := x1;
x1[0] := 25; x1[1] := 15;
som.Objects.Add().Value := x1;
x1[0] := 36; x1[1] := 27;
som.Objects.Add().Value := x1;
x1[0] := 35; x1[1] := 25;
som.Objects.Add().Value := x1;
x1[0] := 10; x1[1] := 43;
som.Objects.Add().Value := x1;
x1[0] := 11; x1[1] := 44;
som.Objects.Add().Value := x1;
x1[0] := 36; x1[1] := 24;
som.Objects.Add().Value := x1;
x1[0] := 26; x1[1] := 14;
som.Objects.Add().Value := x1;
x1[0] := 26; x1[1] := 14;
som.Objects.Add().Value := x1;
x1[0] := 9; x1[1] := 45;
som.Objects.Add().Value := x1;
x1[0] := 33; x1[1] := 23;
som.Objects.Add().Value := x1;
x1[0] := 27; x1[1] := 16;
som.Objects.Add().Value := x1;
x1[0] := 10; x1[1] := 47;
som.Objects.Add().Value := x1;
som.ClusterCount := 3;
som.Epoch := 10;
// network size
som.RowWidth := 2;
// Method of missing data treatment
som.MissingData.Method := MissingDataMethod.mdmCasewise;
min := New Double[m];
max := New Double[m];
Value := som.Objects.Item[0].Value;
For j := 0 To m - 1 Do
min[j] := Value[j] As double;
max[j] := Value[j] As double;
End For;
For i := 1 To som.Objects.Count - 1 Do
Value := som.Objects.Item[i].Value;
For j := 0 To m - 1 Do
If (Value[j] As double) < min[j] Then min[j] := Value[j] As double; End If;
If (Value[j] As double) > max[j] Then max[j] := Value[j] As double; End If;
End For;
End For;
W := New double[som.ClusterCount, m];
For i := 0 To som.ClusterCount - 1 Do
For j := 0 To m - 1 Do
W[i, j] := 1 / System.Math.Sqrt(m);
End For;
End For;
// specify weights
som.SynapsysWeights := SynapsysWeightsType.swtManual;
som.InitialWeights := w;
res := som.Execute();
System.Diagnostics.Debug.WriteLine(som.Errors);
System.Diagnostics.Debug.WriteLine("Matrix of synapse weights");
System.Diagnostics.Debug.Indent();
InitialWeights := som.InitialWeights;
For i := 0 To som.ClusterCount - 1 Do // by clusters
System.Diagnostics.Debug.WriteLine("Node #" + i.ToString());
For j := 0 To som.Clusters.Item[i].Center.Length - 1 Do // by all objects in cluster
indx0 := InitialWeights[i, j] As double;
System.Diagnostics.Debug.WriteLine(indx0.ToString() + ", ");
End For;
System.Diagnostics.Debug.WriteLine("");
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Total weights");
System.Diagnostics.Debug.Indent();
FinalWeights := som.FinalWeights;
For i := 0 To som.ClusterCount - 1 Do // by clusters
System.Diagnostics.Debug.WriteLine("Node #" + i.ToString());
For j := 0 To som.Clusters.Item[i].Center.Length - 1 Do // by all objects in cluster
indx0 := FinalWeights[i, j] As double;
System.Diagnostics.Debug.WriteLine(indx0.ToString() + ", ");
End For;
System.Diagnostics.Debug.WriteLine("");
End For;
System.Diagnostics.Debug.Unindent();
End Sub;
See also: