Changeset 9696 for branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/Resources
- Timestamp:
- 07/04/13 18:05:17 (11 years ago)
- 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 2 2 3 3 CODE << 4 double[,] inputValues;5 double[] targetValues;4 double[,] x; 5 double[] y; 6 6 string[] variableNames; 7 7 Dictionary<string,int> nameToCol; … … 15 15 } 16 16 } 17 return data[row, nameToCol[varName]];17 return x[row, nameToCol[varName]]; 18 18 } 19 19 … … 24 24 else return 0.0; 25 25 } 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 }43 26 >> 44 27 45 28 INIT << 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 } 47 45 >> 48 46 … … 75 73 | Division<<row, out val>> 76 74 | 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); >> 78 76 | Const<<out val>> 79 77 . … … 94 92 MAXIMIZE /* could also use the keyword MINIMIZE here */ 95 93 << 96 var rows = System.Linq.Enumerable.Range(0, inputValues.GetLength(0));94 var rows = System.Linq.Enumerable.Range(0, x.GetLength(0)); 97 95 var predicted = rows.Select(r => { 98 96 double result; … … 100 98 return result; 101 99 }); 102 return RSquared(predicted, targetValues);100 return RSquared(predicted, y); 103 101 >> 104 102 END SymbReg. -
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/Resources/symbreg Koza.txt
r9519 r9696 1 1 PROBLEM SymbRegKoza 2 2 CODE << 3 double[,] inputValues;4 double[] targetValues;3 double[,] x; 4 double[] y; 5 5 string[] variableNames; 6 6 Dictionary<string,int> nameToCol; … … 14 14 } 15 15 } 16 return data[row, nameToCol[varName]];16 return x[row, nameToCol[varName]]; 17 17 } 18 18 … … 23 23 else return 0.0; 24 24 } 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 }42 25 >> 43 26 44 27 INIT << 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 } 46 44 >> 47 45 … … 74 72 | Division<<row, out val>> 75 73 | Multiplication<<row, out val>> 76 | Var<<out varName>> SEM << val = GetValue( inputValues, varName, row); >>74 | Var<<out varName>> SEM << val = GetValue(x, varName, row); >> 77 75 | ERC<<out val>> 78 76 . … … 93 91 MAXIMIZE /* could also use the keyword MINIMIZE here */ 94 92 << 95 var rows = System.Linq.Enumerable.Range(0, inputValues.GetLength(0));93 var rows = System.Linq.Enumerable.Range(0, x.GetLength(0)); 96 94 var predicted = rows.Select(r => { 97 95 double result; … … 99 97 return result; 100 98 }); 101 return RSquared(predicted, targetValues);99 return RSquared(predicted, y); 102 100 >> 103 101 END SymbRegKoza.
Note: See TracChangeset
for help on using the changeset viewer.