Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/16 16:38:20 (7 years ago)
Author:
bburlacu
Message:

#2704: Added the possibility to sample possible arguments without repetition when instantiating expression templates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs

    r14409 r14410  
    3232    protected readonly string label;
    3333
    34     public abstract Expression Instantiate(IRandom random);
     34    public abstract Expression Instantiate(IRandom random, bool sampleWithRepetition = false);
    3535
    3636    protected ExpressionTemplate(string label, Func<IEnumerable<double>, double> transform) {
     
    6262    }
    6363
    64     public override Expression Instantiate(IRandom random) {
     64    public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) {
    6565      var arity = (int)Math.Round(arityDistribution.NextDouble());
    66       var args = arguments.SampleProportional(random, arity, arguments.Select(x => x.Item2)).Select(x => x.Item1);
     66      var weights = arguments.Select(x => x.Item2);
     67      var args = sampleWithRepetition
     68        ? arguments.SampleProportional(random, arity, weights).Select(x => x.Item1)
     69        : arguments.SampleProportionalWithoutRepetition(random, arity, weights).Select(x => x.Item1);
    6770      return Expression.Function(label, transform, args);
    6871    }
     
    7578    }
    7679
    77     public override Expression Instantiate(IRandom random) {
     80    public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) {
    7881      var args = arguments.SampleProportional(random, arity, arguments.Select(x => x.Item2)).Select(x => x.Item1);
    7982      return Expression.Function(label, transform, args);
Note: See TracChangeset for help on using the changeset viewer.