Exemplo n.º 1
0
        private static int SuggestCategorical(List <Result> history, string tag, int size)
        {
            if (history.Count < nStartupJobs)
            {
                return(rng.Integer(size));
            }

            var(obsBelow, obsAbove) = ApSplitTrials(history, tag);

            double[] weights   = LinearForgettingWeights(obsBelow.Length);
            double[] counts    = Bincount(obsBelow, weights, size);
            double[] p         = ArrayMath.DivSum(ArrayMath.Add(counts, priorWeight));
            int[]    sample    = rng.Categorical(p, nEiCandidates);
            double[] belowLLik = ArrayMath.Log(ArrayMath.Index(p, sample));

            weights = LinearForgettingWeights(obsAbove.Length);
            counts  = Bincount(obsAbove, weights, size);
            p       = ArrayMath.DivSum(ArrayMath.Add(counts, priorWeight));
            double[] aboveLLik = ArrayMath.Log(ArrayMath.Index(p, sample));

            return(FindBest(sample, belowLLik, aboveLLik));
        }
Exemplo n.º 2
0
        private static double SuggestNumerical(List <Result> history, string tag, double low, double high, bool log, bool integer)
        {
            if (history.Count < nStartupJobs)
            {
                double x = rng.Uniform(low, high);
                if (log)
                {
                    x = Math.Exp(x);
                }
                if (integer)
                {
                    x = Math.Round(x);
                }
                return(x);
            }

            var(obsBelow, obsAbove) = ApSplitTrials(history, tag);

            if (log)
            {
                obsBelow = ArrayMath.Log(obsBelow);
                obsAbove = ArrayMath.Log(obsAbove);
            }

            double priorMu    = 0.5 * (high + low);
            double priorSigma = high - low;

            var(weights, mus, sigmas) = AdaptiveParzenNormal(obsBelow, priorMu, priorSigma);
            double[] samples   = Gmm1(weights, mus, sigmas, low, high, log, integer);
            double[] belowLLik = Gmm1Lpdf(samples, weights, mus, sigmas, low, high, log, integer);

            (weights, mus, sigmas) = AdaptiveParzenNormal(obsAbove, priorMu, priorSigma);
            double[] aboveLLik = Gmm1Lpdf(samples, weights, mus, sigmas, low, high, log, integer);

            return(FindBest(samples, belowLLik, aboveLLik));
        }