Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2722


Ignore:
Timestamp:
01/29/10 15:22:18 (15 years ago)
Author:
gkronber
Message:

Added a special predictor builder for linear scaling tree evaluation and changed default GP engines to use linear scaling evaluators. #823.

Location:
trunk/sources
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/OffspringSelectionGPTimeSeriesPrognosis.cs

    r2577 r2722  
    5656      funLibInjector.GetVariable("Differentials").Value = new BoolData(true);
    5757      seq.AddSubOperator(funLibInjector);
    58       seq.AddSubOperator(new HL3TreeEvaluatorInjector());
     58      seq.AddSubOperator(new ScalingTreeEvaluatorInjector());
    5959      op.OperatorGraph.AddOperator(seq);
    6060      op.OperatorGraph.InitialOperator = seq;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/StandardGPTimeSeriesPrognosis.cs

    r2577 r2722  
    5656      funLibInjector.GetVariable("Differentials").Value = new BoolData(true);
    5757      seq.AddSubOperator(funLibInjector);
    58       seq.AddSubOperator(new HL3TreeEvaluatorInjector());
     58      seq.AddSubOperator(new ScalingTreeEvaluatorInjector());
    5959      op.OperatorGraph.AddOperator(seq);
    6060      op.OperatorGraph.InitialOperator = seq;
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs

    r2683 r2722  
    3939      SequentialProcessor seq = new SequentialProcessor();
    4040      seq.AddSubOperator(new DefaultFunctionLibraryInjector());
    41       seq.AddSubOperator(new HL3TreeEvaluatorInjector());
     41      seq.AddSubOperator(new ScalingTreeEvaluatorInjector());
    4242      op.OperatorGraph.AddOperator(seq);
    4343      op.OperatorGraph.InitialOperator = seq;
     
    127127      seqSubScopeProc.AddSubOperator(solutionProc);
    128128
    129       HL3TreeEvaluatorInjector evaluatorInjector = new HL3TreeEvaluatorInjector();
     129      ScalingTreeEvaluatorInjector evaluatorInjector = new ScalingTreeEvaluatorInjector();
    130130      evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
    131131      evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     
    160160      VariableNamesExtractor namesExtractor = new VariableNamesExtractor();
    161161      namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames";
    162       PredictorBuilder predictorBuilder = new PredictorBuilder();
    163       predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     162      LinearScalingPredictorBuilder predictorBuilder = new LinearScalingPredictorBuilder();
    164163
    165164      solutionProc.AddSubOperator(namesExtractor);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj

    r2682 r2722  
    8585    <Compile Include="BaseClasses\FunctionTreeBase.cs" />
    8686    <Compile Include="BaseClasses\TreeEvaluatorBase.cs" />
     87    <Compile Include="LinearScalingPredictorBuilder.cs" />
    8788    <Compile Include="Evaluators\VariableFrequencyBasedImpactCalculator.cs" />
    8889    <Compile Include="ScalingTreeEvaluator.cs" />
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Predictor.cs

    r2619 r2722  
    5252
    5353    public override IEnumerable<double> Predict(Dataset input, int start, int end) {
     54      if (input == null) throw new ArgumentNullException();
     55      if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end");
     56      if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end");
    5457      treeEvaluator.UpperEvaluationLimit = UpperPredictionLimit;
    5558      treeEvaluator.LowerEvaluationLimit = LowerPredictionLimit;
    5659
    57       if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end");
    58       if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end");
    5960      return treeEvaluator.Evaluate(input, functionTree.FunctionTree, Enumerable.Range(start, end - start));
    6061    }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ScalingTreeEvaluator.cs

    r2640 r2722  
    5151      this.sampleIndex = sampleIndex;
    5252      double estimation = EvaluateBakedCode();
    53       if (double.IsPositiveInfinity(estimation)) estimation = UpperEvaluationLimit;
    54       else if (double.IsNegativeInfinity(estimation)) estimation = LowerEvaluationLimit;
    55       else if (double.IsNaN(estimation)) estimation = UpperEvaluationLimit;
     53      //if (double.IsPositiveInfinity(estimation)) estimation = UpperEvaluationLimit;
     54      //else if (double.IsNegativeInfinity(estimation)) estimation = LowerEvaluationLimit;
     55      //else if (double.IsNaN(estimation)) estimation = UpperEvaluationLimit;
    5656      return estimation;
    5757    }
    5858
    5959    public override IEnumerable<double> Evaluate(Dataset dataset, IFunctionTree tree, IEnumerable<int> rows) {
    60       double[] result = base.Evaluate(dataset, tree, rows).ToArray();
    6160      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    62       double tMean = dataset.GetMean(targetVariableIndex);
    63       double xMean = Statistics.Mean(result);
    64       double sumXT = 0;
    65       double sumXX = 0;
    66       for (int i = 0; i < result.Length; i++) {
    67         double x = result[i];
    68         double t = dataset.GetValue(rows.ElementAt(i), targetVariableIndex);
    69         sumXT += (x - xMean) * (t - tMean);
    70         sumXX += (x - xMean) * (x - xMean);
     61      // evaluate for all rows
     62      PrepareForEvaluation(dataset, tree);
     63      var result = (from row in rows
     64                    let y = Evaluate(row)
     65                    let y_ = dataset.GetValue(row, targetVariableIndex)
     66                    select new { Row = row, Estimation = y, Target = y_ }).ToArray();
     67
     68      // calculate alpha and beta on the subset of rows with valid values
     69      var filteredResult = result.Where(x => IsValidValue(x.Target) && IsValidValue(x.Estimation));
     70      var target = filteredResult.Select(x => x.Target);
     71      var estimation = filteredResult.Select(x => x.Estimation);
     72      double a, b;
     73      if (filteredResult.Count() > 2) {
     74        double tMean = target.Sum() / target.Count();
     75        double xMean = estimation.Sum() / estimation.Count();
     76        double sumXT = 0;
     77        double sumXX = 0;
     78        foreach (var r in result) {
     79          double x = r.Estimation;
     80          double t = r.Target;
     81          sumXT += (x - xMean) * (t - tMean);
     82          sumXX += (x - xMean) * (x - xMean);
     83        }
     84        b = sumXT / sumXX;
     85        a = tMean - b * xMean;
     86      } else {
     87        b = 1.0;
     88        a = 0.0;
    7189      }
    72       double b = sumXT / sumXX;
    73       double a = tMean - b * xMean;
    74       for (int i = 0; i < result.Length; i++) {
    75         double scaledResult = result[i] * b + a;
    76         scaledResult = Math.Min(Math.Max(scaledResult, LowerEvaluationLimit), UpperEvaluationLimit);
    77         if (double.IsNaN(scaledResult)) scaledResult = UpperEvaluationLimit;
    78         result[i] = scaledResult;
    79       }
    80       return result;
     90      // return scaled results
     91      return from r in result
     92             let scaledR = Math.Min(Math.Max(r.Estimation * b + a, LowerEvaluationLimit), UpperEvaluationLimit)
     93             select double.IsNaN(scaledR) ? UpperEvaluationLimit : scaledR;
     94    }
     95
     96    private bool IsValidValue(double d) {
     97      return !double.IsInfinity(d) && !double.IsNaN(d);
    8198    }
    8299
Note: See TracChangeset for help on using the changeset viewer.