Exemplo n.º 1
0
        public static string StatGetargs(string[] pnames, string[] dflts, ref string eid, ref string crit, ref string dosmooth)
        {
            string maxiter = "";

            try
            {
                eid = "";
                int      nargs     = 0;
                int      nparams   = pnames.Length;
                string[] varargout = new string[dflts.Length];
                dflts.CopyTo(varargout, 0);
                string[] unrecog = new string[1];
                crit     = dflts[1];
                dosmooth = dflts[2];
                string pname = "";
                string i     = "";

                if (nargs % 2 != 0)
                {
                    eid = "WrongNumberArgs";
                }
                else
                {
                    for (int j = 1; j <= nargs; j++)
                    {
                        pname = pnames[j];
                        CellStrMatch.GetMatchString(pname.ToLower(), pnames);
                        j++;
                    }
                }
                return(maxiter);
            }
            catch (Exception ex)
            {
                Common.LogError(ex);
                return(null);
            }
        }
Exemplo n.º 2
0
        public static double[,] LhsDesign(int n, int p)
        {
            try
            {
                bool     ok         = false;
                string   eid        = "";
                string   emsg       = "";
                string   tmp        = "";
                string   crit       = "";
                string   dosmooth   = "";
                int      matchIndex = -1;
                string[] okargs     = { "iterations", "criterion", "'smooth" };
                string[] defaults   = { "NaN", "maximin", "on" };
                int      maxiter    = -1;

                tmp = Statgetargs.StatGetargs(okargs, defaults, ref eid, ref crit, ref dosmooth);
                if ((tmp == null) || (tmp.Length == 0))
                {
                    tmp = "NaN";
                }
                else if (tmp == "NaN")
                {
                    maxiter = 5;
                }
                else
                {
                    ok = int.TryParse(tmp, out maxiter);
                    if (!ok)
                    {
                        return(null);
                    }
                }

                string[] okcrit = { "none", "maximin", "correlation" };
                matchIndex = CellStrMatch.GetMatchString(crit.ToLower(), okcrit);
                crit       = okcrit[matchIndex];
                if (dosmooth.Length == 0)
                {
                    dosmooth = "on";
                }

                double[,] X = GetSample(n, p, dosmooth);

                if (crit == "none" || Common.Get2DimensionsSize(X, 0) < 2)
                {
                    maxiter = 0;
                }
                double bestScore, newscore;
                double[,] x = new double[n, p];
                switch (crit)
                {
                case "maximin":
                    bestScore = GetScore(X, crit);

                    for (int j = 2; j <= maxiter; j++)
                    {
                        x        = GetSample(n, p, dosmooth);
                        newscore = GetScore(x, crit);
                        if (newscore > bestScore)
                        {
                            X  = new double[n, p];
                            ok = Common.Init2Dimensions(ref X, x);
                            if (!ok)
                            {
                                return(null);
                            }
                            bestScore = newscore;
                        }
                    }
                    break;

                case "correlation":
                    break;

                case "":
                    break;
                }
                return(X);
            }
            catch (Exception ex)
            {
                Common.LogError(ex);
                return(null);
            }
        }