Changeset 14515
- Timestamp:
- 12/21/16 13:37:55 (8 years ago)
- Location:
- branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/Expression.cs
r14505 r14515 121 121 // the Label should be known to the infix parser 122 122 if (Label == "+" || Label == "-" || Label == "*" || Label == "/") { 123 if (Label == "/") 124 sb.Append("1 / "); 123 125 if (args.Count == 1) { 124 126 sb.Append(string.Format("{0}", args[0].PrintInfix())); -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionGenerator.cs
r14510 r14515 33 33 34 34 public static Expression Polynomial(IRandom uniformRandom, Expression[] variables, bool useLog, bool useExp) { 35 const int count = 10; // how many instances of each template should be produce? 36 int i = 1; 37 // the main template 38 var template = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 2, count)) { Label = "+" }; 39 template.AddArguments(variables); 40 35 41 var sumTemplate = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 1, variables.Length)) { Label = "+" }; 36 42 sumTemplate.AddArguments(variables); … … 39 45 productTemplate.AddArguments(variables); 40 46 41 const int count = 10; // how many instances of each template should be produce?42 int i = 1;43 44 var logTemplate = new FixedArityTemplate(Log, 1) { Label = "log" };45 logTemplate.AddArguments(variables);46 logTemplate.AddArguments(Enumerable.Range(1, count).Select(x => sumTemplate.Instantiate(string.Format("sum{0}", i++), uniformRandom)));47 48 var expTemplate = new FixedArityTemplate(Exp, 1) { Label = "exp" };49 expTemplate.AddArguments(variables);50 expTemplate.AddArguments(Enumerable.Range(1, count).Select(x => productTemplate.Instantiate(string.Format("prod{0}", i++), uniformRandom)));51 52 47 var inverseTemplate = new FixedArityTemplate(Division, 1) { Label = "/" }; 53 48 inverseTemplate.AddArguments(variables); 54 49 inverseTemplate.AddArguments(Enumerable.Range(1, count).Select(x => sumTemplate.Instantiate(string.Format("sum{0}", i++), uniformRandom))); 55 50 inverseTemplate.AddArguments(Enumerable.Range(1, count).Select(x => productTemplate.Instantiate(string.Format("prod{0}", i++), uniformRandom))); 56 inverseTemplate.AddArguments(Enumerable.Range(1, count).Select(x => logTemplate.Instantiate(string.Format("log{0}", i++), uniformRandom)));57 inverseTemplate.AddArguments(Enumerable.Range(1, count).Select(x => expTemplate.Instantiate(string.Format("exp{0}", i++), uniformRandom)));58 51 59 var template = new RandomArityTemplate(Sum, new UniformDistributedRandom(uniformRandom, 2, count)) { Label = "+" }; 60 template.AddArguments(variables); 61 template.AddArguments(Enumerable.Range(1, count).Select(x => logTemplate.Instantiate(string.Format("log{0}", i++), uniformRandom))); 62 template.AddArguments(Enumerable.Range(1, count).Select(x => expTemplate.Instantiate(string.Format("exp{0}", i++), uniformRandom))); 52 if (useLog) { 53 var logTemplate = new FixedArityTemplate(Log, 1) { Label = "log" }; 54 logTemplate.AddArguments(variables); 55 logTemplate.AddArguments(Enumerable.Range(1, count).Select(x => sumTemplate.Instantiate(string.Format("sum{0}", i++), uniformRandom))); 56 template.AddArguments(Enumerable.Range(1, count).Select(x => logTemplate.Instantiate(string.Format("log{0}", i++), uniformRandom))); 57 inverseTemplate.AddArguments(Enumerable.Range(1, count).Select(x => logTemplate.Instantiate(string.Format("log{0}", i++), uniformRandom))); 58 } 59 60 if (useExp) { 61 var expTemplate = new FixedArityTemplate(Exp, 1) { Label = "exp" }; 62 expTemplate.AddArguments(variables); 63 expTemplate.AddArguments(Enumerable.Range(1, count).Select(x => productTemplate.Instantiate(string.Format("prod{0}", i++), uniformRandom))); 64 template.AddArguments(Enumerable.Range(1, count).Select(x => expTemplate.Instantiate(string.Format("exp{0}", i++), uniformRandom))); 65 inverseTemplate.AddArguments(Enumerable.Range(1, count).Select(x => expTemplate.Instantiate(string.Format("exp{0}", i++), uniformRandom))); 66 } 67 63 68 template.AddArguments(Enumerable.Range(1, count).Select(x => inverseTemplate.Instantiate(string.Format("inv{0}", i++), uniformRandom))); 64 65 69 return template.Instantiate("polynomial", uniformRandom); 66 70 }
Note: See TracChangeset
for help on using the changeset viewer.