public static IEnumerable<Z2<float>> TestData() { var g = new MathNet.Numerics.Distributions.Normal(0.0, 1.0); var randy = new MathNet.Numerics.Random.MersenneTwister(); g.RandomSource = randy; var dblsX = new double[100000]; var dblsY = new double[100000]; g.Samples(dblsX); g.Samples(dblsY); return dblsX.Select((d,i) => new Z2<float>((float)d, (float)dblsY[i])); }
public void validate_general_constructor_with_gaussian_profiletype_for_custom_circular_source_test() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var ps = new CustomCircularSource(_outRad, _inRad, _bdFWHM, _polRange, _aziRange, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[31]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[32]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[33]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[34]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[35]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[36]), ACCEPTABLE_PRECISION); }
private void GenerateUCube(DISTRIBUTION d) { if (array != null) { return; } array = new double[number_of_sims][][]; var uniform = new MathNet.Numerics.Random.MersenneTwister(seed); var normal = new MathNet.Numerics.Distributions.Normal(0, 1, uniform); Func <double[]> rgn = null; switch (d) { case DISTRIBUTION.UNIFORM: rgn = () => { return(uniform.NextDoubles((int)number_of_steps)); }; break; case DISTRIBUTION.NORMAL: rgn = () => { double[] r = new double[number_of_steps]; normal.Samples(r); return(r); }; break; } for (UInt64 i = 0; i < number_of_sims; ++i) { array[i] = new double[number_of_dims][]; for (UInt64 j = 0; j < number_of_dims; ++j) { array[i][j] = rgn(); } } }
public void validate_general_constructor_with_gaussian_profiletype_for_directional_rectangular_source_test() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var profile = new GaussianSourceProfile(_bdFWHM); var ps = new DirectionalRectangularSource(_polarAngle, _lengthX, _widthY, profile, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[91]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[92]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[93]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[94]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[95]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[96]), ACCEPTABLE_PRECISION); }
public void validate_general_constructor_with_flat_profiletype_for_isotropic_line_source_test() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var beamDiameterFWHM = -1.0; // flat profile var ps = new IsotropicLineSource(_lengthX, beamDiameterFWHM, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[42]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[43]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[44]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[45]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[46]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[47]), ACCEPTABLE_PRECISION); }
public void validate_general_constructor_with_flat_profiletype_for_custom_point_source_test() { read_data(); Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); // todo: remove var ps = new CustomPointSource(_polRange, _aziRange, _direction, _translation) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[16]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[17]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[18]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[19]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[20]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[21]), ACCEPTABLE_PRECISION); }
public static SortedMap <DateTime, double> Generate(DateTime startDate, DateTime endDate, TimeSpan step, double annualizedVolatility, double drift = 0.0, double daysPerYear = 365.25, int?seed = null) { if (startDate > endDate) { throw new ArgumentException(); } int capacity = (int)((endDate - startDate).Ticks / step.Ticks); var current = 0.0; var sm = new SortedMap <DateTime, double>(capacity) { { startDate, current } }; var tDelta = step.Ticks / (daysPerYear * TimeSpan.TicksPerDay); var driftPerStep = drift * tDelta; var dt = startDate + step; seed = seed ?? (new System.Random()).Next(int.MinValue, int.MaxValue); #if NET451 var gen = new MathNet.Numerics.Random.MersenneTwister(seed.Value, false); var nd = new Normal(0.0, annualizedVolatility * Math.Sqrt(tDelta)); #else //throw new PlatformNotSupportedException("TODO"); var nd2 = new Statistics.Distribution.Normal(0.0, annualizedVolatility * Math.Sqrt(tDelta)); var gen = new Statistics.MT19937(unchecked ((uint)seed.Value)); #endif while (dt < endDate) { #if NET451 var random = nd.Sample(); #else var random = Statistics.draw(gen, nd2); #endif current += driftPerStep + random; dt = dt + step; sm.Add(dt, current); } return(sm); }
public void validate_general_constructor_with_gaussian_profiletype_for_custom_elliptical_source_test() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var profile = new GaussianSourceProfile(_bdFWHM); var ps = new CustomEllipticalSource(_aParameter, _bParameter, profile, _polRange, _aziRange, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[55]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[56]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[57]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[58]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[59]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[60]), ACCEPTABLE_PRECISION); }
public void validate_general_constructor_with_gaussian_profiletype_for_isotropic_line_source_test() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var profile = new GaussianSourceProfile(_bdFWHM); var ps = new IsotropicLineSource(_lengthX, profile, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[48]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[49]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[50]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[51]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[52]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[53]), ACCEPTABLE_PRECISION); }
public void validate_general_constructor_with_flat_profiletype_for_directional_line_source_test() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var profile = new FlatSourceProfile(); var ps = new DirectionalLineSource(_polarAngle, _lengthX, profile, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[30]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[31]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[32]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[33]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[34]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[35]), ACCEPTABLE_PRECISION); }
public void validate_general_constructor_with_flat_profiletype_for_directional_rectangular_source_test() { read_data(); Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var beamDiameterFWHM = -1.0; // flat beam var ps = new DirectionalRectangularSource(_polarAngle, _lengthX, _widthY, beamDiameterFWHM, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[85]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[86]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[87]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[88]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[89]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[90]), ACCEPTABLE_PRECISION); }
// 50년 누적값이 몇개의 난수셋을 거치면서 안정되는지 확인 public static void TestRandom2() { var rd = new MathNet.Numerics.Random.MersenneTwister(); var normalD = new MathNet.Numerics.Distributions.Normal(); double val = 0.0; double avg = 0.0; List <double> avgVal = new List <double>(); for (int i = 1; i <= 1000000; i++) { double cumVal = 1.0; for (int j = 0; j < 50; j++) { val = normalD.InverseCumulativeDistribution(rd.NextDouble()); cumVal *= 1.0 + (val / 10.0); } if (i == 1) { avg = cumVal; } else { avg = avg * (Convert.ToDouble(i - 1) / Convert.ToDouble(i)) + cumVal * (1 / Convert.ToDouble(i)); } // 1000개마다 평균값을 저장 if (i % 1000 == 0) { avgVal.Add(avg); } } }
public void validate_general_constructor_with_flat_profiletype_for_custom_rectangular_source_test() { read_data(); Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var profile = new FlatSourceProfile(); var ps = new CustomRectangularSource(_lengthX, _widthY, profile, _polRange, _aziRange, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[73]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[74]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[75]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[76]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[77]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[78]), ACCEPTABLE_PRECISION); }
public void validate_general_constructor_with_flat_profiletype_for_custom_elliptical_source_test() { read_data(); Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default ITissue tissue = new MultiLayerTissue(); var beamDiameterFWHM = -1.0; // flat beam var ps = new CustomEllipticalSource(_aParameter, _bParameter, beamDiameterFWHM, _polRange, _aziRange, _direction, _translation, _angPair) { Rng = rng }; var photon = ps.GetNextPhoton(tissue); Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[49]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[50]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[51]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.X - _tp[52]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[53]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[54]), ACCEPTABLE_PRECISION); }
public override void UpdateDistribution() { MathNet.Numerics.Random.RandomSource rand; if(RandomSeed) { rand = new MathNet.Numerics.Random.MersenneTwister(); } else { rand = new MathNet.Numerics.Random.MersenneTwister(Seed); } _gauss = new MathNet.Numerics.Distributions.Normal(_mean, _deviation, rand); }
public Vector CollapseValue(double value, int bucketIndex) { var prng = new MersenneTwisterPrng(bucketIndex); return(ArrayUtils.Init(Dimension, reductionIndex => value * GenF(reductionIndex, prng)).ToVector()); }
static void Main(string[] args) { var games = PokerCore.Data.FullHistory.LoadHistoryBin(@"C:\Data\Poker\2015-11-03_STA_NL10_SH_QLVWN231\binary.dat"); var preflopModel = new PokerCore.Model.PreflopKNN(games); BinaryFormatter bf = new BinaryFormatter(); int count = 0; using (FileStream fs = new FileStream(@"C:\Data\Poker\2015-11-03_STA_NL10_SH_QLVWN231\binary.dat", FileMode.OpenOrCreate)) using (GZipStream zs = new GZipStream(fs, CompressionLevel.Fastest)) { foreach (var game in PokerCore.Data.FullHistory.LoadHistoryHH(@"C:\Data\Poker\2015-11-03_STA_NL10_SH_QLVWN231").Take(100000)) { bf.Serialize(zs, game); count++; if (count % 100 == 0) { Console.WriteLine(count); } } } CudafyModes.Target = eGPUType.OpenCL; // To use OpenCL, change this enum CudafyModes.DeviceId = 0; CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL || CudafyModes.Target == eGPUType.Emulator ? eLanguage.OpenCL : eLanguage.Cuda; CudafyTranslator.GenerateDebug = true; var hands = PokerCore.Gpu.Hand.RandomHands(7, 256 * 256 * 256 * 2).ToArray(); //var hands = new Card[][] { new[] { Card.KingClubs, Card.KingDiamonds, Card.EightDiamonds, Card.SixHearts, Card.EightClubs, Card.SevenClubs, Card.TwoClubs } } // .Select(c => PokerCore.Gpu.Hand.ConvertHand(c)).ToArray(); var o = PokerCore.Gpu.Hand.Evaluate(hands, 7); for (int i = 0; i < hands.Length; i++) { var s = PokerCore.Gpu.Hand.DescriptionFromMask(hands[i], o[i]); var hs = PokerCore.Gpu.Hand.MaskToString(hands[i]); } var rnd = new MathNet.Numerics.Random.MersenneTwister(); var deck = new Deck(rnd); while (true) { deck.ResetAndShuffle(); Card[] c; Hand.Sort7Rank(c = new Card[] { deck.DealCard(), deck.DealCard(), deck.DealCard(), deck.DealCard(), deck.DealCard(), deck.DealCard(), deck.DealCard() }); var p = CardRank.Two; for (var i = 0; i < c.Length; i++) { if (c[i].Rank < p) { throw new Exception(); } p = c[i].Rank; } } }