Пример #1
0
    /// <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");
        }
    }