Changeset 14880
- Timestamp:
- 04/20/17 18:21:01 (8 years ago)
- 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 37 37 public ExpressionType Type { get; private set; } 38 38 39 private readonly List<Expression> arguments; 39 private readonly List<Expression> arguments; // only for functions 40 40 public IEnumerable<Expression> Arguments { 41 41 get { return arguments ?? Enumerable.Empty<Expression>(); } … … 85 85 switch (Type) { 86 86 case ExpressionType.Constant: 87 sb.Append(Value.ToString(" 0.000", CultureInfo.InvariantCulture));87 sb.Append(Value.ToString("E4", CultureInfo.InvariantCulture)); 88 88 break; 89 89 case ExpressionType.RandomVariable: … … 108 108 case ExpressionType.Constant: 109 109 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)); 112 112 break; 113 113 case ExpressionType.RandomVariable: -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionGenerator.cs
r14879 r14880 24 24 using System.Linq; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.ExpressionGenerator.Interfaces; 26 27 using HeuristicLab.Random; 27 28 … … 32 33 } 33 34 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 = "+" }; 39 140 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 = "*" }; 41 142 prodTemplate.AddArguments(variables); 42 143 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)); 56 173 mainTemplate.AddArguments(scaledVars); 57 174 if (useLog || useExp) { 58 mainTemplate.AddArguments(Instantiate(scaledExprTemplate, uniformRandom, 100, "scaledExpr"));175 mainTemplate.AddArguments(Instantiate(scaledExprTemplate, uniformRandom, 20, "scaledExpr")); 59 176 } 60 177 mainTemplate.Label = "+"; 61 178 62 return mainTemplate .Instantiate("main", uniformRandom, false);179 return mainTemplate; 63 180 } 64 181 … … 67 184 int i = 1; 68 185 // 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 = "+" }; 70 187 template.AddArguments(variables); 71 188 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 = "+" }; 73 190 sumTemplate.AddArguments(variables); 74 191 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 = "*" }; 76 193 productTemplate.AddArguments(variables); 77 194 … … 102 219 103 220 // variance random must have support only positive numbers 104 private static ExpressionTemplate ScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments, I Random varianceRandom) {105 var scalingTemplate = new ScalingTemplate(scaledVariance: variance Random);221 private static ExpressionTemplate ScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments, IDistribution<double> varianceDistribution) { 222 var scalingTemplate = new ScalingTemplate(scaledVariance: varianceDistribution); 106 223 scalingTemplate.AddArguments(arguments); 107 224 scalingTemplate.Label = "*"; … … 111 228 /// template scales and translates the argument expression first to guarantee positive values 112 229 private static ExpressionTemplate LogOfScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments, 113 I Random minValue = null, IRandomvalueRange = null) {230 IDistribution<double> minValue = null, IDistribution<double> valueRange = null) { 114 231 var limitToRangeTemplate = new RangeTemplate(minValue, valueRange); 115 232 limitToRangeTemplate.AddArguments(arguments); 116 233 117 234 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))); 119 236 return logTemplate; 120 237 } … … 122 239 /// template scales the argument expression first to guarantee reasonable values 123 240 private static ExpressionTemplate ExpOfScaledExpression(IRandom uniformRandom, IEnumerable<Expression> arguments, 124 I RandomminValue = null,125 I RandomvalueRange = null) {241 IDistribution<double> minValue = null, 242 IDistribution<double> valueRange = null) { 126 243 var limitToRangeTemplate = new RangeTemplate(minValue, valueRange); 127 244 limitToRangeTemplate.AddArguments(arguments); 128 245 129 246 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))); 131 248 return expTemplate; 132 249 } -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs
r14873 r14880 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.ExpressionGenerator.Interfaces; 27 28 using HeuristicLab.Random; 28 29 29 30 namespace HeuristicLab.ExpressionGenerator { 30 public abstract class ExpressionTemplate { 31 public interface IExpressionTemplate { 32 string Label { get; set; } 33 } 34 public abstract class ExpressionTemplate : IExpressionTemplate { 31 35 protected List<Tuple<Expression, double>> arguments; 32 36 protected readonly Func<IEnumerable<double>, double> transform; … … 42 46 var weights = arguments.Select(x => x.Item2); 43 47 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); 46 50 return args; 47 51 } … … 70 74 71 75 public class RandomArityTemplate : ExpressionTemplate { 72 private readonly I RandomarityDistribution;73 74 public RandomArityTemplate(Func<IEnumerable<double>, double> transform, I RandomarityDistribution) : base(transform) {76 private readonly IDistribution<int> arityDistribution; 77 78 public RandomArityTemplate(Func<IEnumerable<double>, double> transform, IDistribution<int> arityDistribution) : base(transform) { 75 79 this.arityDistribution = arityDistribution; 76 80 } 77 81 78 82 public override Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false) { 79 var arity = (int)Math.Round(arityDistribution.NextDouble());83 var arity = arityDistribution.Sample(); 80 84 return Instantiate(name, random, arity, sampleWithRepetition); 81 85 } … … 93 97 } 94 98 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 95 163 public class ScalingTemplate : ExpressionTemplate { 96 private readonly I RandomscaledVariance;164 private readonly IDistribution<double> scaledVariance; 97 165 // w * expr 98 public ScalingTemplate(I RandomscaledVariance = null) : base(ExpressionGenerator.Product) {166 public ScalingTemplate(IDistribution<double> scaledVariance = null) : base(ExpressionGenerator.Product) { 99 167 this.scaledVariance = scaledVariance; 100 168 } … … 109 177 var data = evaluator.GenerateData(expr, 10000); 110 178 var variance = data[expr].VariancePop(); 111 @const = scaledVariance. NextDouble() / variance;179 @const = scaledVariance.Sample() / variance; 112 180 } 113 181 … … 119 187 120 188 public class OffsetTemplate : ExpressionTemplate { 121 private readonly I Randomoffset;189 private readonly IDistribution<double> offset; 122 190 // expr + offset 123 public OffsetTemplate(I Randomoffset = null) : base(ExpressionGenerator.Sum) {191 public OffsetTemplate(IDistribution<double> offset = null) : base(ExpressionGenerator.Sum) { 124 192 this.offset = offset; 125 193 } … … 134 202 var data = evaluator.GenerateData(expr, 10000); 135 203 var average = data[expr].Average(); 136 @const = offset. NextDouble() - average;204 @const = offset.Sample() - average; 137 205 } 138 206 … … 144 212 145 213 public class RangeTemplate : ExpressionTemplate { 146 private readonly I RandomminValue;147 private readonly I RandomvalueRange;214 private readonly IDistribution<double> minValue; 215 private readonly IDistribution<double> valueRange; 148 216 // expr + offset 149 public RangeTemplate(I Random minValue = null, IRandomvalueRange = null) : base(null) {217 public RangeTemplate(IDistribution<double> minValue = null, IDistribution<double> valueRange = null) : base(null) { 150 218 this.minValue = minValue; 151 219 this.valueRange = valueRange; … … 163 231 var data = evaluator.GenerateData(expr, 10000); 164 232 if (valueRange != null) { 165 var targetRange = valueRange. NextDouble();233 var targetRange = valueRange.Sample(); 166 234 var min = data[expr].Min(); 167 235 var max = data[expr].Max(); … … 171 239 } 172 240 if (minValue != null) { 173 var targetMin = minValue. NextDouble();241 var targetMin = minValue.Sample(); 174 242 var min = data[expr].Min(); 175 243 add += (targetMin - min) / mult; -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/HeuristicLab.ExpressionGenerator.csproj
r14873 r14880 72 72 </ItemGroup> 73 73 <ItemGroup> 74 <Compile Include="Distributions.cs" /> 74 75 <Compile Include="Expression.cs" /> 75 76 <Compile Include="ExpressionEvaluator.cs" /> 76 77 <Compile Include="ExpressionGenerator.cs" /> 77 78 <Compile Include="ExpressionTemplate.cs" /> 79 <Compile Include="Interfaces\IDistribution.cs" /> 78 80 <Compile Include="Interfaces\IExpression.cs" /> 79 <Compile Include="PointDistribution.cs" />80 81 <Compile Include="Plugin.cs" /> 81 82 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.