Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/04/13 18:05:17 (11 years ago)
Author:
gkronber
Message:

#2026 simplified symb-reg example, cleaned ATG file (whitespace), removed obsolete files

Location:
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/Resources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/Resources/symbreg HEAL.txt

    r9519 r9696  
    22
    33CODE <<
    4   double[,] inputValues;
    5   double[] targetValues;
     4  double[,] x;
     5  double[] y;
    66  string[] variableNames;
    77  Dictionary<string,int> nameToCol;
     
    1515      }
    1616    }
    17     return data[row, nameToCol[varName]];
     17    return x[row, nameToCol[varName]];
    1818  }
    1919
     
    2424     else return 0.0;
    2525  }
    26  
    27 
    28   void LoadData(string fileName, out double[,] inputValues, out string[] variableNames, out double[] target) {
    29     var prov = new HeuristicLab.Problems.Instances.DataAnalysis.RegressionRealWorldInstanceProvider();
    30     var dd = prov.GetDataDescriptors().OfType<HeuristicLab.Problems.Instances.DataAnalysis.Housing>().Single();
    31     var problemData = prov.LoadData(dd);   
    32    
    33     inputValues = new double[problemData.TrainingIndices.Count(), problemData.AllowedInputVariables.Count()];
    34     foreach(var r in problemData.TrainingIndices) {
    35        int i=0;
    36        foreach(var v in problemData.AllowedInputVariables) {
    37           inputValues[r, i++] = problemData.Dataset.GetDoubleValue(v, r);
    38        }
    39     }
    40     variableNames = problemData.AllowedInputVariables.ToArray();
    41     target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray();
    42   }
    4326>>
    4427
    4528INIT <<
    46   LoadData("filename.csv", out inputValues, out variableNames, out targetValues);
     29  // generate 500 case of poly-10 benchmark function
     30  int n = 500;
     31  variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" };
     32  var rand = new System.Random();
     33  x = new double[n, 10];
     34  y = new double[n];
     35  for(int row = 0; row < 500; row++) {
     36    for(int col = 0; col < 10; col++) {
     37      x[row, col] = rand.NextDouble() * 2.0 - 1.0;
     38    }
     39    y[row] = x[row, 0] * x[row, 1] +
     40             x[row, 2] * x[row, 3] +
     41             x[row, 4] * x[row, 5] +
     42             x[row, 0] * x[row, 6] + x[row, 8] +
     43             x[row, 2] * x[row, 5] + x[row, 9];
     44  }
    4745>>
    4846
     
    7573    | Division<<row, out val>>
    7674    | Multiplication<<row, out val>>                       
    77     | Var<<out varName, out w>>                            SEM << val = w * GetValue(inputValues, varName, row); >>
     75    | Var<<out varName, out w>>                            SEM << val = w * GetValue(x, varName, row); >>
    7876    | Const<<out val>>
    7977  .
     
    9492MAXIMIZE                                                   /* could also use the keyword MINIMIZE here */
    9593  <<
    96     var rows = System.Linq.Enumerable.Range(0, inputValues.GetLength(0));
     94    var rows = System.Linq.Enumerable.Range(0, x.GetLength(0));
    9795    var predicted = rows.Select(r => {
    9896      double result;
     
    10098      return result;
    10199    });
    102     return RSquared(predicted, targetValues);
     100    return RSquared(predicted, y);
    103101  >>
    104102END SymbReg.
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/Resources/symbreg Koza.txt

    r9519 r9696  
    11PROBLEM SymbRegKoza
    22CODE <<
    3   double[,] inputValues;
    4   double[] targetValues;
     3  double[,] x;
     4  double[] y;
    55  string[] variableNames;
    66  Dictionary<string,int> nameToCol;
     
    1414      }
    1515    }
    16     return data[row, nameToCol[varName]];
     16    return x[row, nameToCol[varName]];
    1717  }
    1818
     
    2323     else return 0.0;
    2424  }
    25  
    26 
    27   void LoadData(string fileName, out double[,] inputValues, out string[] variableNames, out double[] target) {
    28     var prov = new HeuristicLab.Problems.Instances.DataAnalysis.RegressionRealWorldInstanceProvider();
    29     var dd = prov.GetDataDescriptors().OfType<HeuristicLab.Problems.Instances.DataAnalysis.Housing>().Single();
    30     var problemData = prov.LoadData(dd);   
    31    
    32     inputValues = new double[problemData.TrainingIndices.Count(), problemData.AllowedInputVariables.Count()];
    33     foreach(var r in problemData.TrainingIndices) {
    34        int i=0;
    35        foreach(var v in problemData.AllowedInputVariables) {
    36           inputValues[r, i++] = problemData.Dataset.GetDoubleValue(v, r);
    37        }
    38     }
    39     variableNames = problemData.AllowedInputVariables.ToArray();
    40     target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray();
    41   }
    4225>>
    4326
    4427INIT <<
    45   LoadData("filename.csv", out inputValues, out variableNames, out targetValues);
     28  // generate 500 case of poly-10 benchmark function
     29  int n = 500;
     30  variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" };
     31  var rand = new System.Random();
     32  x = new double[n, 10];
     33  y = new double[n];
     34  for(int row = 0; row < 500; row++) {
     35    for(int col = 0; col < 10; col++) {
     36      x[row, col] = rand.NextDouble() * 2.0 - 1.0;
     37    }
     38    y[row] = x[row, 0] * x[row, 1] +
     39             x[row, 2] * x[row, 3] +
     40             x[row, 4] * x[row, 5] +
     41             x[row, 0] * x[row, 6] + x[row, 8] +
     42             x[row, 2] * x[row, 5] + x[row, 9];
     43  }
    4644>>
    4745
     
    7472    | Division<<row, out val>>
    7573    | Multiplication<<row, out val>>
    76     | Var<<out varName>>                                   SEM << val = GetValue(inputValues, varName, row); >>
     74    | Var<<out varName>>                                   SEM << val = GetValue(x, varName, row); >>
    7775    | ERC<<out val>>
    7876  .
     
    9391MAXIMIZE                                                   /* could also use the keyword MINIMIZE here */
    9492  <<
    95     var rows = System.Linq.Enumerable.Range(0, inputValues.GetLength(0));
     93    var rows = System.Linq.Enumerable.Range(0, x.GetLength(0));
    9694    var predicted = rows.Select(r => {
    9795      double result;
     
    9997      return result;
    10098    });
    101     return RSquared(predicted, targetValues);
     99    return RSquared(predicted, y);
    102100  >>
    103101END SymbRegKoza.
Note: See TracChangeset for help on using the changeset viewer.