//End of ui.cs file Contents //------------------------------------------------------------------------- //Begin of Random.cs file contents /// <summary> /// Initializes the random-number generator with a specific seed. /// </summary> public void Initialize(uint seed) { RandomNumberGenerator = new MT19937Generator(seed); betaDist = new BetaDistribution(RandomNumberGenerator); betaPrimeDist = new BetaPrimeDistribution(RandomNumberGenerator); cauchyDist = new CauchyDistribution(RandomNumberGenerator); chiDist = new ChiDistribution(RandomNumberGenerator); chiSquareDist = new ChiSquareDistribution(RandomNumberGenerator); continuousUniformDist = new ContinuousUniformDistribution(RandomNumberGenerator); erlangDist = new ErlangDistribution(RandomNumberGenerator); exponentialDist = new ExponentialDistribution(RandomNumberGenerator); fisherSnedecorDist = new FisherSnedecorDistribution(RandomNumberGenerator); fisherTippettDist = new FisherTippettDistribution(RandomNumberGenerator); gammaDist = new GammaDistribution(RandomNumberGenerator); laplaceDist = new LaplaceDistribution(RandomNumberGenerator); lognormalDist = new LognormalDistribution(RandomNumberGenerator); normalDist = new NormalDistribution(RandomNumberGenerator); paretoDist = new ParetoDistribution(RandomNumberGenerator); powerDist = new PowerDistribution(RandomNumberGenerator); rayleighDist = new RayleighDistribution(RandomNumberGenerator); studentsTDist = new StudentsTDistribution(RandomNumberGenerator); triangularDist = new TriangularDistribution(RandomNumberGenerator); weibullDist = new WeibullDistribution(RandomNumberGenerator); poissonDist = new PoissonDistribution(RandomNumberGenerator); // generator.randomGenerator = new MT19937Generator(seed); }
public void TestFisherTippettDistribution() { double[][] para = { new double[] { 3.5, 1.8, 2.912058332039094231671373, 0.1925408834888736970603423, 8.846351448275896206409006, 0.0270714609267627815304924 } }; for (int i = 0; i < para.Length; i++) { var tester = new ContDistTester(para[i], delegate(double a, double b) { var ret = new FisherTippettDistribution { Mu = a, Alpha = b }; return(ret); } ); tester.Test(1e-14); } }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("$projectname$ entry point called", "Information"); while (true) { //Thread.Sleep(200); // Make the simulation process a long running calculation ~200ms // (If it is too quick, you do not see the difference when adding new worker processes) //Trace.WriteLine("Working", "Information"); // Pick up a message from the "simulation" message queue. // Create a TaskAggregator and call GenerateAggregatedDuration // Save the simulation result (project name, run number, calculated duration) // to Azure table storage using (CalculatorDataSource dataSource = new CalculatorDataSource("simulation")) { Project project = dataSource.GetProjectFromQueueMessage(); if (project != null) { // Create a random number generator Distribution randomNumberGenerator = new FisherTippettDistribution(); // Create a TaskAggregator, passing in the RNG and the project TaskAggregator taskAggregator = new TaskAggregator(project, randomNumberGenerator); double aggregatedDuration = taskAggregator.GenerateAggregatedDuration(); dataSource.AddEntry( new ProjectCalculationEntry {Duration = aggregatedDuration, ProjectName = project.Name}, project.Name); } } // Don't bother sending back a "done" message } }
public override void Run() { while (!IsStopped) { Project project = null; if (UseMessageBus) { try { // Receive the message BrokeredMessage receivedMessage = null; receivedMessage = QueueClient.Receive(); if (receivedMessage != null) { // Process the message Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString()); project = receivedMessage.GetBody<Project>(); receivedMessage.Complete(); } } catch (MessagingException e) { if (!e.IsTransient) { Trace.WriteLine(e.Message); throw; } Thread.Sleep(10000); } catch (OperationCanceledException e) { if (!IsStopped) { Trace.WriteLine(e.Message); throw; } } } else { //------------------------------------ // Pick up a message from the "simulation" message queue. // Create a TaskAggregator and call GenerateAggregatedDuration // Save the simulation result (project name, run number, calculated duration) // to Azure table storage //using (CalculatorDataSource dataSource = new CalculatorDataSource("simulation")) //{ project = dataSource.GetProjectFromQueueMessage(); //} //------------------------------------ } if (project != null) { // Create a random number generator Distribution randomNumberGenerator = new FisherTippettDistribution(); // Create a TaskAggregator, passing in the RNG and the project TaskAggregator taskAggregator = new TaskAggregator(project, randomNumberGenerator); double aggregatedDuration = taskAggregator.GenerateAggregatedDuration(); dataSource.AddEntry( new ProjectCalculationEntry { Duration = aggregatedDuration, ProjectName = project.Name }, project.Name); } } }
/// <summary> /// Sets the distribution for operations using the current genrator /// </summary> /// <param name="distx">Distx.</param> public void setDistribution(distributions distx, Dictionary <string, double> args) { //TODO check arguments to ensure they are making a change to the distribution //otherwise throw an exception see laplace as a example of implementing this switch (distx) { case distributions.Bernoili: BernoulliDistribution x0 = new BernoulliDistribution(gen); if (args.ContainsKey("alpha")) { x0.Alpha = args["alpha"]; } else { throw new System.Exception("for Bernoili distribution you must provide an alpha"); } dist = x0; break; case distributions.Beta: BetaDistribution x1 = new BetaDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x1.Alpha = args["alpha"]; x1.Beta = args["beta"]; } else { throw new System.Exception(" for beta distribution you must provide alpha and beta"); } dist = x1; break; case distributions.BetaPrime: BetaPrimeDistribution x2 = new BetaPrimeDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x2.Alpha = args["alpha"]; x2.Beta = args["beta"]; } else { throw new System.Exception(" for betaPrime distribution you must provide alpha and beta"); } dist = x2; break; case distributions.Cauchy: CauchyDistribution x3 = new CauchyDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("gamma")) { x3.Alpha = args["alpha"]; x3.Gamma = args["gamma"]; } else { throw new System.Exception("for cauchy dist you must provide alpha and gamma"); } dist = x3; break; case distributions.Chi: ChiDistribution x4 = new ChiDistribution(gen); if (args.ContainsKey("alpha")) { x4.Alpha = (int)args["alpha"]; } else { throw new System.Exception("for chi you must provide alpha"); } dist = x4; break; case distributions.ChiSquared: ChiSquareDistribution x5 = new ChiSquareDistribution(gen); if (args.ContainsKey("alpha")) { x5.Alpha = (int)args["alpha"]; } else { throw new System.Exception("for chiSquared you must provide alpha"); } dist = x5; break; case distributions.ContinuousUniform: ContinuousUniformDistribution x6 = new ContinuousUniformDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x6.Alpha = args["alpha"]; x6.Beta = args["beta"]; } else { throw new System.Exception("for ContinuousUniform you must provide alpha and beta"); } dist = x6; break; case distributions.DiscreteUniform: DiscreteUniformDistribution x7 = new DiscreteUniformDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x7.Alpha = (int)args["alpha"]; x7.Beta = (int)args["beta"]; } else { throw new System.Exception("for discrete uniform distribution you must provide alpha and beta"); } dist = x7; break; case distributions.Erlang: ErlangDistribution x8 = new ErlangDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("lambda")) { x8.Alpha = (int)args["alpha"]; x8.Lambda = (int)args["lambda"]; } else { throw new System.Exception("for Erlang dist you must provide alpha and lambda"); } dist = x8; break; case distributions.Exponential: ExponentialDistribution x9 = new ExponentialDistribution(gen); if (args.ContainsKey("lambda")) { x9.Lambda = args["lambda"]; } else { throw new System.Exception("for exponential dist you must provide lambda"); } dist = x9; break; case distributions.FisherSnedecor: FisherSnedecorDistribution x10 = new FisherSnedecorDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x10.Alpha = (int)args["alpha"]; x10.Beta = (int)args["beta"]; } else { throw new System.Exception("for FisherSnedecor you must provide alpha and beta"); } dist = x10; break; case distributions.FisherTippett: FisherTippettDistribution x11 = new FisherTippettDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("mu")) { x11.Alpha = args["alpha"]; x11.Mu = args["mu"]; } else { throw new System.Exception("for FisherTippets you must provide alpha and mu"); } dist = x11; break; case distributions.Gamma: GammaDistribution x12 = new GammaDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("theta")) { x12.Alpha = args["alpha"]; x12.Theta = args["theta"]; } else { throw new System.Exception("for Gamma dist you must provide alpha and theta"); } dist = x12; break; case distributions.Geometric: GeometricDistribution x13 = new GeometricDistribution(gen); if (args.ContainsKey("alpha")) { x13.Alpha = args["alpha"]; } else { throw new System.Exception("Geometric distribution requires alpha value"); } dist = x13; break; case distributions.Binomial: BinomialDistribution x14 = new BinomialDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x14.Alpha = args["alpha"]; x14.Beta = (int)args["beta"]; } else { throw new System.Exception("binomial distribution requires alpha and beta"); } dist = x14; break; case distributions.None: break; case distributions.Laplace: LaplaceDistribution x15 = new LaplaceDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("mu")) { if (x15.IsValidAlpha(args["alpha"]) && x15.IsValidMu(args["mu"])) { x15.Alpha = args["alpha"]; x15.Mu = args["mu"]; } else { throw new ArgumentException("alpha must be greater than zero"); } } else { throw new System.Exception("Laplace dist requires alpha and mu"); } dist = x15; break; case distributions.LogNormal: LognormalDistribution x16 = new LognormalDistribution(gen); if (args.ContainsKey("mu") && args.ContainsKey("sigma")) { x16.Mu = args["mu"]; x16.Sigma = args["sigma"]; } else { throw new System.Exception("lognormal distribution requires mu and sigma"); } dist = x16; break; case distributions.Normal: NormalDistribution x17 = new NormalDistribution(gen); if (args.ContainsKey("mu") && args.ContainsKey("sigma")) { x17.Mu = args["mu"]; x17.Sigma = args["sigma"]; } else { throw new System.Exception("normal distribution requires mu and sigma"); } dist = x17; break; case distributions.Pareto: ParetoDistribution x18 = new ParetoDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x18.Alpha = args["alpha"]; x18.Beta = args["beta"]; } else { throw new System.Exception("pareto distribution requires alpha and beta"); } dist = x18; break; case distributions.Poisson: PoissonDistribution x19 = new PoissonDistribution(gen); if (args.ContainsKey("lambda")) { x19.Lambda = args["lambda"]; } else { throw new System.Exception("Poisson distribution requires lambda"); } dist = x19; break; case distributions.Power: PowerDistribution x20 = new PowerDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x20.Alpha = args["alpha"]; x20.Beta = args["beta"]; } else { throw new System.Exception("Power dist requires alpha and beta"); } dist = x20; break; case distributions.RayLeigh: RayleighDistribution x21 = new RayleighDistribution(gen); if (args.ContainsKey("sigma")) { x21.Sigma = args["sigma"]; } else { throw new System.Exception("Rayleigh dist requires sigma"); } dist = x21; break; case distributions.StudentsT: StudentsTDistribution x22 = new StudentsTDistribution(gen); if (args.ContainsKey("nu")) { x22.Nu = (int)args["nu"]; } else { throw new System.Exception("StudentsT dist requirres nu"); } dist = x22; break; case distributions.Triangular: TriangularDistribution x23 = new TriangularDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta") && args.ContainsKey("gamma")) { x23.Alpha = args["alpha"]; x23.Beta = args["beta"]; x23.Gamma = args["gamma"]; } else { throw new System.Exception("Triangular distribution requires alpha, beta and gamma"); } dist = x23; break; case distributions.WeiBull: WeibullDistribution x24 = new WeibullDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("lambda")) { x24.Alpha = args["alpha"]; x24.Lambda = args["lambda"]; } else { throw new System.Exception("WeiBull dist requires alpha and lambda"); } dist = x24; break; default: throw new NotImplementedException("the distribution you want has not yet been implemented " + "you could help everyone out by going and implementing it"); } }