Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3491


Ignore:
Timestamp:
04/22/10 18:41:07 (15 years ago)
Author:
gkronber
Message:

Minor improvements. #938 (Data types and operators for regression problems)

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ISymbolicRegressionEvaluator.cs

    r3452 r3491  
    4040    IValueLookupParameter<IntValue> SamplesStartParameter { get; }
    4141    IValueLookupParameter<IntValue> SamplesEndParameter { get; }
    42     ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter { get; }
    4342  }
    4443}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs

    r3462 r3491  
    4646    private const string SamplesStartParameterName = "SamplesStart";
    4747    private const string SamplesEndParameterName = "SamplesEnd";
    48     private const string NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes";
    4948    #region ISymbolicRegressionEvaluator Members
    5049
     
    7372    }
    7473
    75     public ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter {
    76       get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfEvaluatedNodexParameterName]; }
    77     }
    7874    #endregion
    7975    #region properties
     
    10399      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated."));
    104100      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.)"));
    106101    }
    107102
    108103    public override IOperation Apply() {
    109       DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
    110104      QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset,
    111         RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd, numberOfEvaluatedNodes));
     105        RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd));
    112106      return null;
    113107    }
     
    117111      Dataset dataset,
    118112      StringValue targetVariable,
    119       IntValue samplesStart, IntValue samplesEnd,
    120       DoubleValue numberOfEvaluatedNodes);
     113      IntValue samplesStart, IntValue samplesEnd);
    121114  }
    122115}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs

    r3462 r3491  
    4141  [StorableClass]
    4242  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) {
    4444      double mse = Calculate(interpreter, solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);
    45       numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value);
    4645      return mse;
    4746    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r3480 r3491  
    7373      get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }
    7474    }
    75     public ValueParameter<DoubleValue> NumberOfEvaluatedNodesParameter {
    76       get { return (ValueParameter<DoubleValue>)Parameters["NumberOfEvaluatedNodes"]; }
    77     }
    7875    public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter {
    7976      get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; }
     
    159156      Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", new IntValue(3)));
    160157      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()));
    162158      Parameters.Add(new ValueParameter<ISingleObjectiveSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize symbolic regression solutions.", visualizer));
    163159
     
    323319        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    324320        op.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
    325         op.NumberOfEvaluatedNodesParameter.ActualName = NumberOfEvaluatedNodesParameter.Name;
    326321      }
    327322      foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r3462 r3491  
    3333  [StorableClass]
    3434  [Item("SimpleArithmeticExpressionInterpreter", "Interpreter for arithmetic symbolic expression trees including function calls.")]
     35  // not thread safe!
    3536  public class SimpleArithmeticExpressionInterpreter : Item, ISymbolicExpressionTreeInterpreter {
    3637    private class OpCodes {
     
    4546    }
    4647
     48    private const int ARGUMENT_STACK_SIZE = 1024;
    4749    private Dataset dataset;
    4850    private int row;
     
    5860        this.row = row;
    5961        pc = 0;
    60         argumentStack.Clear();
     62        argStackPointer = 0;
    6163        var estimatedValue = Evaluate();
    6264        if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0;
     
    8587    }
    8688
    87     private Stack<List<double>> argumentStack = new Stack<List<double>>();
     89    private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
     90    private int argStackPointer;
     91
    8892    public double Evaluate() {
    8993      var currentInstr = code[pc++];
     
    118122          }
    119123        case OpCodes.Call: {
    120             // save current arguments
    121             List<double> arguments = new List<double>();
    122124            // evaluate sub-trees
     125            // push on argStack in reverse order
    123126            for (int i = 0; i < currentInstr.nArguments; i++) {
    124               arguments.Add(Evaluate());
     127              argumentStack[argStackPointer + currentInstr.nArguments - i] = Evaluate();
     128              argStackPointer++;
    125129            }
    126             argumentStack.Push(arguments);
     130
    127131            // save the pc
    128132            int nextPc = pc;
     
    131135            // evaluate the function
    132136            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
    134142            // restore the pc => evaluation will continue at point after my subtrees 
    135143            pc = nextPc;
     
    137145          }
    138146        case OpCodes.Arg: {
    139             return argumentStack.Peek()[currentInstr.iArg0];
     147            return argumentStack[argStackPointer - currentInstr.iArg0];
    140148          }
    141149        case OpCodes.Variable: {
Note: See TracChangeset for help on using the changeset viewer.