PROBLEM SymbReg CODE << double[,] x; double[] y; string[] variableNames; Dictionary nameToCol; double GetValue(double[,] data, string varName, int row) { if(nameToCol == null) { /* init mapping */ nameToCol = new Dictionary(); for(int i=0; i xs, IEnumerable ys) { HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError error; var r2 = HeuristicLab.Problems.DataAnalysis.OnlinePearsonsRSquaredCalculator.Calculate(xs, ys, out error); if(error == HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError.None) return r2; else return 0.0; } >> INIT << // generate 500 case of poly-10 benchmark function int n = 500; variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" }; var rand = new System.Random(); x = new double[n, 10]; y = new double[n]; for(int row = 0; row < 500; row++) { for(int col = 0; col < 10; col++) { x[row, col] = rand.NextDouble() * 2.0 - 1.0; } y[row] = x[row, 0] * x[row, 1] + x[row, 2] * x[row, 3] + x[row, 4] * x[row, 5] + x[row, 0] * x[row, 6] + x[row, 8] + x[row, 2] * x[row, 5] + x[row, 9]; } >> NONTERMINALS Model<>. RPB<>. Addition<>. Subtraction<>. Multiplication<>. Division<>. TERMINALS Const<> CONSTRAINTS val IN RANGE <<-100>> .. <<100>> . Var<> CONSTRAINTS varName IN SET <> weight IN RANGE <<-100>> .. <<100>> . RULES Model<> = RPB<> . RPB<> = LOCAL << string varName; double w; >> Addition<> | Subtraction<> | Division<> | Multiplication<> | Var<> SEM << val = w * GetValue(x, varName, row); >> | Const<> . Addition<> = LOCAL << double x1, x2; >> RPB<> RPB<> SEM << val = x1 + x2; >> . Subtraction<> = LOCAL << double x1, x2; >> RPB<> RPB<> SEM << val = x1 - x2; >> . Division<> = LOCAL << double x1, x2; >> RPB<> RPB<> SEM << val = x1 / x2; >> . Multiplication<> = LOCAL << double x1, x2; >> RPB<> RPB<> SEM << val = x1 * x2; >> . MAXIMIZE /* could also use the keyword MINIMIZE here */ << var rows = System.Linq.Enumerable.Range(0, x.GetLength(0)); var predicted = rows.Select(r => { double result; Model(r, out result); /* we can call the root symbol directly */ return result; }); return RSquared(predicted, y); >> END SymbReg.