Changeset 14880


Ignore:
Timestamp:
04/20/17 18:21:01 (3 months ago)
Author:
gkronber
Message:

#2704: added more expression templates

Location:
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4
Files:
2 added
1 deleted
4 edited

Legend:

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

    r14873 r14880  
    3737    public ExpressionType Type { get; private set; }
    3838
    39     private readonly List<Expression> arguments;
     39    private readonly List<Expression> arguments; // only for functions
    4040    public IEnumerable<Expression> Arguments {
    4141      get { return arguments ?? Enumerable.Empty<Expression>(); }
     
    8585      switch (Type) {
    8686        case ExpressionType.Constant:
    87           sb.Append(Value.ToString("0.000", CultureInfo.InvariantCulture));
     87          sb.Append(Value.ToString("E4", CultureInfo.InvariantCulture));
    8888          break;
    8989        case ExpressionType.RandomVariable:
     
    108108        case ExpressionType.Constant:
    109109          sb.Append(Value < 0
    110               ? string.Format("(- {0})", Math.Abs(Value).ToString("0.000", CultureInfo.InvariantCulture))
    111               : Value.ToString("0.000", CultureInfo.InvariantCulture));
     110              ? string.Format("(- {0})", Math.Abs(Value).ToString("E4", CultureInfo.InvariantCulture))
     111              : Value.ToString("E4", CultureInfo.InvariantCulture));
    112112          break;
    113113        case ExpressionType.RandomVariable:
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionGenerator.cs

    r14879 r14880  
    2424using System.Linq;
    2525using HeuristicLab.Core;
     26using HeuristicLab.ExpressionGenerator.Interfaces;
    2627using HeuristicLab.Random;
    2728
     
    3233    }
    3334
    34     public static Expression NonlinearExpression(IRandom uniformRandom, Expression[] variables, bool useLog, bool useExp) {
    35       var scalingTemplate = ScaledExpression(uniformRandom, variables, varianceRandom: new UniformDistributedRandom(uniformRandom, 1, 10));
    36       var scaledVars = Instantiate(scalingTemplate, uniformRandom, 100, "scaledVar");
    37 
    38       var sumTemplate = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 1, 3)) { Label = "+" };
     35    public static Expression RationalExpression(IRandom uniformRandom, Expression[] variables, bool useLog, bool useExp) {
     36      var numerators =
     37        Enumerable.Range(0, 20)
     38          .Select(
     39            i =>
     40              NonlinearExpressionTemplate(uniformRandom, variables, useLog, useExp, false)
     41                .Instantiate("numerator" + i, uniformRandom, sampleWithRepetition: false))
     42          .ToArray();
     43      var denominators =
     44        Enumerable.Range(0, 20)
     45          .Select(
     46            i =>
     47              NonlinearExpressionTemplate(uniformRandom, variables, useLog, useExp, false)
     48                .Instantiate("denominator" + i, uniformRandom, sampleWithRepetition: false))
     49          .ToArray();
     50
     51
     52      var scaledNumeratorTemplate = new ScalingTemplate(new PointDistribution<double>(1.0));
     53      scaledNumeratorTemplate.AddArguments(numerators);
     54
     55      var scaledDenominatorTemplate = new RangeTemplate(
     56        minValue: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 0.01, 1)),
     57        valueRange: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 2, 10)));
     58      scaledDenominatorTemplate.AddArguments(denominators);
     59
     60
     61      var scaledNumerators =
     62        Enumerable.Range(0, 20)
     63          .Select(i => scaledNumeratorTemplate.Instantiate("scaledNumerator" + i, uniformRandom, false));
     64
     65      var scaledDenominators =
     66        Enumerable.Range(0, 20)
     67          .Select(i => scaledDenominatorTemplate.Instantiate("scaledDenom" + i, uniformRandom, false));
     68
     69      var template = new BinaryOperatorTemplate(Division) { Label = "/" };
     70      template.AddLeftArguments(scaledNumerators);
     71      template.AddRightArguments(scaledDenominators);
     72
     73      return template.Instantiate("rational", uniformRandom, false);
     74    }
     75
     76    public static Expression SumOfCompactNonlinearTerms(IRandom uniformRandom, Expression[] variables, bool useLog,
     77      bool useExp, bool useFrac) {
     78      var numInstances = 2 * variables.Length;
     79
     80      var scalingVarsTemplate = new ScalingTemplate(new DoublePrngDistribution(new GammaDistributedRandom(uniformRandom, 2, 2))); // exp(x) = 1, var(x) = 8
     81      scalingVarsTemplate.AddArguments(variables);
     82      var scaledVars = Instantiate(scalingVarsTemplate, uniformRandom, numInstances, "scaledVar");
     83
     84      var sumOfScaledVarsTemplate = new RandomArityTemplate(Sum, new DiscreteUniformDistribution(uniformRandom, 1, 3)) { Label = "+" };
     85      sumOfScaledVarsTemplate.AddArguments(scaledVars);
     86      var sumOfScaledVars = Instantiate(sumOfScaledVarsTemplate, uniformRandom, numInstances, "sumOfScaledVars");
     87
     88      var prodTemplate = new RandomArityTemplate(Product, new DiscreteUniformDistribution(uniformRandom, 1, 3)) { Label = "*" };
     89      prodTemplate.AddArguments(variables);
     90
     91      var logTermsTemplate = LogOfScaledExpression(uniformRandom, sumOfScaledVars,
     92      minValue: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 0.1, 2)),
     93      valueRange: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 1, 10)));
     94      var logTerms = Instantiate(logTermsTemplate, uniformRandom, numInstances, "log");
     95
     96      var expTemplate = ExpOfScaledExpression(uniformRandom, Instantiate(prodTemplate, uniformRandom, numInstances, "prodOfVars"),
     97                           minValue: new PointDistribution<double>(-2.0),
     98                           valueRange: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 4, 6)));
     99      var expTerms = Instantiate(expTemplate, uniformRandom, numInstances, "exp");
     100
     101      var fracTemplate = new BinaryOperatorTemplate(Division) { Label = "/" };
     102      fracTemplate.AddLeftArgument(Expression.Constant("const", 1.0), variables.Length);
     103      fracTemplate.AddLeftArguments(variables);
     104      fracTemplate.AddRightArguments(sumOfScaledVars);
     105      var fracTerms = Enumerable.Range(1, numInstances).Select(i => fracTemplate.Instantiate("frac" + i, uniformRandom, false));
     106
     107      var prodOfFactorsTemplate = new RandomArityTemplate(Product, new DiscreteUniformDistribution(uniformRandom, 1, 4)) { Label = "*" };
     108      prodOfFactorsTemplate.AddArguments(variables, variables.Select(_ => 1.0));
     109      if (useLog) prodOfFactorsTemplate.AddArguments(logTerms, logTerms.Select(_ => .3));
     110      if (useExp) prodOfFactorsTemplate.AddArguments(expTerms, expTerms.Select(_ => .3));
     111      if (useFrac) prodOfFactorsTemplate.AddArguments(fracTerms, fracTerms.Select(_ => .3));
     112      var prodFactors = Instantiate(prodOfFactorsTemplate, uniformRandom, numInstances, "prod");
     113
     114      var scaledTermsTemplate =
     115        new ScalingTemplate(new DoublePrngDistribution(new GammaDistributedRandom(uniformRandom, 2, 2))); // exp(x) = 1, var(x) = 8
     116      scaledTermsTemplate.AddArguments(variables, variables.Select(_ => 1.0));
     117      if (useLog) scaledTermsTemplate.AddArguments(logTerms, logTerms.Select(_ => 1.0));
     118      if (useExp) scaledTermsTemplate.AddArguments(expTerms, expTerms.Select(_ => 1.0));
     119      if (useFrac) scaledTermsTemplate.AddArguments(fracTerms, fracTerms.Select(_ => 1.0));
     120      scaledTermsTemplate.AddArguments(prodFactors, prodFactors.Select(_ => 4.0));
     121
     122      var scaledTerms = Instantiate(scaledTermsTemplate, uniformRandom, 100, "scaledTerm");
     123
     124      var sumTemplate = new RandomArityTemplate(Sum, arityDistribution: new DiscreteUniformDistribution(uniformRandom, 5, 25)) { Label = "+" };
     125      sumTemplate.AddArguments(scaledTerms);
     126
     127      return sumTemplate.Instantiate("sum", uniformRandom, false);
     128    }
     129
     130    public static Expression NonlinearExpression(IRandom uniformRandom, Expression[] variables, bool useLog, bool useExp, bool useFrac) {
     131      return NonlinearExpressionTemplate(uniformRandom, variables, useLog, useExp, useFrac)
     132        .Instantiate("nonlinearexpr", uniformRandom, sampleWithRepetition: false);
     133    }
     134
     135    public static ExpressionTemplate NonlinearExpressionTemplate(IRandom uniformRandom, Expression[] variables, bool useLog, bool useExp, bool useFrac) {
     136      var scalingTemplate = ScaledExpression(uniformRandom, variables, varianceDistribution: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 1, 10)));
     137      var scaledVars = Instantiate(scalingTemplate, uniformRandom, variables.Length, "scaledVar");
     138
     139      var sumTemplate = new RandomArityTemplate(Sum, new DiscreteUniformDistribution(uniformRandom, 1, 3)) { Label = "+" };
    39140      sumTemplate.AddArguments(scaledVars);
    40       var prodTemplate = new RandomArityTemplate(Product, new UniformDistributedRandom(uniformRandom, 1, 3)) { Label = "*" };
     141      var prodTemplate = new RandomArityTemplate(Product, new DiscreteUniformDistribution(uniformRandom, 1, 3)) { Label = "*" };
    41142      prodTemplate.AddArguments(variables);
    42143
    43       var logTemplate = LogOfScaledExpression(uniformRandom, Instantiate(sumTemplate, uniformRandom, 100, "sumOfScaledVars"),
    44         minValue: new UniformDistributedRandom(uniformRandom, 0.1, 2),
    45         valueRange: new UniformDistributedRandom(uniformRandom, 1, 10));
    46 
    47       var expTemplate = ExpOfScaledExpression(uniformRandom, Instantiate(prodTemplate, uniformRandom, 100, "prodOfVars"),
    48         minValue: new PointDistribution(-3),
    49         valueRange: new UniformDistributedRandom(uniformRandom, 4, 6));
    50 
    51       var scaledExprTemplate = new ScalingTemplate(new UniformDistributedRandom(uniformRandom, 1, 10)) { Label = "*" };
    52       if (useLog) scaledExprTemplate.AddArguments(Instantiate(logTemplate, uniformRandom, 100, "log"));
    53       if (useExp) scaledExprTemplate.AddArguments(Instantiate(expTemplate, uniformRandom, 100, "exp"));
    54 
    55       var mainTemplate = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 3, 5));
     144      var logTemplate = LogOfScaledExpression(uniformRandom, Instantiate(sumTemplate, uniformRandom, scaledVars.Count(), "sumOfScaledVars"),
     145        minValue: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 0.1, 2)),
     146        valueRange: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 1, 10)));
     147
     148      var expTemplate = ExpOfScaledExpression(uniformRandom, Instantiate(prodTemplate, uniformRandom, variables.Length, "prodOfVars"),
     149        minValue: new PointDistribution<double>(-3.0),
     150        valueRange: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 4, 6)));
     151
     152      var variableSumTemplate = new RandomArityTemplate(Sum, new DiscreteUniformDistribution(uniformRandom, 1, 4)) { Label = "+" };
     153      variableSumTemplate.AddArguments(variables);
     154      var variableSums = Instantiate(variableSumTemplate, uniformRandom, variables.Length * 2, "varsum");
     155
     156      var scaledVariableSumTemplate =
     157        new RangeTemplate(minValue: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 0.1, 1)),
     158          valueRange: new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 1, 5))) { Label = "*" };
     159      scaledVariableSumTemplate.AddArguments(variableSums);
     160      var scaledVariableSums = Instantiate(scaledVariableSumTemplate, uniformRandom, variables.Length * 2,
     161        "scaledvarsum");
     162
     163      var fracTemplate = new BinaryOperatorTemplate(Division) { Label = "/" };
     164      fracTemplate.AddLeftArguments(variables);
     165      fracTemplate.AddRightArguments(scaledVariableSums);
     166
     167      var scaledExprTemplate = new ScalingTemplate(new DoublePrngDistribution(new UniformDistributedRandom(uniformRandom, 1, 10))) { Label = "*" };
     168      if (useLog) scaledExprTemplate.AddArguments(Instantiate(logTemplate, uniformRandom, scaledVars.Count(), "log"));
     169      if (useExp) scaledExprTemplate.AddArguments(Instantiate(expTemplate, uniformRandom, variables.Length, "exp"));
     170      if (useFrac) scaledExprTemplate.AddArguments(Enumerable.Range(0, 20).Select(i => fracTemplate.Instantiate("frac" + i, uniformRandom, false)));
     171
     172      var mainTemplate = new RandomArityTemplate(Sum, arityDistribution: new DiscreteUniformDistribution(uniformRandom, 3, 5));
    56173      mainTemplate.AddArguments(scaledVars);
    57174      if (useLog || useExp) {
    58         mainTemplate.AddArguments(Instantiate(scaledExprTemplate, uniformRandom, 100, "scaledExpr"));
     175        mainTemplate.AddArguments(Instantiate(scaledExprTemplate, uniformRandom, 20, "scaledExpr"));
    59176      }
    60177      mainTemplate.Label = "+";
    61178
    62       return mainTemplate.Instantiate("main", uniformRandom, false);
     179      return mainTemplate;
    63180    }
    64181
     
    67184      int i = 1;
    68185      // the main template
    69       var template = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 2, count)) { Label = "+" };
     186      var template = new RandomArityTemplate(Sum, arityDistribution: new DiscreteUniformDistribution(uniformRandom, 2, count)) { Label = "+" };
    70187      template.AddArguments(variables);
    71188
    72       var sumTemplate = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 1, variables.Length)) { Label = "+" };
     189      var sumTemplate = new RandomArityTemplate(Sum, arityDistribution: new DiscreteUniformDistribution(uniformRandom, 1, variables.Length)) { Label = "+" };
    73190      sumTemplate.AddArguments(variables);
    74191
    75       var productTemplate = new RandomArityTemplate(Product, new UniformDistributedRandom(uniformRandom, 1, variables.Length)) { Label = "*" };
     192      var productTemplate = new RandomArityTemplate(Product, arityDistribution: new DiscreteUniformDistribution(uniformRandom, 1, variables.Length)) { Label = "*" };
    76193      productTemplate.AddArguments(variables);
    77194
     
    102219
    103220    // variance random must have support only positive numbers
    104     private static ExpressionTemplate ScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments, IRandom varianceRandom) {
    105       var scalingTemplate = new ScalingTemplate(scaledVariance: varianceRandom);
     221    private static ExpressionTemplate ScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments, IDistribution<double> varianceDistribution) {
     222      var scalingTemplate = new ScalingTemplate(scaledVariance: varianceDistribution);
    106223      scalingTemplate.AddArguments(arguments);
    107224      scalingTemplate.Label = "*";
     
    111228    /// template scales and translates the argument expression first to guarantee positive values
    112229    private static ExpressionTemplate LogOfScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments,
    113       IRandom minValue = null, IRandom valueRange = null) {
     230      IDistribution<double> minValue = null, IDistribution<double> valueRange = null) {
    114231      var limitToRangeTemplate = new RangeTemplate(minValue, valueRange);
    115232      limitToRangeTemplate.AddArguments(arguments);
    116233
    117234      var logTemplate = new FixedArityTemplate(Log, 1) { Label = "log" };
    118       logTemplate.AddArguments(Enumerable.Range(1, 100).Select(i => limitToRangeTemplate.Instantiate(string.Format("log{0}", i), uniformRandom, false)));
     235      logTemplate.AddArguments(Enumerable.Range(1, arguments.Count()).Select(i => limitToRangeTemplate.Instantiate(string.Format("log{0}", i), uniformRandom, false)));
    119236      return logTemplate;
    120237    }
     
    122239    /// template scales the argument expression first to guarantee reasonable values
    123240    private static ExpressionTemplate ExpOfScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments,
    124       IRandom minValue = null,
    125       IRandom valueRange = null) {
     241      IDistribution<double> minValue = null,
     242      IDistribution<double> valueRange = null) {
    126243      var limitToRangeTemplate = new RangeTemplate(minValue, valueRange);
    127244      limitToRangeTemplate.AddArguments(arguments);
    128245
    129246      var expTemplate = new FixedArityTemplate(Exp, 1) { Label = "exp" };
    130       expTemplate.AddArguments(Enumerable.Range(1, 100).Select(i => limitToRangeTemplate.Instantiate(string.Format("exp{0}", i), uniformRandom, false)));
     247      expTemplate.AddArguments(Enumerable.Range(1, arguments.Count()).Select(i => limitToRangeTemplate.Instantiate(string.Format("exp{0}", i), uniformRandom, false)));
    131248      return expTemplate;
    132249    }
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs

    r14873 r14880  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.ExpressionGenerator.Interfaces;
    2728using HeuristicLab.Random;
    2829
    2930namespace HeuristicLab.ExpressionGenerator {
    30   public abstract class ExpressionTemplate {
     31  public interface IExpressionTemplate {
     32    string Label { get; set; }
     33  }
     34  public abstract class ExpressionTemplate : IExpressionTemplate {
    3135    protected List<Tuple<Expression, double>> arguments;
    3236    protected readonly Func<IEnumerable<double>, double> transform;
     
    4246      var weights = arguments.Select(x => x.Item2);
    4347      var args = sampleWithRepetition
    44        ? arguments.SampleProportional(random, n, weights).Select(x => x.Item1)
    45        : arguments.SampleProportionalWithoutRepetition(random, n, weights).Select(x => x.Item1);
     48       ? arguments.SampleProportional(random, n, weights, windowing: false).Select(x => x.Item1)
     49       : arguments.SampleProportionalWithoutRepetition(random, n, weights, windowing: false).Select(x => x.Item1);
    4650      return args;
    4751    }
     
    7074
    7175  public class RandomArityTemplate : ExpressionTemplate {
    72     private readonly IRandom arityDistribution;
    73 
    74     public RandomArityTemplate(Func<IEnumerable<double>, double> transform, IRandom arityDistribution) : base(transform) {
     76    private readonly IDistribution<int> arityDistribution;
     77
     78    public RandomArityTemplate(Func<IEnumerable<double>, double> transform, IDistribution<int> arityDistribution) : base(transform) {
    7579      this.arityDistribution = arityDistribution;
    7680    }
    7781
    7882    public override Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false) {
    79       var arity = (int)Math.Round(arityDistribution.NextDouble());
     83      var arity = arityDistribution.Sample();
    8084      return Instantiate(name, random, arity, sampleWithRepetition);
    8185    }
     
    9397  }
    9498
     99
     100  public class BinaryOperatorTemplate : IExpressionTemplate {
     101    public string Label { get; set; }
     102    private readonly Func<IEnumerable<double>, double> transform;
     103    private List<Tuple<Expression, double>> leftArguments;
     104    private List<Tuple<Expression, double>> rightArguments;
     105
     106    public BinaryOperatorTemplate(Func<IEnumerable<double>, double> transform) {
     107      this.transform = transform;
     108    }
     109
     110    public void AddLeftArgument(Expression expression, double weight = 1d) {
     111      leftArguments = leftArguments ?? new List<Tuple<Expression, double>>();
     112      leftArguments.Add(Tuple.Create(expression, weight));
     113    }
     114
     115    public void AddLeftArguments(IEnumerable<Expression> expressions) {
     116      leftArguments = leftArguments ?? new List<Tuple<Expression, double>>();
     117      leftArguments.AddRange(expressions.Select(x => Tuple.Create(x, 1d)));
     118    }
     119
     120    public void AddLeftArguments(IEnumerable<Expression> expressions, IEnumerable<double> weights) {
     121      leftArguments = leftArguments ?? new List<Tuple<Expression, double>>();
     122      leftArguments.AddRange(expressions.Zip(weights, Tuple.Create));
     123    }
     124
     125
     126    public void AddRightArgument(Expression expression, double weight = 1d) {
     127      rightArguments = rightArguments ?? new List<Tuple<Expression, double>>();
     128      rightArguments.Add(Tuple.Create(expression, weight));
     129    }
     130
     131    public void AddRightArguments(IEnumerable<Expression> expressions) {
     132      rightArguments = rightArguments ?? new List<Tuple<Expression, double>>();
     133      rightArguments.AddRange(expressions.Select(x => Tuple.Create(x, 1d)));
     134    }
     135
     136    public void AddRightArguments(IEnumerable<Expression> expressions, IEnumerable<double> weights) {
     137      rightArguments = rightArguments ?? new List<Tuple<Expression, double>>();
     138      rightArguments.AddRange(expressions.Zip(weights, Tuple.Create));
     139    }
     140
     141    public Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false) {
     142      Expression leftArgument = null;
     143      Expression rightArgument = null;
     144      {
     145        var weights = leftArguments.Select(x => x.Item2);
     146        leftArgument = sampleWithRepetition
     147          ? leftArguments.SampleProportional(random, 1, weights, windowing: false).Select(x => x.Item1).First() :
     148          leftArguments.SampleProportionalWithoutRepetition(random, 1, weights, windowing: false).Select(x => x.Item1).First();
     149      }
     150      {
     151        var weights = rightArguments.Select(x => x.Item2);
     152        rightArgument = sampleWithRepetition
     153          ? rightArguments.SampleProportional(random, 1, weights).Select(x => x.Item1).First() :
     154          rightArguments.SampleProportionalWithoutRepetition(random, 1, weights).Select(x => x.Item1).First();
     155      }
     156
     157      var func = Expression.Function(name, transform, new Expression[] { leftArgument, rightArgument });
     158      func.Label = Label;
     159      return func;
     160    }
     161  }
     162
    95163  public class ScalingTemplate : ExpressionTemplate {
    96     private readonly IRandom scaledVariance;
     164    private readonly IDistribution<double> scaledVariance;
    97165    // w * expr
    98     public ScalingTemplate(IRandom scaledVariance = null) : base(ExpressionGenerator.Product) {
     166    public ScalingTemplate(IDistribution<double> scaledVariance = null) : base(ExpressionGenerator.Product) {
    99167      this.scaledVariance = scaledVariance;
    100168    }
     
    109177        var data = evaluator.GenerateData(expr, 10000);
    110178        var variance = data[expr].VariancePop();
    111         @const = scaledVariance.NextDouble() / variance;
     179        @const = scaledVariance.Sample() / variance;
    112180      }
    113181
     
    119187
    120188  public class OffsetTemplate : ExpressionTemplate {
    121     private readonly IRandom offset;
     189    private readonly IDistribution<double> offset;
    122190    // expr + offset
    123     public OffsetTemplate(IRandom offset = null) : base(ExpressionGenerator.Sum) {
     191    public OffsetTemplate(IDistribution<double> offset = null) : base(ExpressionGenerator.Sum) {
    124192      this.offset = offset;
    125193    }
     
    134202        var data = evaluator.GenerateData(expr, 10000);
    135203        var average = data[expr].Average();
    136         @const = offset.NextDouble() - average;
     204        @const = offset.Sample() - average;
    137205      }
    138206
     
    144212
    145213  public class RangeTemplate : ExpressionTemplate {
    146     private readonly IRandom minValue;
    147     private readonly IRandom valueRange;
     214    private readonly IDistribution<double> minValue;
     215    private readonly IDistribution<double> valueRange;
    148216    // expr + offset
    149     public RangeTemplate(IRandom minValue = null, IRandom valueRange = null) : base(null) {
     217    public RangeTemplate(IDistribution<double> minValue = null, IDistribution<double> valueRange = null) : base(null) {
    150218      this.minValue = minValue;
    151219      this.valueRange = valueRange;
     
    163231        var data = evaluator.GenerateData(expr, 10000);
    164232        if (valueRange != null) {
    165           var targetRange = valueRange.NextDouble();
     233          var targetRange = valueRange.Sample();
    166234          var min = data[expr].Min();
    167235          var max = data[expr].Max();
     
    171239        }
    172240        if (minValue != null) {
    173           var targetMin = minValue.NextDouble();
     241          var targetMin = minValue.Sample();
    174242          var min = data[expr].Min();
    175243          add += (targetMin - min) / mult;
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/HeuristicLab.ExpressionGenerator.csproj

    r14873 r14880  
    7272  </ItemGroup>
    7373  <ItemGroup>
     74    <Compile Include="Distributions.cs" />
    7475    <Compile Include="Expression.cs" />
    7576    <Compile Include="ExpressionEvaluator.cs" />
    7677    <Compile Include="ExpressionGenerator.cs" />
    7778    <Compile Include="ExpressionTemplate.cs" />
     79    <Compile Include="Interfaces\IDistribution.cs" />
    7880    <Compile Include="Interfaces\IExpression.cs" />
    79     <Compile Include="PointDistribution.cs" />
    8081    <Compile Include="Plugin.cs" />
    8182  </ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.