Changeset 14411
- Timestamp:
- 11/24/16 16:58:48 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs
r14410 r14411 28 28 namespace HeuristicLab.ExpressionGenerator { 29 29 public abstract class ExpressionTemplate { 30 protected List<Tuple<Expression, double>> arguments; 31 protected readonly Func<IEnumerable<double>, double> transform; 32 protected readonly string label; 30 private List<Tuple<Expression, double>> arguments; 31 private readonly Func<IEnumerable<double>, double> transform; 32 private readonly string label; 33 34 protected Expression Instantiate(IRandom random, int n, bool sampleWithRepetition = false) { 35 var weights = arguments.Select(x => x.Item2); 36 var args = sampleWithRepetition 37 ? arguments.SampleProportional(random, n, weights).Select(x => x.Item1) 38 : arguments.SampleProportionalWithoutRepetition(random, n, weights).Select(x => x.Item1); 39 return Expression.Function(label, transform, args); 40 } 33 41 34 42 public abstract Expression Instantiate(IRandom random, bool sampleWithRepetition = false); … … 64 72 public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) { 65 73 var arity = (int)Math.Round(arityDistribution.NextDouble()); 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); 70 return Expression.Function(label, transform, args); 74 return Instantiate(random, arity, sampleWithRepetition); 71 75 } 72 76 } … … 79 83 80 84 public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) { 81 var args = arguments.SampleProportional(random, arity, arguments.Select(x => x.Item2)).Select(x => x.Item1); 82 return Expression.Function(label, transform, args); 85 return Instantiate(random, arity, sampleWithRepetition); 83 86 } 84 87 }
Note: See TracChangeset
for help on using the changeset viewer.