Changeset 3491
- Timestamp:
- 04/22/10 18:41:07 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ISymbolicRegressionEvaluator.cs
r3452 r3491 40 40 IValueLookupParameter<IntValue> SamplesStartParameter { get; } 41 41 IValueLookupParameter<IntValue> SamplesEndParameter { get; } 42 ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter { get; }43 42 } 44 43 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs
r3462 r3491 46 46 private const string SamplesStartParameterName = "SamplesStart"; 47 47 private const string SamplesEndParameterName = "SamplesEnd"; 48 private const string NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes";49 48 #region ISymbolicRegressionEvaluator Members 50 49 … … 73 72 } 74 73 75 public ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter {76 get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfEvaluatedNodexParameterName]; }77 }78 74 #endregion 79 75 #region properties … … 103 99 Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated.")); 104 100 Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic regression solution should be evaluated.")); 105 Parameters.Add(new LookupParameter<DoubleValue>(NumberOfEvaluatedNodexParameterName, "The number of evaluated nodes so far (for performance measurements.)"));106 101 } 107 102 108 103 public override IOperation Apply() { 109 DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;110 104 QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset, 111 RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd , numberOfEvaluatedNodes));105 RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd)); 112 106 return null; 113 107 } … … 117 111 Dataset dataset, 118 112 StringValue targetVariable, 119 IntValue samplesStart, IntValue samplesEnd, 120 DoubleValue numberOfEvaluatedNodes); 113 IntValue samplesStart, IntValue samplesEnd); 121 114 } 122 115 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r3462 r3491 41 41 [StorableClass] 42 42 public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator { 43 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd , DoubleValue numberOfEvaluatedNodes) {43 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd) { 44 44 double mse = Calculate(interpreter, solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value); 45 numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value);46 45 return mse; 47 46 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3480 r3491 73 73 get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; } 74 74 } 75 public ValueParameter<DoubleValue> NumberOfEvaluatedNodesParameter {76 get { return (ValueParameter<DoubleValue>)Parameters["NumberOfEvaluatedNodes"]; }77 }78 75 public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter { 79 76 get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; } … … 159 156 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", new IntValue(3))); 160 157 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", new IntValue(3))); 161 Parameters.Add(new ValueParameter<DoubleValue>("NumberOfEvaluatedNodes", "The total number of evaluated function tree nodes (for performance measurements.)", new DoubleValue()));162 158 Parameters.Add(new ValueParameter<ISingleObjectiveSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize symbolic regression solutions.", visualizer)); 163 159 … … 323 319 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 324 320 op.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name; 325 op.NumberOfEvaluatedNodesParameter.ActualName = NumberOfEvaluatedNodesParameter.Name;326 321 } 327 322 foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs
r3462 r3491 33 33 [StorableClass] 34 34 [Item("SimpleArithmeticExpressionInterpreter", "Interpreter for arithmetic symbolic expression trees including function calls.")] 35 // not thread safe! 35 36 public class SimpleArithmeticExpressionInterpreter : Item, ISymbolicExpressionTreeInterpreter { 36 37 private class OpCodes { … … 45 46 } 46 47 48 private const int ARGUMENT_STACK_SIZE = 1024; 47 49 private Dataset dataset; 48 50 private int row; … … 58 60 this.row = row; 59 61 pc = 0; 60 arg umentStack.Clear();62 argStackPointer = 0; 61 63 var estimatedValue = Evaluate(); 62 64 if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0; … … 85 87 } 86 88 87 private Stack<List<double>> argumentStack = new Stack<List<double>>(); 89 private double[] argumentStack = new double[ARGUMENT_STACK_SIZE]; 90 private int argStackPointer; 91 88 92 public double Evaluate() { 89 93 var currentInstr = code[pc++]; … … 118 122 } 119 123 case OpCodes.Call: { 120 // save current arguments121 List<double> arguments = new List<double>();122 124 // evaluate sub-trees 125 // push on argStack in reverse order 123 126 for (int i = 0; i < currentInstr.nArguments; i++) { 124 arguments.Add(Evaluate()); 127 argumentStack[argStackPointer + currentInstr.nArguments - i] = Evaluate(); 128 argStackPointer++; 125 129 } 126 argumentStack.Push(arguments); 130 127 131 // save the pc 128 132 int nextPc = pc; … … 131 135 // evaluate the function 132 136 double v = Evaluate(); 133 argumentStack.Pop(); 137 138 // decrease the argument stack pointer by the number of arguments pushed 139 // to set the argStackPointer back to the original location 140 argStackPointer -= currentInstr.nArguments; 141 134 142 // restore the pc => evaluation will continue at point after my subtrees 135 143 pc = nextPc; … … 137 145 } 138 146 case OpCodes.Arg: { 139 return argumentStack .Peek()[currentInstr.iArg0];147 return argumentStack[argStackPointer - currentInstr.iArg0]; 140 148 } 141 149 case OpCodes.Variable: {
Note: See TracChangeset
for help on using the changeset viewer.