K: Integer;
K: integer;
The K property determines the dimension of distribution.
This value must meet the following condition: K ≥ 1.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
Distrib: ISmMultiNormalDistribution;
Mu, Sigma, MultiRandom, MultiRandomVector: Array Of Double;
i, j: Integer;
d: Integer = 2;
Cnt: Integer = 10;
Begin
Distrib := New SmMultiNormalDistribution.Create;
Distrib.K := d;
Mu := New Double[d];
Mu[0] := -1; Mu[1] := 0;
Distrib.Mu := Mu;
Sigma := New Double[d, d];
Sigma[0, 0] := 2; Sigma[0, 1] := 0;
Sigma[1, 0] := 0; Sigma[1, 1] := 1;
Distrib.Sigma := Sigma;
MultiRandom := Distrib.MultiRandom;
Debug.WriteLine("-- Generated vector --");
For i := 0 To d - 1 Do
Debug.Write(MultiRandom[i]);
Debug.Write("; ");
End For;
Debug.WriteLine("");
Debug.WriteLine("-- Generated matrix --");
MultiRandomVector := Distrib.MultiRandomVector(Cnt);
For i := 0 To Cnt - 1 Do
For j := 0 To d - 1 Do
Debug.Write(MultiRandomVector[i, j]);
Debug.Write("; ");
End For;
Debug.WriteLine("");
End For;
End Sub UserProc;
After executing the example the console window shows vector and matrix of pseudo-random numbers from multivariate normal distribution.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
Distrib: ISmMultiNormalDistribution;
Mu, Sigma, MultiRandom, MultiRandomVector: System.Array;
i, j: Integer;
d: Integer = 2;
Cnt: Integer = 10;
Begin
Distrib := New SmMultiNormalDistribution.Create();
Distrib.K := d;
Mu := New Double[d];
Mu[0] := -1; Mu[1] := 0;
Distrib.Mu := Mu;
Sigma := New Double[d, d];
Sigma[0, 0] := 2; Sigma[0, 1] := 0;
Sigma[1, 0] := 0; Sigma[1, 1] := 1;
Distrib.Sigma := Sigma;
MultiRandom := Distrib.MultiRandom();
System.Diagnostics.Debug.WriteLine("-- Generated vector --");
For i := 0 To d - 1 Do
System.Diagnostics.Debug.Write(MultiRandom[i]);
System.Diagnostics.Debug.Write("; ");
End For;
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine("-- Generated matrix --");
MultiRandomVector := Distrib.MultiRandomVector(Cnt);
For i := 0 To Cnt - 1 Do
For j := 0 To d - 1 Do
System.Diagnostics.Debug.Write(MultiRandomVector[j, i]);
System.Diagnostics.Debug.Write("; ");
End For;
System.Diagnostics.Debug.WriteLine("");
End For;
End Sub;
After executing the example the console window shows vector and matrix of pseudo-random numbers from multivariate normal distribution.
See also: