public CentralLimitMersenneTwisterGaussianRng(MersenneTwisterUniformRng rng) : this(NQuantLibcPINVOKE.new_CentralLimitMersenneTwisterGaussianRng(MersenneTwisterUniformRng.getCPtr(rng)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public MersenneTwisterUniformRsg(uint dimensionality, MersenneTwisterUniformRng rng) : this(NQuantLibcPINVOKE.new_MersenneTwisterUniformRsg__SWIG_0(dimensionality, MersenneTwisterUniformRng.getCPtr(rng)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public MoroInvCumulativeMersenneTwisterGaussianRng(MersenneTwisterUniformRng rng) : this(NQuantLibcPINVOKE.new_MoroInvCumulativeMersenneTwisterGaussianRng(MersenneTwisterUniformRng.getCPtr(rng)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public void testIncrementalStatistics() { // Testing incremental statistics MersenneTwisterUniformRng mt = new MersenneTwisterUniformRng(42); IncrementalStatistics stat = new IncrementalStatistics(); for (int i = 0; i < 500000; ++i) { double x = 2.0 * (mt.nextReal() - 0.5) * 1234.0; double w = mt.nextReal(); stat.add(x, w); } if (stat.samples() != 500000) { QAssert.Fail("stat.samples() (" + stat.samples() + ") can not be reproduced against cached result (" + 500000 + ")"); } TEST_INC_STAT(stat.weightSum(), 2.5003623600676749e+05); TEST_INC_STAT(stat.mean(), 4.9122325964293845e-01); TEST_INC_STAT(stat.variance(), 5.0706503959683329e+05); TEST_INC_STAT(stat.standardDeviation(), 7.1208499464378076e+02); TEST_INC_STAT(stat.errorEstimate(), 1.0070402569876076e+00); TEST_INC_STAT(stat.skewness(), -1.7360169326720038e-03); TEST_INC_STAT(stat.kurtosis(), -1.1990742562085395e+00); TEST_INC_STAT(stat.min(), -1.2339945045639761e+03); TEST_INC_STAT(stat.max(), 1.2339958308008499e+03); TEST_INC_STAT(stat.downsideVariance(), 5.0786776146975247e+05); TEST_INC_STAT(stat.downsideDeviation(), 7.1264841364431061e+02); // This is a test for numerical stability, actual implementation fails //InverseCumulativeRng<MersenneTwisterUniformRng,InverseCumulativeNormal> normal_gen = // new InverseCumulativeRng<MersenneTwisterUniformRng, InverseCumulativeNormal>(mt); //IncrementalStatistics stat2 = new IncrementalStatistics(); //for (int i = 0; i < 500000; ++i) //{ // double x = normal_gen.next().value * 1E-1 + 1E8; // double w = 1.0; // stat2.add(x, w); //} //double tol = 1E-5; //if(Math.Abs( stat2.variance() - 1E-2 ) > tol) // QAssert.Fail("variance (" + stat2.variance() + ") out of expected range " + 1E-2 + " +- " + tol); }
public void testSpareMatrixReference() { int rows = 10; int columns = 10; int nMatrices = 5; int nElements = 50; MersenneTwisterUniformRng rng = new MersenneTwisterUniformRng(1234); SparseMatrix expected = new SparseMatrix(rows, columns); List <SparseMatrix> refs = new List <SparseMatrix>(); for (int i = 0; i < nMatrices; ++i) { SparseMatrix m = new SparseMatrix(rows, columns); for (int j = 0; j < nElements; ++j) { int row = Convert.ToInt32(rng.next().value *rows); int column = Convert.ToInt32(rng.next().value *columns); double value = rng.next().value; m[row, column] += value; expected[row, column] += value; } refs.Add(m); } SparseMatrix calculated = refs.accumulate(1, refs.Count, refs[0], (a, b) => a + b); for (int i = 0; i < rows; ++i) { for (int j = 0; j < columns; ++j) { if (Math.Abs(calculated[i, j] - expected[i, j]) > 100 * Const.QL_EPSILON) { QAssert.Fail("Error using sparse matrix references in " + "Element (" + i + ", " + j + ")" + "\n expected : " + expected[i, j] + "\n calculated: " + calculated[i, j]); } } } }
public void testQRSolve() { // Testing QR solve... setup(); double tol = 1.0e-12; MersenneTwisterUniformRng rng = new MersenneTwisterUniformRng(1234); Matrix bigM = new Matrix(50, 100, 0.0); for (int i = 0; i < Math.Min(bigM.rows(), bigM.columns()); ++i) { bigM[i, i] = i + 1.0; } Matrix[] testMatrices = { M1, M2, M3, Matrix.transpose(M3), M4, Matrix.transpose(M4), M5, I, M7,bigM, Matrix.transpose(bigM) }; for (int j = 0; j < testMatrices.Length; j++) { Matrix A = testMatrices[j]; Vector b = new Vector(A.rows()); for (int k = 0; k < 10; ++k) { for (int i = 0; i < b.Count; ++i) { b[i] = rng.next().value; } Vector x = MatrixUtilities.qrSolve(A, b, true); if (A.columns() >= A.rows()) { if (norm(A * x - b) > tol) { QAssert.Fail("A*x does not match vector b (norm = " + norm(A * x - b) + ")"); } } else { // use the SVD to calculate the reference values int n = A.columns(); Vector xr = new Vector(n, 0.0); SVD svd = new SVD(A); Matrix V = svd.V(); Matrix U = svd.U(); Vector w = svd.singularValues(); double threshold = n * Const.QL_EPSILON; for (int i = 0; i < n; ++i) { if (w[i] > threshold) { double u = 0; int zero = 0; for (int kk = 0; kk < U.rows(); kk++) { u += (U[kk, i] * b[zero++]) / w[i]; } for (int jj = 0; jj < n; ++jj) { xr[jj] += u * V[jj, i]; } } } if (norm(xr - x) > tol) { QAssert.Fail("least square solution does not match (norm = " + norm(x - xr) + ")"); } } } } }
public MersenneTwisterUniformRsg(uint dimensionality, MersenneTwisterUniformRng rng) : this(NQuantLibcPINVOKE.new_MersenneTwisterUniformRsg(dimensionality, MersenneTwisterUniformRng.getCPtr(rng)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); }
public MoroInvCumulativeMersenneTwisterGaussianRng(MersenneTwisterUniformRng rng) : this(NQuantLibcPINVOKE.new_MoroInvCumulativeMersenneTwisterGaussianRng(MersenneTwisterUniformRng.getCPtr(rng)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MersenneTwisterUniformRng obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MersenneTwisterUniformRng obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public ModFourthDeJong() { uniformRng_ = new MersenneTwisterUniformRng(4711); }
public CentralLimitMersenneTwisterGaussianRng(MersenneTwisterUniformRng rng) : this(NQuantLibcPINVOKE.new_CentralLimitMersenneTwisterGaussianRng(MersenneTwisterUniformRng.getCPtr(rng)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); }