コード例 #1
0
        protected override Parameters CreateParamSet(ISweepable sweepable)
        {
            var indexs = this.GetSelectedIndexForEachPipe();

            this.start += 1;
            return(new Parameters(sweepable.SweepableValueGenerators.Select((param, i) => param[indexs[i]])));
        }
コード例 #2
0
        public virtual IEnumerable <IDictionary <string, string> > ProposeSweeps(ISweepable sweepable, int maxSweeps, IEnumerable <IRunResult> previousRuns = null)
        {
            Parameters candidate;

            if (previousRuns != null)
            {
                this._history.Concat(previousRuns);
            }

            for (int i = 0; i != maxSweeps; ++i)
            {
                for (int j = 0; j != this._options.Retry; ++j)
                {
                    candidate = this.CreateParamSet(sweepable);
                    if (!AlreadyGenerated(candidate, this._history.Select(x => x.ParameterSet)) &&
                        !this._generated.Contains(candidate))
                    {
                        this._generated.Add(candidate);
                        yield return(candidate.ParameterValues);

                        break;
                    }
                }
            }
        }
コード例 #3
0
 public IEnumerable <IDictionary <string, string> > ProposeSweeps(ISweepable sweepingSpace, int maxSweeps = 100, IEnumerable <IRunResult> previousRuns = null)
 {
     using (var stream = new StreamReader(SearchSpaceJson))
     {
         var json       = stream.ReadToEnd();
         var parameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
         yield return(parameters);
     }
 }
コード例 #4
0
        /// <summary>
        /// Propose parameter sets that can be used by <see cref="ISweepable{T}.BuildFromParameterSet(Parameters)"/>.
        /// </summary>
        /// <param name="sweepable">objects that implement <see cref="ISweepable"/>.</param>
        /// <param name="maxSweeps">max sweep iteration. If greater than the total grid points, the number of total grid points will be used instead.</param>
        /// <param name="previousRuns">previous run, which will be used to avoid proposing duplicate parameterset if provided.</param>
        /// <returns><see cref="IEnumerable{ParameterSet}"/>.</returns>
        public override IEnumerable <IDictionary <string, string> > ProposeSweeps(ISweepable sweepable, int maxSweeps, IEnumerable <IRunResult> previousRuns = null)
        {
            this.start       = 0;
            this.basePerPipe = sweepable.SweepableValueGenerators.Select(x => x.Count).ToArray();
            long accumulateCount = 1;

            this.accumulateCountPerBase = Enumerable.Repeat(0L, sweepable.SweepableValueGenerators.Count()).ToArray();
            for (int i = 0; i != sweepable.SweepableValueGenerators.Count(); ++i)
            {
                this.accumulateCountPerBase[i] = accumulateCount;
                accumulateCount *= this.basePerPipe[i];
            }

            this.total = accumulateCount;

            if (maxSweeps > this.total)
            {
                maxSweeps = (int)this.total;
            }

            return(base.ProposeSweeps(sweepable, maxSweeps, previousRuns));
        }
コード例 #5
0
 protected abstract Parameters CreateParamSet(ISweepable sweepable);
コード例 #6
0
 protected override Parameters CreateParamSet(ISweepable sweepable)
 {
     return(new Parameters(sweepable.SweepableValueGenerators.Select(sweepParameter => sweepParameter[this._rand.Next(sweepParameter.Count)])));
 }
コード例 #7
0
 protected override Parameters CreateParamSet(ISweepable sweepable)
 {
     return(new Parameters(sweepable.SweepableValueGenerators.Select(sweepParameter => sweepParameter.CreateFromNormalized(this._rand.NextDouble()))));
 }
コード例 #8
0
        public IEnumerable <IDictionary <string, string> > ProposeSweeps(ISweepable sweepable, int maxSweeps = 100, IEnumerable <IRunResult> previousRuns = null)
        {
            this._valueGenerators = sweepable.SweepableValueGenerators;
            if (previousRuns != null)
            {
                foreach (var history in previousRuns)
                {
                    this._runHistory.Add(history);
                }
            }

            for (int i = 0; i != maxSweeps; ++i)
            {
                if (this._runHistory.Count < this._option.InitialPopulation)
                {
                    var randomSweepResult = this._randomSweeper.ProposeSweeps(sweepable, 1, this._runHistory).First();
                    this._generated.Add(randomSweepResult);
                    yield return(randomSweepResult);
                }
                else
                {
                    // Get K best paramater set
                    IEnumerable <IRunResult> kBestParents;
                    if (this._runHistory.First().IsMetricMaximizing)
                    {
                        kBestParents = this._runHistory.OrderByDescending((result) => result.MetricValue).Take(this._option.KBestParents);
                    }
                    else
                    {
                        kBestParents = this._runHistory.OrderBy((result) => result.MetricValue).Take(this._option.KBestParents);
                    }

                    // Get K*N one-step sample from kBestParents.
                    var candidates = new List <IDictionary <string, string> >();
                    foreach (var parent in kBestParents)
                    {
                        var parameter = new Parameters(parent.ParameterSet.Select(kv =>
                        {
                            var generator = this._valueGenerators.Where(g => g.Name == kv.Key).FirstOrDefault();
                            return(generator.CreateFromString(kv.Value));
                        }));
                        var _candidates = this.GetOneMutationNeighbourhood(parameter);
                        candidates.AddRange(_candidates);
                    }

                    // add some random samples
                    var random_sample = this._randomSweeper.ProposeSweeps(sweepable, 20, this._runHistory).ToList();
                    candidates.AddRange(random_sample);

                    // prepare train data
                    var X_train  = this.CreateNDarrayFromParamaters(this._runHistory.Select(history => history.ParameterSet));
                    var y_train  = np.array(this._runHistory.Select(x => x.IsMetricMaximizing ? (double)x.MetricValue : -(double)x.MetricValue).ToArray()).reshape(-1, 1);
                    var X_sample = this.CreateNDarrayFromParamaters(candidates);

                    // fit
                    (var predict_y, var std, var cov) = this._regressor.Fit(X_train, y_train).Transform(X_sample);

                    // calulate ei
                    var ei            = GaussProcessSweeper.EI(predict_y.reshape(-1, 1), std.reshape(-1, 1), np.max(y_train));
                    var bestCandidate = (int)np.argmax(ei);

                    if ((double)np.max(ei) <= 0)
                    {
                        bestCandidate = this._rand.Next(0, ei.len);
                    }

                    this._generated.Add(candidates[bestCandidate]);
                    yield return(candidates[bestCandidate]);
                }
            }
        }