Esempio n. 1
0
        /// <summary>
        /// Keep only the top K results from the history.
        /// </summary>
        /// <param name="history">set of all history.</param>
        /// <returns>The best K points contained in the history.</returns>
        private IRunResult[] TruncateHistory(IRunResult[] history)
        {
            SortedSet <RunResult> bestK = new SortedSet <RunResult>();

            foreach (RunResult r in history)
            {
                RunResult worst = bestK.Min();

                if (bestK.Count < _args.HistoryLength || r.CompareTo(worst) > 0)
                {
                    bestK.Add(r);
                }

                if (bestK.Count > _args.HistoryLength)
                {
                    bestK.Remove(worst);
                }
            }

            return(bestK.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Does a mix of greedy local search around best performing parameter sets, while throwing random parameter sets into the mix.
        /// </summary>
        /// <param name="parents">Beginning locations for local greedy search.</param>
        /// <param name="forest">Trained random forest, used later for evaluating parameters.</param>
        /// <param name="numOfCandidates">Number of candidate configurations returned by the method (top K).</param>
        /// <param name="previousRuns">Historical run results.</param>
        /// <returns>Array of parameter sets, which will then be evaluated.</returns>
        private ParameterSet[] GreedyPlusRandomSearch(ParameterSet[] parents, FastForestRegressionModelParameters forest, int numOfCandidates, IEnumerable <IRunResult> previousRuns)
        {
            // REVIEW: The IsMetricMaximizing flag affects the comparator, so that
            // performing Max() should get the best, regardless of if it is maximizing or
            // minimizing.
            RunResult bestRun  = (RunResult)previousRuns.Max();
            RunResult worstRun = (RunResult)previousRuns.Min();
            double    bestVal  = bestRun.IsMetricMaximizing ? bestRun.MetricValue : worstRun.MetricValue - bestRun.MetricValue;

            HashSet <Tuple <double, ParameterSet> > configurations = new HashSet <Tuple <double, ParameterSet> >();

            // Perform local search.
            foreach (ParameterSet c in parents)
            {
                Tuple <double, ParameterSet> bestChildKvp = LocalSearch(c, forest, bestVal, _args.Epsilon);
                configurations.Add(bestChildKvp);
            }

            // Additional set of random configurations to choose from during local search.
            ParameterSet[] randomConfigs = _randomSweeper.ProposeSweeps(_args.NumRandomEISearchConfigurations, previousRuns);
            double[]       randomEIs     = EvaluateConfigurationsByEI(forest, bestVal, randomConfigs);
            AutoMlUtils.Assert(randomConfigs.Length == randomEIs.Length);

            for (int i = 0; i < randomConfigs.Length; i++)
            {
                configurations.Add(new Tuple <double, ParameterSet>(randomEIs[i], randomConfigs[i]));
            }

            HashSet <ParameterSet> retainedConfigs = new HashSet <ParameterSet>();
            IOrderedEnumerable <Tuple <double, ParameterSet> > bestConfigurations = configurations.OrderByDescending(x => x.Item1);

            foreach (Tuple <double, ParameterSet> t in bestConfigurations.Take(numOfCandidates))
            {
                retainedConfigs.Add(t.Item2);
            }

            return(retainedConfigs.ToArray());
        }