public void RandomNormalTestWithStddev() { RandomNormal rn = new RandomNormal(2018, 0.0f, 4.2f); Assert.AreEqual(firstValue * 4.2, rn.NextDouble(), epsilon); Assert.AreEqual(secondValue * 4.2, rn.NextDouble(), epsilon); }
public void RandomNormalTestTwoDouble() { RandomNormal rn = new RandomNormal(2018); Assert.AreEqual(firstValue, rn.NextDouble(), epsilon); Assert.AreEqual(secondValue, rn.NextDouble(), epsilon); }
public void RandomNormalTestWithMean() { RandomNormal rn = new RandomNormal(2018, 5.0f); Assert.AreEqual(firstValue + 5.0, rn.NextDouble(), epsilon); Assert.AreEqual(secondValue + 5.0, rn.NextDouble(), epsilon); }
public void RandomNormalTestWithStddev() { var rn = new RandomNormal(2018, 0.0f, 4.2f); Assert.AreEqual(k_FirstValue * 4.2, rn.NextDouble(), k_Epsilon); Assert.AreEqual(k_SecondValue * 4.2, rn.NextDouble(), k_Epsilon); }
public void RandomNormalTestTwoDouble() { var rn = new RandomNormal(2018); Assert.AreEqual(k_FirstValue, rn.NextDouble(), k_Epsilon); Assert.AreEqual(k_SecondValue, rn.NextDouble(), k_Epsilon); }
public void RandomNormalTestWithMean() { var rn = new RandomNormal(2018, 5.0f); Assert.AreEqual(k_FirstValue + 5.0, rn.NextDouble(), k_Epsilon); Assert.AreEqual(k_SecondValue + 5.0, rn.NextDouble(), k_Epsilon); }
public void RandomNormalTestWithMeanStddev() { RandomNormal rn = new RandomNormal(2018, -3.2f, 2.2f); Assert.AreEqual(-4.2266, rn.NextDouble(), 0.0001); Assert.AreEqual(-4.0357, rn.NextDouble(), 0.0001); }
public void RandomNormalTestWithStddev() { RandomNormal rn = new RandomNormal(2018, 1.0f, 4.2f); Assert.AreEqual(-0.9599, rn.NextDouble(), 0.0001); Assert.AreEqual(-0.5955, rn.NextDouble(), 0.0001); }
public void RandomNormalTestWithMean() { RandomNormal rn = new RandomNormal(2018, 5.0f); Assert.AreEqual(4.53333, rn.NextDouble(), 0.0001); Assert.AreEqual(4.6201, rn.NextDouble(), 0.0001); }
public void RandomNormalTestTwoDouble() { RandomNormal rn = new RandomNormal(2018); Assert.AreEqual(-0.46666, rn.NextDouble(), 0.0001); Assert.AreEqual(-0.37989, rn.NextDouble(), 0.0001); }
public void RandomNormalTestWithMeanStddev() { float mean = -3.2f; float stddev = 2.2f; RandomNormal rn = new RandomNormal(2018, mean, stddev); Assert.AreEqual(firstValue * stddev + mean, rn.NextDouble(), epsilon); Assert.AreEqual(secondValue * stddev + mean, rn.NextDouble(), epsilon); }
public void RandomNormalTestWithMeanStddev() { const float mean = -3.2f; const float stddev = 2.2f; var rn = new RandomNormal(2018, mean, stddev); Assert.AreEqual(k_FirstValue * stddev + mean, rn.NextDouble(), k_Epsilon); Assert.AreEqual(k_SecondValue * stddev + mean, rn.NextDouble(), k_Epsilon); }
/// <summary> /// Fill a pre-allocated Tensor with random numbers /// </summary> /// <param name="tensorProxy">The pre-allocated Tensor to fill</param> /// <param name="randomNormal">RandomNormal object used to populate tensor</param> /// <exception cref="NotImplementedException"> /// Throws when trying to fill a Tensor of type other than float /// </exception> /// <exception cref="ArgumentNullException"> /// Throws when the Tensor is not allocated /// </exception> public static void FillTensorWithRandomNormal( TensorProxy tensorProxy, RandomNormal randomNormal) { if (tensorProxy.DataType != typeof(float)) { throw new NotImplementedException("Only float data types are currently supported"); } if (tensorProxy.data == null) { throw new ArgumentNullException(); } for (var i = 0; i < tensorProxy.data.length; i++) { tensorProxy.data[i] = (float)randomNormal.NextDouble(); } }
public void RandomNormalTestDistribution() { float mean = -3.2f; float stddev = 2.2f; RandomNormal rn = new RandomNormal(2018, mean, stddev); int numSamples = 100000; // Adapted from https://www.johndcook.com/blog/standard_deviation/ // Computes stddev and mean without losing precision double oldM = 0.0, newM = 0.0, oldS = 0.0, newS = 0.0; for (int i = 0; i < numSamples; i++) { double x = rn.NextDouble(); if (i == 0) { oldM = newM = x; oldS = 0.0; } else { newM = oldM + (x - oldM) / i; newS = oldS + (x - oldM) * (x - newM); // set up for next iteration oldM = newM; oldS = newS; } } double sampleMean = newM; double sampleVariance = newS / (numSamples - 1); double sampleStddev = Math.Sqrt(sampleVariance); // Note a larger epsilon here. We could get closer to the true values with more samples. Assert.AreEqual(mean, sampleMean, 0.01); Assert.AreEqual(stddev, sampleStddev, 0.01); }
public static Func <float> CreateGaussianSampler(float mean, float stddev, int seed) { RandomNormal distr = new RandomNormal(seed, mean, stddev); return(() => (float)distr.NextDouble()); }