[13648] | 1 | using System;
|
---|
[15420] | 2 | using System.Collections.Generic;
|
---|
[13648] | 3 | using System.Linq;
|
---|
| 4 | using System.Threading;
|
---|
[13661] | 5 | using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression.Policies;
|
---|
[13648] | 6 | using HeuristicLab.Data;
|
---|
| 7 | using HeuristicLab.Optimization;
|
---|
| 8 | using HeuristicLab.Problems.DataAnalysis;
|
---|
[15403] | 9 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
[15416] | 10 | using HeuristicLab.Random;
|
---|
[13648] | 11 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 12 |
|
---|
[15404] | 13 | namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
|
---|
[13648] | 14 | [TestClass()]
|
---|
| 15 | public class MctsSymbolicRegressionTest {
|
---|
[15404] | 16 | #region expression hashing
|
---|
| 17 | [TestMethod]
|
---|
| 18 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 19 | [TestProperty("Time", "short")]
|
---|
| 20 | public void ExprHashTest() {
|
---|
| 21 | int nParams;
|
---|
| 22 | byte[] code;
|
---|
| 23 |
|
---|
| 24 | {
|
---|
| 25 | // addition of variables
|
---|
| 26 | var codeGen = new CodeGenerator();
|
---|
| 27 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 28 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 29 | codeGen.Emit1(OpCodes.Add);
|
---|
| 30 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 31 | codeGen.GetCode(out code, out nParams);
|
---|
| 32 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 33 |
|
---|
| 34 | codeGen = new CodeGenerator();
|
---|
| 35 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 36 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 37 | codeGen.Emit1(OpCodes.Add);
|
---|
| 38 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 39 | codeGen.GetCode(out code, out nParams);
|
---|
| 40 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 41 |
|
---|
| 42 | Assert.AreEqual(h1, h2);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | {
|
---|
| 46 | // multiplication of variables
|
---|
| 47 | var codeGen = new CodeGenerator();
|
---|
| 48 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 49 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 50 | codeGen.Emit1(OpCodes.Mul);
|
---|
| 51 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 52 | codeGen.GetCode(out code, out nParams);
|
---|
| 53 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 54 |
|
---|
| 55 | codeGen = new CodeGenerator();
|
---|
| 56 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 57 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 58 | codeGen.Emit1(OpCodes.Mul);
|
---|
| 59 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 60 | codeGen.GetCode(out code, out nParams);
|
---|
| 61 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 62 |
|
---|
| 63 | Assert.AreEqual(h1, h2);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | {
|
---|
| 67 | // distributivity
|
---|
| 68 | var codeGen = new CodeGenerator();
|
---|
| 69 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 70 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 71 | codeGen.Emit1(OpCodes.Add);
|
---|
| 72 | codeGen.Emit2(OpCodes.LoadVar, 3);
|
---|
| 73 | codeGen.Emit1(OpCodes.Mul);
|
---|
| 74 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 75 | codeGen.GetCode(out code, out nParams);
|
---|
| 76 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 77 |
|
---|
| 78 | codeGen = new CodeGenerator();
|
---|
| 79 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 80 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 3);
|
---|
| 81 | codeGen.Emit1(OpCodes.Mul);
|
---|
| 82 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 83 | codeGen.Emit2(OpCodes.LoadVar, 3);
|
---|
| 84 | codeGen.Emit1(OpCodes.Mul);
|
---|
| 85 | codeGen.Emit1(OpCodes.Add);
|
---|
| 86 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 87 | codeGen.GetCode(out code, out nParams);
|
---|
| 88 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 89 |
|
---|
| 90 | Assert.AreEqual(h1, h2);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | {
|
---|
| 95 | // div
|
---|
| 96 | var codeGen = new CodeGenerator();
|
---|
| 97 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 98 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 99 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 100 | codeGen.Emit1(OpCodes.Inv);
|
---|
| 101 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 102 | codeGen.GetCode(out code, out nParams);
|
---|
| 103 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 104 |
|
---|
| 105 | codeGen = new CodeGenerator();
|
---|
| 106 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 107 | codeGen.Emit1(OpCodes.Inv);
|
---|
| 108 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 109 | codeGen.Emit1(OpCodes.Inv);
|
---|
| 110 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 111 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 112 | codeGen.GetCode(out code, out nParams);
|
---|
| 113 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 114 |
|
---|
| 115 | Assert.AreEqual(h1, h2);
|
---|
| 116 | }
|
---|
| 117 | {
|
---|
| 118 | // exp
|
---|
| 119 | var codeGen = new CodeGenerator();
|
---|
| 120 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 121 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 122 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Add);
|
---|
| 123 | codeGen.Emit1(OpCodes.Exp);
|
---|
| 124 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 125 | codeGen.GetCode(out code, out nParams);
|
---|
| 126 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 127 |
|
---|
| 128 | codeGen = new CodeGenerator();
|
---|
| 129 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 130 | codeGen.Emit1(OpCodes.Exp);
|
---|
| 131 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 132 | codeGen.Emit1(OpCodes.Exp);
|
---|
| 133 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 134 | codeGen.GetCode(out code, out nParams);
|
---|
| 135 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 136 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 137 |
|
---|
| 138 | Assert.AreEqual(h1, h2);
|
---|
| 139 | }
|
---|
| 140 | {
|
---|
| 141 | // log
|
---|
| 142 | var codeGen = new CodeGenerator();
|
---|
| 143 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 144 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 145 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 146 | codeGen.Emit1(OpCodes.Log);
|
---|
| 147 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 148 | codeGen.GetCode(out code, out nParams);
|
---|
| 149 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 150 |
|
---|
| 151 | codeGen = new CodeGenerator();
|
---|
| 152 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 153 | codeGen.Emit1(OpCodes.Log);
|
---|
| 154 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2);
|
---|
| 155 | codeGen.Emit1(OpCodes.Log);
|
---|
| 156 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Add);
|
---|
| 157 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 158 | codeGen.GetCode(out code, out nParams);
|
---|
| 159 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 160 |
|
---|
| 161 | Assert.AreEqual(h1, h2);
|
---|
| 162 | }
|
---|
[15414] | 163 |
|
---|
| 164 | {
|
---|
| 165 | // x1 + x1 is equivalent to x1
|
---|
| 166 | var codeGen = new CodeGenerator();
|
---|
| 167 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 168 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 169 | codeGen.Emit1(OpCodes.Add);
|
---|
| 170 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 171 | codeGen.GetCode(out code, out nParams);
|
---|
| 172 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 173 |
|
---|
| 174 | codeGen = new CodeGenerator();
|
---|
| 175 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 176 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 177 | codeGen.GetCode(out code, out nParams);
|
---|
| 178 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 179 |
|
---|
| 180 | Assert.AreEqual(h1, h2);
|
---|
| 181 | }
|
---|
| 182 | {
|
---|
| 183 | // c1*x1 + c2*x1 is equivalent to c3*x1
|
---|
| 184 | var codeGen = new CodeGenerator();
|
---|
| 185 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadParamN);
|
---|
| 186 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 187 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 188 |
|
---|
| 189 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadParamN);
|
---|
| 190 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 191 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 192 |
|
---|
| 193 | codeGen.Emit1(OpCodes.Add);
|
---|
| 194 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 195 | codeGen.GetCode(out code, out nParams);
|
---|
| 196 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 197 |
|
---|
| 198 | codeGen = new CodeGenerator();
|
---|
| 199 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadParamN);
|
---|
| 200 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 201 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 202 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 203 | codeGen.GetCode(out code, out nParams);
|
---|
| 204 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 205 |
|
---|
| 206 | Assert.AreEqual(h1, h2);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | {
|
---|
| 210 | var codeGen = new CodeGenerator();
|
---|
| 211 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadConst0);
|
---|
| 212 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadConst1);
|
---|
| 213 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadParamN);
|
---|
| 214 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 215 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 216 |
|
---|
| 217 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadParamN);
|
---|
| 218 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 219 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 220 |
|
---|
| 221 | codeGen.Emit1(OpCodes.Add);
|
---|
| 222 |
|
---|
| 223 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 224 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Add);
|
---|
| 225 |
|
---|
| 226 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 227 | codeGen.GetCode(out code, out nParams);
|
---|
| 228 | var h1 = ExprHash.GetHash(code, nParams);
|
---|
| 229 |
|
---|
| 230 | codeGen = new CodeGenerator();
|
---|
| 231 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadConst0);
|
---|
| 232 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadConst1);
|
---|
| 233 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.LoadParamN);
|
---|
| 234 | codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1);
|
---|
| 235 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 236 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul);
|
---|
| 237 | codeGen.Emit1(MctsSymbolicRegression.OpCodes.Add);
|
---|
| 238 | codeGen.Emit1(OpCodes.Exit);
|
---|
| 239 | codeGen.GetCode(out code, out nParams);
|
---|
| 240 | var h2 = ExprHash.GetHash(code, nParams);
|
---|
| 241 |
|
---|
| 242 | Assert.AreEqual(h1, h2);
|
---|
| 243 | }
|
---|
[15404] | 244 | }
|
---|
| 245 | #endregion
|
---|
| 246 |
|
---|
[13648] | 247 | #region number of solutions
|
---|
| 248 | // the algorithm should visits each solution only once
|
---|
| 249 | [TestMethod]
|
---|
| 250 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 251 | [TestProperty("Time", "short")]
|
---|
| 252 | public void MctsSymbRegNumberOfSolutionsOneVariable() {
|
---|
| 253 | // this problem has only one variable
|
---|
[15403] | 254 | var provider = new NguyenInstanceProvider();
|
---|
[13648] | 255 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
|
---|
| 256 | {
|
---|
| 257 | // possible solutions with max one variable reference:
|
---|
| 258 | // x
|
---|
| 259 | // log(x)
|
---|
| 260 | // exp(x)
|
---|
| 261 | // 1/x
|
---|
| 262 | TestMctsNumberOfSolutions(regProblem, 1, 4);
|
---|
| 263 | }
|
---|
| 264 | {
|
---|
| 265 | // possible solutions with max two variable references:
|
---|
[13651] | 266 | // TODO: equal terms should not be allowed (see ConstraintHandler)
|
---|
[13648] | 267 | // x
|
---|
| 268 | // log(x)
|
---|
| 269 | // exp(x)
|
---|
| 270 | // 1/x
|
---|
| 271 | // -- 4
|
---|
| 272 | // x * x
|
---|
| 273 | // x * log(x)
|
---|
| 274 | // x * exp(x)
|
---|
| 275 | // x * 1/x
|
---|
[13651] | 276 | // x + x ?
|
---|
[13648] | 277 | // x + log(x)
|
---|
| 278 | // x + exp(x)
|
---|
| 279 | // x + 1/x
|
---|
| 280 | // -- 8
|
---|
| 281 | // log(x) * log(x)
|
---|
| 282 | // log(x) * exp(x)
|
---|
| 283 | // log(x) * 1/x
|
---|
[13651] | 284 | // log(x) + log(x) ?
|
---|
| 285 | // log(x) + exp(x) ?
|
---|
[13648] | 286 | // log(x) + 1/x
|
---|
| 287 | // -- 6
|
---|
| 288 | // exp(x) * exp(x)
|
---|
| 289 | // exp(x) * 1/x
|
---|
[13651] | 290 | // exp(x) + exp(x) ?
|
---|
[13648] | 291 | // exp(x) + 1/x
|
---|
| 292 | // -- 4
|
---|
| 293 | // 1/x * 1/x
|
---|
[13651] | 294 | // 1/x + 1/x ?
|
---|
[13648] | 295 | // -- 2
|
---|
[13651] | 296 | // log(x+x) ?
|
---|
[13648] | 297 | // log(x*x)
|
---|
| 298 | // exp(x*x)
|
---|
[13651] | 299 | // 1/(x+x) ?
|
---|
[13648] | 300 | // 1/(x*x)
|
---|
| 301 | // -- 5
|
---|
[13651] | 302 |
|
---|
| 303 |
|
---|
[13648] | 304 | TestMctsNumberOfSolutions(regProblem, 2, 29);
|
---|
| 305 | }
|
---|
| 306 | {
|
---|
| 307 | // possible solutions with max three variable references:
|
---|
| 308 | // without log and inv
|
---|
| 309 | // x
|
---|
| 310 | // exp(x)
|
---|
| 311 | // -- 2
|
---|
| 312 | // x * x
|
---|
[13651] | 313 | // x + x ?
|
---|
[13648] | 314 | // x * exp(x)
|
---|
| 315 | // x + exp(x)
|
---|
| 316 | // exp(x) * exp(x)
|
---|
[13651] | 317 | // exp(x) + exp(x) ?
|
---|
[13648] | 318 | // exp(x*x)
|
---|
| 319 | // -- 7
|
---|
| 320 | // x * x * x
|
---|
[13651] | 321 | // x + x * x
|
---|
| 322 | // x + x + x ?
|
---|
[13648] | 323 | // x * x * exp(x)
|
---|
[13651] | 324 | // x + x * exp(x)
|
---|
| 325 | // x + x + exp(x) ?
|
---|
| 326 | // exp(x) + x*x
|
---|
| 327 | // exp(x) + x*exp(x)
|
---|
| 328 | // x + exp(x) * exp(x)
|
---|
| 329 | // x + exp(x) + exp(x) ?
|
---|
[13648] | 330 | // x * exp(x) * exp(x)
|
---|
| 331 | // x * exp(x*x)
|
---|
| 332 | // x + exp(x*x)
|
---|
[13651] | 333 | // -- 13
|
---|
[13648] | 334 |
|
---|
| 335 | // exp(x) * exp(x) * exp(x)
|
---|
[13651] | 336 | // exp(x) + exp(x) * exp(x)
|
---|
| 337 | // exp(x) + exp(x) + exp(x) ?
|
---|
| 338 | // -- 3
|
---|
[13648] | 339 |
|
---|
| 340 | // exp(x) * exp(x*x)
|
---|
| 341 | // exp(x) + exp(x*x)
|
---|
[13651] | 342 | // -- 2
|
---|
[13648] | 343 | // exp(x*x*x)
|
---|
| 344 | // -- 1
|
---|
[13651] | 345 | TestMctsNumberOfSolutions(regProblem, 3, 2 + 7 + 13 + 3 + 2 + 1, allowLog: false, allowInv: false);
|
---|
| 346 | }
|
---|
| 347 | {
|
---|
| 348 | // possible solutions with max 4 variable references:
|
---|
| 349 | // without exp, log and inv
|
---|
| 350 | // x
|
---|
| 351 | // x*x
|
---|
| 352 | // x+x ?
|
---|
| 353 | // x*x*x
|
---|
| 354 | // x+x*x
|
---|
| 355 | // x+x+x ?
|
---|
| 356 | // x*x*x*x
|
---|
| 357 | // x+x*x*x
|
---|
| 358 | // x*x+x*x ?
|
---|
| 359 | // x+x+x*x ?
|
---|
| 360 | // x+x+x+x ?
|
---|
[13648] | 361 |
|
---|
[13651] | 362 | TestMctsNumberOfSolutions(regProblem, 4, 11, allowLog: false, allowInv: false, allowExp: false);
|
---|
[13648] | 363 | }
|
---|
[13651] | 364 | {
|
---|
| 365 | // possible solutions with max 5 variable references:
|
---|
| 366 | // without exp, log and inv
|
---|
| 367 | // x
|
---|
| 368 | // xx
|
---|
| 369 | // x+x ?
|
---|
| 370 | // xxx
|
---|
| 371 | // x+xx
|
---|
| 372 | // x+x+x ?
|
---|
| 373 | // xxxx
|
---|
| 374 | // x+xxx
|
---|
| 375 | // xx+xx ?
|
---|
| 376 | // x+x+xx ?
|
---|
| 377 | // x+x+x+x ?
|
---|
| 378 | // xxxxx
|
---|
| 379 | // x+xxxx
|
---|
| 380 | // xx+xxx
|
---|
| 381 | // x+x+xxx ?
|
---|
| 382 | // x+xx+xx ?
|
---|
| 383 | // x+x+x+xx ?
|
---|
| 384 | // x+x+x+x+x ?
|
---|
| 385 | TestMctsNumberOfSolutions(regProblem, 5, 18, allowLog: false, allowInv: false, allowExp: false);
|
---|
| 386 | }
|
---|
[13648] | 387 | }
|
---|
| 388 |
|
---|
| 389 | [TestMethod]
|
---|
| 390 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 391 | [TestProperty("Time", "short")]
|
---|
| 392 | public void MctsSymbRegNumberOfSolutionsTwoVariables() {
|
---|
| 393 | // this problem has only two input variables
|
---|
| 394 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 395 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
|
---|
| 396 | {
|
---|
| 397 | // possible solutions with max one variable reference:
|
---|
| 398 | // x
|
---|
| 399 | // log(x)
|
---|
| 400 | // exp(x)
|
---|
| 401 | // 1/x
|
---|
| 402 | // y
|
---|
| 403 | // log(y)
|
---|
| 404 | // exp(y)
|
---|
| 405 | // 1/y
|
---|
| 406 | TestMctsNumberOfSolutions(regProblem, 1, 8);
|
---|
| 407 | }
|
---|
| 408 | {
|
---|
| 409 | // possible solutions with max one variable reference:
|
---|
| 410 | // without log and inv
|
---|
| 411 |
|
---|
| 412 | // x
|
---|
| 413 | // exp(x)
|
---|
| 414 | // y
|
---|
| 415 | // exp(y)
|
---|
| 416 | TestMctsNumberOfSolutions(regProblem, 1, 4, allowLog: false, allowInv: false);
|
---|
| 417 | }
|
---|
| 418 | {
|
---|
| 419 | // possible solutions with max two variable references:
|
---|
| 420 | // without log and inv
|
---|
| 421 |
|
---|
| 422 | // x
|
---|
| 423 | // y
|
---|
| 424 | // exp(x)
|
---|
| 425 | // exp(y)
|
---|
| 426 | // -- 4
|
---|
| 427 | // x (*|+) x
|
---|
| 428 | // x (*|+) exp(x)
|
---|
| 429 | // x (*|+) y
|
---|
| 430 | // x (*|+) exp(y)
|
---|
| 431 | // -- 8
|
---|
| 432 | // exp(x) (*|+) exp(x)
|
---|
| 433 | // exp(x) (*|+) exp(y)
|
---|
| 434 | // -- 4
|
---|
| 435 | // y (*|+) y
|
---|
| 436 | // y (*|+) exp(x)
|
---|
| 437 | // y (*|+) exp(y)
|
---|
| 438 | // -- 6
|
---|
| 439 | // exp(y) (*|+) exp(y)
|
---|
| 440 | // -- 2
|
---|
| 441 | //
|
---|
| 442 | // exp(x*x)
|
---|
| 443 | // exp(x*y)
|
---|
| 444 | // exp(y*y)
|
---|
| 445 | // -- 3
|
---|
| 446 |
|
---|
| 447 | TestMctsNumberOfSolutions(regProblem, 2, 4 + 8 + 4 + 6 + 2 + 3, allowLog: false, allowInv: false);
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | {
|
---|
| 451 | // possible solutions with max two variable references:
|
---|
| 452 | // without exp and sum
|
---|
| 453 | // x
|
---|
| 454 | // y
|
---|
| 455 | // log(x)
|
---|
| 456 | // log(y)
|
---|
| 457 | // inv(x)
|
---|
| 458 | // inv(y)
|
---|
| 459 | // -- 6
|
---|
| 460 | // x * x
|
---|
| 461 | // x * y
|
---|
| 462 | // x * log(x)
|
---|
| 463 | // x * log(y)
|
---|
| 464 | // x * inv(x)
|
---|
| 465 | // x * inv(y)
|
---|
| 466 | // -- 6
|
---|
| 467 | // log(x) * log(x)
|
---|
| 468 | // log(x) * log(y)
|
---|
| 469 | // log(x) * inv(x)
|
---|
| 470 | // log(x) * inv(y)
|
---|
| 471 | // -- 4
|
---|
| 472 | // inv(x) * inv(x)
|
---|
| 473 | // inv(x) * inv(y)
|
---|
| 474 | // -- 2
|
---|
| 475 | // y * y
|
---|
| 476 | // y * log(x)
|
---|
| 477 | // y * log(y)
|
---|
| 478 | // y * inv(x)
|
---|
| 479 | // y * inv(y)
|
---|
| 480 | // -- 5
|
---|
| 481 | // log(y) * log(y)
|
---|
| 482 | // log(y) * inv(x)
|
---|
| 483 | // log(y) * inv(y)
|
---|
| 484 | // -- 3
|
---|
| 485 | // inv(y) * inv(y)
|
---|
| 486 | // -- 1
|
---|
| 487 | // log(x*x)
|
---|
| 488 | // log(x*y)
|
---|
| 489 | // log(y*y)
|
---|
| 490 |
|
---|
| 491 | // inv(x*x)
|
---|
| 492 | // inv(x*y)
|
---|
| 493 | // inv(y*y)
|
---|
| 494 | // -- 6
|
---|
| 495 | // log(x+x)
|
---|
| 496 | // log(x+y)
|
---|
| 497 | // log(y+y)
|
---|
| 498 |
|
---|
| 499 | // inv(x+x)
|
---|
| 500 | // inv(x+y)
|
---|
| 501 | // inv(y+y)
|
---|
| 502 | // -- 6
|
---|
| 503 | TestMctsNumberOfSolutions(regProblem, 2, 6 + 6 + 4 + 2 + 5 + 3 + 1 + 6 + 6, allowExp: false, allowSum: false);
|
---|
| 504 | }
|
---|
| 505 | }
|
---|
| 506 | #endregion
|
---|
| 507 |
|
---|
[13661] | 508 |
|
---|
[15403] | 509 | #region test structure search (no constants)
|
---|
| 510 | [TestMethod]
|
---|
[13648] | 511 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 512 | [TestProperty("Time", "short")]
|
---|
[15403] | 513 | public void MctsSymbReg_NoConstants_Nguyen1() {
|
---|
| 514 | // x³ + x² + x
|
---|
| 515 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 516 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
|
---|
[15414] | 517 | TestMctsWithoutConstants(regProblem, nVarRefs: 10, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 518 | }
|
---|
[15403] | 519 | [TestMethod]
|
---|
[13648] | 520 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 521 | [TestProperty("Time", "short")]
|
---|
[15403] | 522 | public void MctsSymbReg_NoConstants_Nguyen2() {
|
---|
| 523 | // x^4 + x³ + x² + x
|
---|
| 524 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 525 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 ")));
|
---|
[15403] | 526 | TestMctsWithoutConstants(regProblem, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 527 | }
|
---|
[15403] | 528 | [TestMethod]
|
---|
[13648] | 529 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 530 | [TestProperty("Time", "short")]
|
---|
[15403] | 531 | public void MctsSymbReg_NoConstants_Nguyen3() {
|
---|
| 532 | // x^5 + x^4 + x³ + x² + x
|
---|
| 533 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 534 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));
|
---|
[15414] | 535 | TestMctsWithoutConstants(regProblem, nVarRefs: 15, iterations: 1000000, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 536 | }
|
---|
[15403] | 537 | [TestMethod]
|
---|
[13648] | 538 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 539 | [TestProperty("Time", "short")]
|
---|
[15403] | 540 | public void MctsSymbReg_NoConstants_Nguyen4() {
|
---|
| 541 | // x^6 + x^5 + x^4 + x³ + x² + x
|
---|
| 542 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 543 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 ")));
|
---|
[15414] | 544 | TestMctsWithoutConstants(regProblem, nVarRefs: 25, iterations: 1000000, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 545 | }
|
---|
[15403] | 546 |
|
---|
| 547 | [TestMethod]
|
---|
| 548 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 549 | [TestProperty("Time", "short")]
|
---|
[15414] | 550 | public void MctsSymbReg_NoConstants_Nguyen7() {
|
---|
| 551 | // log(x + 1) + log(x² + 1)
|
---|
| 552 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
| 553 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
|
---|
[15416] | 554 | TestMctsWithoutConstants(regProblem, nVarRefs: 10, iterations: 100000, allowExp: false, allowLog: true, allowInv: false);
|
---|
[15414] | 555 | }
|
---|
| 556 |
|
---|
| 557 | [TestMethod]
|
---|
| 558 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 559 | [TestProperty("Time", "short")]
|
---|
[15416] | 560 | public void MctsSymbReg_NoConstants_Poly10_Part1() {
|
---|
| 561 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 562 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 563 |
|
---|
| 564 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 565 | // Y' = X1*X2 + X3*X4 + X5*X6
|
---|
| 566 | // simplify problem by changing target
|
---|
| 567 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 568 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 569 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 570 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 571 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 572 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 573 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 574 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 575 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 576 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 577 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 578 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 579 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 580 | ys[i] -= x1[i] * x7[i] * x9[i];
|
---|
| 581 | ys[i] -= x3[i] * x6[i] * x10[i];
|
---|
| 582 | }
|
---|
| 583 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 584 |
|
---|
| 585 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 586 |
|
---|
| 587 |
|
---|
| 588 | TestMctsWithoutConstants(modifiedProblemData, nVarRefs: 15, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | [TestMethod]
|
---|
| 592 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 593 | [TestProperty("Time", "short")]
|
---|
| 594 | public void MctsSymbReg_NoConstants_Poly10_Part2() {
|
---|
| 595 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 596 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 597 |
|
---|
| 598 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 599 | // Y' = X1*X7*X9 + X3*X6*X10
|
---|
| 600 | // simplify problem by changing target
|
---|
| 601 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 602 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 603 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 604 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 605 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 606 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 607 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 608 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 609 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 610 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 611 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 612 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 613 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 614 | ys[i] -= x1[i] * x2[i];
|
---|
| 615 | ys[i] -= x3[i] * x4[i];
|
---|
| 616 | ys[i] -= x5[i] * x6[i];
|
---|
| 617 | }
|
---|
| 618 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 619 |
|
---|
| 620 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 621 |
|
---|
| 622 |
|
---|
| 623 | TestMctsWithoutConstants(modifiedProblemData, nVarRefs: 15, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | [TestMethod]
|
---|
| 627 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 628 | [TestProperty("Time", "short")]
|
---|
| 629 | public void MctsSymbReg_NoConstants_Poly10_Part3() {
|
---|
| 630 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 631 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 632 |
|
---|
| 633 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 634 | // Y' = X1*X2 + X1*X7*X9
|
---|
| 635 | // simplify problem by changing target
|
---|
| 636 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 637 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 638 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 639 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 640 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 641 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 642 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 643 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 644 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 645 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 646 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 647 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 648 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 649 | ys[i] -= x3[i] * x4[i];
|
---|
| 650 | ys[i] -= x5[i] * x6[i];
|
---|
| 651 | ys[i] -= x3[i] * x6[i] * x10[i];
|
---|
| 652 | }
|
---|
| 653 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 654 |
|
---|
| 655 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 656 |
|
---|
| 657 |
|
---|
| 658 | TestMctsWithoutConstants(modifiedProblemData, nVarRefs: 15, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 659 | }
|
---|
| 660 |
|
---|
| 661 | [TestMethod]
|
---|
| 662 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 663 | [TestProperty("Time", "short")]
|
---|
| 664 | public void MctsSymbReg_NoConstants_Poly10_Part4() {
|
---|
| 665 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 666 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 667 |
|
---|
| 668 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 669 | // Y' = X3*X4 + X5*X6 + X3*X6*X10
|
---|
| 670 | // simplify problem by changing target
|
---|
| 671 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 672 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 673 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 674 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 675 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 676 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 677 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 678 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 679 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 680 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 681 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 682 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 683 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 684 | ys[i] -= x1[i] * x2[i];
|
---|
| 685 | ys[i] -= x1[i] * x7[i] * x9[i];
|
---|
| 686 | }
|
---|
| 687 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 688 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 689 |
|
---|
| 690 |
|
---|
| 691 | TestMctsWithoutConstants(modifiedProblemData, nVarRefs: 15, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | [TestMethod]
|
---|
| 695 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 696 | [TestProperty("Time", "short")]
|
---|
| 697 | public void MctsSymbReg_NoConstants_Poly10_Part5() {
|
---|
| 698 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 699 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 700 |
|
---|
| 701 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 702 | // Y' = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9
|
---|
| 703 | // simplify problem by changing target
|
---|
| 704 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 705 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 706 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 707 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 708 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 709 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 710 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 711 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 712 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 713 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 714 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 715 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 716 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 717 | ys[i] -= x3[i] * x6[i] * x10[i];
|
---|
| 718 | }
|
---|
| 719 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 720 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 721 |
|
---|
| 722 |
|
---|
| 723 | TestMctsWithoutConstants(modifiedProblemData, nVarRefs: 15, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 724 | }
|
---|
| 725 |
|
---|
| 726 | [TestMethod]
|
---|
| 727 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 728 | [TestProperty("Time", "short")]
|
---|
| 729 | public void MctsSymbReg_NoConstants_Poly10_Part6() {
|
---|
| 730 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 731 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 732 |
|
---|
| 733 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 734 | // Y' = X1*X2 + X3*X4 + X5*X6 + X3*X6*X10
|
---|
| 735 | // simplify problem by changing target
|
---|
| 736 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 737 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 738 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 739 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 740 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 741 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 742 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 743 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 744 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 745 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 746 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 747 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 748 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 749 | ys[i] -= x1[i] * x7[i] * x9[i];
|
---|
| 750 | }
|
---|
| 751 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 752 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 753 |
|
---|
| 754 |
|
---|
| 755 | TestMctsWithoutConstants(modifiedProblemData, nVarRefs: 9, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 756 | }
|
---|
| 757 |
|
---|
| 758 |
|
---|
| 759 | [TestMethod]
|
---|
| 760 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
[15420] | 761 | [TestProperty("Time", "long")]
|
---|
| 762 | public void MctsSymbReg_NoConstants_Poly10_250rows() {
|
---|
[15403] | 763 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234);
|
---|
| 764 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
[15420] | 765 | regProblem.TrainingPartition.Start = 0;
|
---|
| 766 | regProblem.TrainingPartition.End = regProblem.Dataset.Rows;
|
---|
| 767 | regProblem.TestPartition.Start = 0;
|
---|
| 768 | regProblem.TestPartition.End = 2;
|
---|
[15416] | 769 | TestMctsWithoutConstants(regProblem, nVarRefs: 15, iterations: 200000, allowExp: false, allowLog: false, allowInv: false);
|
---|
[15403] | 770 | }
|
---|
[15420] | 771 | [TestMethod]
|
---|
| 772 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 773 | [TestProperty("Time", "long")]
|
---|
| 774 | public void MctsSymbReg_NoConstants_Poly10_10000rows() {
|
---|
| 775 | // as poly-10 but more rows
|
---|
| 776 | var rand = new FastRandom(1234);
|
---|
| 777 | var x1 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 778 | var x2 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 779 | var x3 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 780 | var x4 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 781 | var x5 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 782 | var x6 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 783 | var x7 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 784 | var x8 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 785 | var x9 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 786 | var x10 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 787 | var ys = new List<double>();
|
---|
| 788 | for (int i = 0; i < x1.Count; i++) {
|
---|
| 789 | ys.Add(x1[i] * x2[i] + x3[i] * x4[i] + x5[i] * x6[i] + x1[i] * x7[i] * x9[i] + x3[i] * x6[i] * x10[i]);
|
---|
| 790 | }
|
---|
[15416] | 791 |
|
---|
[15420] | 792 | var ds = new Dataset(new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "y" },
|
---|
| 793 | new[] { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, ys });
|
---|
| 794 |
|
---|
| 795 |
|
---|
| 796 | var problemData = new RegressionProblemData(ds, new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}, "y");
|
---|
| 797 |
|
---|
| 798 | problemData.TrainingPartition.Start = 0;
|
---|
| 799 | problemData.TrainingPartition.End = problemData.Dataset.Rows;
|
---|
| 800 | problemData.TestPartition.Start = 0;
|
---|
| 801 | problemData.TestPartition.End = 2; // must not be empty
|
---|
| 802 |
|
---|
| 803 |
|
---|
| 804 | TestMctsWithoutConstants(problemData, nVarRefs: 15, iterations: 100000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 805 | }
|
---|
| 806 |
|
---|
[15416] | 807 | [TestMethod]
|
---|
| 808 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 809 | [TestProperty("Time", "short")]
|
---|
| 810 | public void MctsSymbReg_NoConstants_TwoVars() {
|
---|
| 811 |
|
---|
| 812 | // y = x1 + x2 + x1*x2 + x1*x2*x2 + x1*x1*x2
|
---|
| 813 | var rand = new FastRandom(1234);
|
---|
| 814 | var x1 = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 815 | var x2 = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 816 | var ys = x1.Zip(x2, (x1i, x2i) => x1i + x2i + x1i * x2i + x1i * x2i * x2i + x1i * x1i * x2i).ToList();
|
---|
| 817 |
|
---|
| 818 | var ds = new Dataset(new string[] { "a", "b", "y" }, new[] { x1, x2, ys });
|
---|
| 819 |
|
---|
| 820 | var problemData = new RegressionProblemData(ds, new string[] { "a", "b" }, "y");
|
---|
| 821 |
|
---|
| 822 |
|
---|
| 823 | TestMctsWithoutConstants(problemData, nVarRefs: 10, iterations: 10000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 824 | }
|
---|
| 825 |
|
---|
| 826 | [TestMethod]
|
---|
| 827 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 828 | [TestProperty("Time", "short")]
|
---|
| 829 | public void MctsSymbReg_NoConstants_Misleading() {
|
---|
| 830 |
|
---|
| 831 | // y = a + baaaaa (the effect of the second term should be very small)
|
---|
| 832 | // the alg will quickly find that a has big effect and will search below a
|
---|
| 833 | // since we prevent a + a... the algorithm must find the correct expression via a + b...
|
---|
| 834 | // however b has a small effect so the branch might not be identified as relevant
|
---|
| 835 |
|
---|
| 836 | var rand = new FastRandom(1234);
|
---|
| 837 | var @as = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 838 | var bs = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
[15420] | 839 | var cs = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() * 1.0e-3).ToList();
|
---|
| 840 | var ds = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 841 | var es = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
[15416] | 842 | var ys = new double[@as.Count];
|
---|
[15420] | 843 | for (int i = 0; i < ys.Length; i++)
|
---|
| 844 | ys[i] = @as[i] + bs[i] + @as[i] * bs[i] * cs[i];
|
---|
[15416] | 845 |
|
---|
| 846 | var dataset = new Dataset(new string[] { "a", "b", "c", "d", "e", "y" }, new[] { @as, bs, cs, ds, es, ys.ToList() });
|
---|
| 847 |
|
---|
[15420] | 848 | var problemData = new RegressionProblemData(dataset, new string[] { "a", "b", "c", "d", "e" }, "y");
|
---|
[15416] | 849 |
|
---|
| 850 |
|
---|
| 851 | TestMctsWithoutConstants(problemData, nVarRefs: 10, iterations: 10000, allowExp: false, allowLog: false, allowInv: false);
|
---|
| 852 | }
|
---|
[15403] | 853 | #endregion
|
---|
| 854 |
|
---|
| 855 | #region restricted structure but including numeric constants
|
---|
| 856 |
|
---|
| 857 | [TestMethod]
|
---|
| 858 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 859 | [TestProperty("Time", "short")]
|
---|
| 860 | public void MctsSymbRegKeijzer7() {
|
---|
| 861 | // ln(x)
|
---|
| 862 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
| 863 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 7 f(")));
|
---|
| 864 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 865 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 866 | TestMcts(regProblem, allowExp: false, allowLog: true, allowInv: false);
|
---|
| 867 | }
|
---|
| 868 |
|
---|
| 869 | /*
|
---|
[13708] | 870 | // [TestMethod]
|
---|
[13648] | 871 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 872 | [TestProperty("Time", "short")]
|
---|
| 873 | public void MctsSymbRegBenchmarkNguyen5() {
|
---|
[15403] | 874 | // sin(x²)cos(x) - 1
|
---|
[13648] | 875 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 876 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F5 ")));
|
---|
| 877 | TestMcts(regProblem);
|
---|
| 878 | }
|
---|
[13708] | 879 | // [TestMethod]
|
---|
[13648] | 880 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 881 | [TestProperty("Time", "short")]
|
---|
| 882 | public void MctsSymbRegBenchmarkNguyen6() {
|
---|
[15403] | 883 | // sin(x) + sin(x + x²)
|
---|
[13648] | 884 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 885 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 ")));
|
---|
| 886 | TestMcts(regProblem);
|
---|
| 887 | }
|
---|
[15403] | 888 | */
|
---|
| 889 | [TestMethod]
|
---|
[13648] | 890 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 891 | [TestProperty("Time", "short")]
|
---|
| 892 | public void MctsSymbRegBenchmarkNguyen7() {
|
---|
[15403] | 893 | // log(x + 1) + log(x² + 1)
|
---|
| 894 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 895 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
|
---|
[15420] | 896 | TestMcts(regProblem, maxVariableReferences: 5, allowExp: false, allowLog: true, allowInv: false);
|
---|
[13648] | 897 | }
|
---|
[15403] | 898 | [TestMethod]
|
---|
[13648] | 899 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 900 | [TestProperty("Time", "short")]
|
---|
| 901 | public void MctsSymbRegBenchmarkNguyen8() {
|
---|
[15403] | 902 | // Sqrt(x)
|
---|
| 903 | // = x ^ 0.5
|
---|
| 904 | // = exp(0.5 * log(x))
|
---|
| 905 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 906 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F8 ")));
|
---|
[15403] | 907 | TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false);
|
---|
[13648] | 908 | }
|
---|
[15403] | 909 | /*
|
---|
[13708] | 910 | // [TestMethod]
|
---|
[13648] | 911 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 912 | [TestProperty("Time", "short")]
|
---|
| 913 | public void MctsSymbRegBenchmarkNguyen9() {
|
---|
[15403] | 914 | // sin(x) + sin(y²)
|
---|
[13648] | 915 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 916 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
|
---|
[15403] | 917 | TestMcts(regProblem);
|
---|
[13648] | 918 | }
|
---|
[13708] | 919 | // [TestMethod]
|
---|
[13648] | 920 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 921 | [TestProperty("Time", "short")]
|
---|
| 922 | public void MctsSymbRegBenchmarkNguyen10() {
|
---|
[15403] | 923 | // 2sin(x)cos(y)
|
---|
[13648] | 924 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 925 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F10 ")));
|
---|
| 926 | TestMcts(regProblem);
|
---|
| 927 | }
|
---|
[15403] | 928 | */
|
---|
| 929 | [TestMethod]
|
---|
[13648] | 930 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 931 | [TestProperty("Time", "short")]
|
---|
| 932 | public void MctsSymbRegBenchmarkNguyen11() {
|
---|
[15403] | 933 | // x ^ y , x > 0, y > 0
|
---|
| 934 | // = exp(y * log(x))
|
---|
| 935 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 936 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F11 ")));
|
---|
[15420] | 937 | TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false);
|
---|
[13648] | 938 | }
|
---|
[15403] | 939 | [TestMethod]
|
---|
[13648] | 940 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 941 | [TestProperty("Time", "short")]
|
---|
| 942 | public void MctsSymbRegBenchmarkNguyen12() {
|
---|
[15403] | 943 | // x^4 - x³ + y²/2 - y
|
---|
| 944 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234);
|
---|
[13648] | 945 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F12 ")));
|
---|
[15403] | 946 | TestMcts(regProblem, maxVariableReferences: 20, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 947 | }
|
---|
| 948 |
|
---|
| 949 | #endregion
|
---|
| 950 |
|
---|
| 951 | #region keijzer
|
---|
[15403] | 952 | [TestMethod]
|
---|
[13648] | 953 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 954 | [TestProperty("Time", "long")]
|
---|
| 955 | public void MctsSymbRegBenchmarkKeijzer5() {
|
---|
[15403] | 956 | // (30 * x * z) / ((x - 10) * y²)
|
---|
| 957 | // = 30 x z / (xy² - y²)
|
---|
| 958 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 959 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 5 f(")));
|
---|
| 960 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 961 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 962 | TestMcts(regProblem, maxVariableReferences: 20, allowExp: false, allowLog: false, allowInv: true);
|
---|
[13648] | 963 | }
|
---|
| 964 |
|
---|
[15403] | 965 | [TestMethod]
|
---|
[13648] | 966 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 967 | [TestProperty("Time", "short")]
|
---|
| 968 | public void MctsSymbRegBenchmarkKeijzer6() {
|
---|
[15403] | 969 | // Keijzer 6 f(x) = Sum(1 / i) From 1 to X , x \in [0..120]
|
---|
| 970 | // we can only approximate this
|
---|
| 971 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 972 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 6 f(")));
|
---|
| 973 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 974 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 975 | TestMcts(regProblem, maxVariableReferences: 20, allowExp: false, allowLog: false, allowInv: true);
|
---|
[13648] | 976 | }
|
---|
| 977 |
|
---|
| 978 |
|
---|
| 979 | [TestMethod]
|
---|
[15403] | 980 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
[13648] | 981 | [TestProperty("Time", "short")]
|
---|
| 982 | public void MctsSymbRegBenchmarkKeijzer8() {
|
---|
[15403] | 983 | // sqrt(x)
|
---|
| 984 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 985 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 8 f(")));
|
---|
| 986 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 987 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 988 | TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false);
|
---|
[13648] | 989 | }
|
---|
| 990 |
|
---|
| 991 | [TestMethod]
|
---|
[15403] | 992 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
[13648] | 993 | [TestProperty("Time", "short")]
|
---|
| 994 | public void MctsSymbRegBenchmarkKeijzer9() {
|
---|
[15403] | 995 | // arcsinh(x) i.e. ln(x + sqrt(x² + 1))
|
---|
| 996 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 997 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 9 f(")));
|
---|
| 998 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 999 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 1000 | TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false);
|
---|
[13648] | 1001 | }
|
---|
| 1002 |
|
---|
[15403] | 1003 | /*
|
---|
[13648] | 1004 | [TestMethod]
|
---|
| 1005 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 1006 | [TestProperty("Time", "short")]
|
---|
| 1007 | public void MctsSymbRegBenchmarkKeijzer11() {
|
---|
[15403] | 1008 | // xy + sin( (x-1) (y-1) )
|
---|
[13648] | 1009 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
|
---|
| 1010 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 11 f(")));
|
---|
| 1011 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 1012 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 1013 | TestMcts(regProblem, successThreshold: 0.99); // cannot solve this yet
|
---|
| 1014 | }
|
---|
| 1015 | */
|
---|
[15403] | 1016 | [TestMethod]
|
---|
[13648] | 1017 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 1018 | [TestProperty("Time", "short")]
|
---|
| 1019 | public void MctsSymbRegBenchmarkKeijzer12() {
|
---|
[15403] | 1020 | // x^4 - x³ + y² / 2 - y, same as Nguyen 12
|
---|
| 1021 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 1022 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 12 f(")));
|
---|
| 1023 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 1024 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 1025 | TestMcts(regProblem, maxVariableReferences: 15, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 1026 | }
|
---|
[15403] | 1027 | [TestMethod]
|
---|
[13648] | 1028 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 1029 | [TestProperty("Time", "short")]
|
---|
| 1030 | public void MctsSymbRegBenchmarkKeijzer14() {
|
---|
[15403] | 1031 | // 8 / (2 + x² + y²)
|
---|
| 1032 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 1033 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 14 f(")));
|
---|
| 1034 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 1035 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 1036 | TestMcts(regProblem, maxVariableReferences: 10, allowExp: false, allowLog: false, allowInv: true);
|
---|
[13648] | 1037 | }
|
---|
[15403] | 1038 | [TestMethod]
|
---|
[13648] | 1039 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 1040 | [TestProperty("Time", "short")]
|
---|
| 1041 | public void MctsSymbRegBenchmarkKeijzer15() {
|
---|
[15403] | 1042 | // x³ / 5 + y³ / 2 - y - x
|
---|
| 1043 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234);
|
---|
[13648] | 1044 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 15 f(")));
|
---|
| 1045 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 1046 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
[15403] | 1047 | TestMcts(regProblem, maxVariableReferences: 10, allowExp: false, allowLog: false, allowInv: false);
|
---|
[13648] | 1048 | }
|
---|
| 1049 | #endregion
|
---|
| 1050 |
|
---|
[15403] | 1051 | private void TestMcts(IRegressionProblemData problemData,
|
---|
| 1052 | int iterations = 20000,
|
---|
| 1053 | double successThreshold = 0.99999,
|
---|
| 1054 | int maxVariableReferences = 5,
|
---|
[13648] | 1055 | bool allowExp = true,
|
---|
| 1056 | bool allowLog = true,
|
---|
| 1057 | bool allowInv = true,
|
---|
| 1058 | bool allowSum = true
|
---|
| 1059 | ) {
|
---|
| 1060 | var mctsSymbReg = new MctsSymbolicRegressionAlgorithm();
|
---|
| 1061 | var regProblem = new RegressionProblem();
|
---|
| 1062 | regProblem.ProblemDataParameter.Value = problemData;
|
---|
| 1063 | #region Algorithm Configuration
|
---|
| 1064 | mctsSymbReg.Problem = regProblem;
|
---|
| 1065 | mctsSymbReg.Iterations = iterations;
|
---|
[15403] | 1066 | mctsSymbReg.MaxVariableReferences = maxVariableReferences;
|
---|
| 1067 |
|
---|
[13648] | 1068 | mctsSymbReg.SetSeedRandomly = false;
|
---|
| 1069 | mctsSymbReg.Seed = 1234;
|
---|
| 1070 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp")), allowExp);
|
---|
| 1071 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog);
|
---|
| 1072 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 /")), allowInv);
|
---|
[15403] | 1073 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("t1(x) + t2(x) + ... ")), allowSum);
|
---|
| 1074 |
|
---|
| 1075 | mctsSymbReg.ScaleVariables = true;
|
---|
| 1076 | mctsSymbReg.ConstantOptimizationIterations = 0;
|
---|
| 1077 |
|
---|
[13648] | 1078 | #endregion
|
---|
| 1079 | RunAlgorithm(mctsSymbReg);
|
---|
| 1080 |
|
---|
| 1081 | Console.WriteLine(mctsSymbReg.ExecutionTime);
|
---|
| 1082 | var eps = 1.0 - successThreshold;
|
---|
| 1083 | Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (train)"].Value).Value, eps);
|
---|
| 1084 | Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (test)"].Value).Value, eps);
|
---|
| 1085 | }
|
---|
| 1086 |
|
---|
[15403] | 1087 |
|
---|
[15414] | 1088 | private void TestMctsWithoutConstants(IRegressionProblemData problemData,
|
---|
| 1089 | int nVarRefs = 10,
|
---|
| 1090 | int iterations = 200000, double successThreshold = 0.99999,
|
---|
[15403] | 1091 | bool allowExp = true,
|
---|
| 1092 | bool allowLog = true,
|
---|
| 1093 | bool allowInv = true,
|
---|
| 1094 | bool allowSum = true
|
---|
| 1095 | ) {
|
---|
| 1096 | var mctsSymbReg = new MctsSymbolicRegressionAlgorithm();
|
---|
| 1097 | var regProblem = new RegressionProblem();
|
---|
| 1098 | regProblem.ProblemDataParameter.Value = problemData;
|
---|
| 1099 | #region Algorithm Configuration
|
---|
| 1100 | mctsSymbReg.Problem = regProblem;
|
---|
| 1101 | mctsSymbReg.Iterations = iterations;
|
---|
[15414] | 1102 | mctsSymbReg.MaxVariableReferences = nVarRefs;
|
---|
[15403] | 1103 | mctsSymbReg.SetSeedRandomly = false;
|
---|
| 1104 | mctsSymbReg.Seed = 1234;
|
---|
| 1105 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp")), allowExp);
|
---|
| 1106 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog);
|
---|
| 1107 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 /")), allowInv);
|
---|
| 1108 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("t1(x) + t2(x) + ... ")), allowSum);
|
---|
| 1109 |
|
---|
| 1110 | // no constants
|
---|
| 1111 | mctsSymbReg.ScaleVariables = false;
|
---|
| 1112 | mctsSymbReg.ConstantOptimizationIterations = -1;
|
---|
| 1113 |
|
---|
[15416] | 1114 | // random policy
|
---|
| 1115 | // var epsPolicy = new EpsilonGreedy();
|
---|
| 1116 | // epsPolicy.Eps = 1.0;
|
---|
| 1117 | // mctsSymbReg.Policy = epsPolicy;
|
---|
| 1118 |
|
---|
| 1119 | // UCB tuned
|
---|
| 1120 | // var ucbTuned = new UcbTuned();
|
---|
| 1121 | // ucbTuned.C = 1.5;
|
---|
| 1122 | // mctsSymbReg.Policy = ucbTuned;
|
---|
| 1123 |
|
---|
| 1124 |
|
---|
[15403] | 1125 | #endregion
|
---|
| 1126 | RunAlgorithm(mctsSymbReg);
|
---|
| 1127 |
|
---|
| 1128 | Console.WriteLine(mctsSymbReg.ExecutionTime);
|
---|
| 1129 | var eps = 1.0 - successThreshold;
|
---|
| 1130 | Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (train)"].Value).Value, eps);
|
---|
| 1131 | Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (test)"].Value).Value, eps);
|
---|
| 1132 | }
|
---|
| 1133 |
|
---|
[13648] | 1134 | private void TestMctsNumberOfSolutions(IRegressionProblemData problemData, int maxNumberOfVariables, int expectedNumberOfSolutions,
|
---|
[13651] | 1135 | bool allowProd = true,
|
---|
[13648] | 1136 | bool allowExp = true,
|
---|
| 1137 | bool allowLog = true,
|
---|
| 1138 | bool allowInv = true,
|
---|
| 1139 | bool allowSum = true
|
---|
| 1140 | ) {
|
---|
| 1141 | var mctsSymbReg = new MctsSymbolicRegressionAlgorithm();
|
---|
| 1142 | var regProblem = new RegressionProblem();
|
---|
| 1143 | regProblem.ProblemDataParameter.Value = problemData;
|
---|
| 1144 | #region Algorithm Configuration
|
---|
[13651] | 1145 |
|
---|
| 1146 | mctsSymbReg.SetSeedRandomly = false;
|
---|
| 1147 | mctsSymbReg.Seed = 1234;
|
---|
[13648] | 1148 | mctsSymbReg.Problem = regProblem;
|
---|
| 1149 | mctsSymbReg.Iterations = int.MaxValue; // stopping when all solutions have been enumerated
|
---|
[13654] | 1150 | mctsSymbReg.MaxVariableReferences = maxNumberOfVariables;
|
---|
[13661] | 1151 | var ucbPolicy = new Ucb();
|
---|
| 1152 | ucbPolicy.C = 1000; // essentially breadth first search
|
---|
| 1153 | mctsSymbReg.Policy = ucbPolicy;
|
---|
[15403] | 1154 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.StartsWith("x * y * ...")), allowProd);
|
---|
| 1155 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp(c * x * y ...)")), allowExp);
|
---|
| 1156 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log(c + c1 x + c2 x + ...)")), allowLog);
|
---|
| 1157 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 / (1 + c1 x + c2 x + ...)")), allowInv);
|
---|
| 1158 | mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("t1(x) + t2(x) + ... ")), allowSum);
|
---|
[13648] | 1159 | #endregion
|
---|
| 1160 | RunAlgorithm(mctsSymbReg);
|
---|
| 1161 |
|
---|
| 1162 | Console.WriteLine(mctsSymbReg.ExecutionTime);
|
---|
| 1163 | Assert.AreEqual(expectedNumberOfSolutions, ((IntValue)mctsSymbReg.Results["Iterations"].Value).Value);
|
---|
| 1164 | }
|
---|
| 1165 |
|
---|
| 1166 |
|
---|
| 1167 | // same as in SamplesUtil
|
---|
| 1168 | private void RunAlgorithm(IAlgorithm a) {
|
---|
| 1169 | var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);
|
---|
| 1170 | Exception ex = null;
|
---|
| 1171 | a.Stopped += (src, e) => { trigger.Set(); };
|
---|
| 1172 | a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };
|
---|
| 1173 | a.Prepare();
|
---|
| 1174 | a.Start();
|
---|
| 1175 | trigger.WaitOne();
|
---|
| 1176 |
|
---|
| 1177 | Assert.AreEqual(ex, null);
|
---|
| 1178 | }
|
---|
| 1179 |
|
---|
| 1180 | }
|
---|
| 1181 | }
|
---|