Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5742


Ignore:
Timestamp:
03/17/11 21:40:31 (14 years ago)
Author:
gkronber
Message:

#1418 fixed grammar cloning bug, improved analyzers for multi objective symbolic data analysis problems.

Location:
branches/DataAnalysis Refactoring
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs

    r5695 r5742  
    2121
    2222using HeuristicLab.Common;
     23using System.Linq;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using System.Collections.Generic;
    2426
    2527namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    104106      startSymbol = (StartSymbol)cloner.Clone(original.StartSymbol);
    105107      defunSymbol = (Defun)cloner.Clone(original.defunSymbol);
     108      symbols = original.symbols
     109        .ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value));
    106110      maximumFunctionArguments = original.maximumFunctionArguments;
    107111      minimumFunctionArguments = original.minimumFunctionArguments;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r5733 r5742  
    6666      Parameters.Add(new FixedValueParameter<DoubleValue>(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue()));
    6767
    68       Maximization = new BoolArray(new bool[] { false, false });
     68      Maximization = new BoolArray(new bool[] { true, false });
    6969      MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
    7070      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r5722 r5742  
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using System.Linq;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    5455      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5556      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    56       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    57       return OnlinePearsonsRSquaredEvaluator.Calculate(originalValues, boundedEstimatedValues);
     57      return OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues);
    5858    }
    5959
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r5607 r5742  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using System;
    3233
    3334namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    9596        if (IsNonDominated(qualities[i], trainingBestQualities, maximization) &&
    9697          IsNonDominated(qualities[i], qualities, maximization)) {
    97           newNonDominatedQualities.Add(qualities[i]);
    98           nonDominatedIndexes.Add(i);
     98          if (!newNonDominatedQualities.Contains(qualities[i], new DoubleArrayComparer())) {
     99            newNonDominatedQualities.Add(qualities[i]);
     100            nonDominatedIndexes.Add(i);
     101          }
    99102        }
    100103      }
     
    113116        for (int i = 0; i < trainingBestQualities.Count; i++) {
    114117          if (IsNonDominated(trainingBestQualities[i], newNonDominatedQualities, maximization)) {
    115             nonDominatedSolutions.Add(TrainingBestSolutions[i]);
    116             nonDominatedQualities.Add(TrainingBestSolutionQualities[i]);
     118            if (!newNonDominatedQualities.Contains(trainingBestQualities[i], new DoubleArrayComparer())) {
     119              nonDominatedSolutions.Add(TrainingBestSolutions[i]);
     120              nonDominatedQualities.Add(TrainingBestSolutionQualities[i]);
     121            }
    117122          }
    118123        }
     
    125130    }
    126131
     132    private class DoubleArrayComparer : IEqualityComparer<double[]> {
     133      public bool Equals(double[] x, double[] y) {
     134        if (y.Length != x.Length) throw new ArgumentException();
     135        for (int i = 0; i < x.Length;i++ ) {
     136          if (!x[i].IsAlmost(y[i])) return false;
     137        }
     138        return true;
     139      }
     140
     141      public int GetHashCode(double[] obj) {
     142        int c = obj.Length;
     143        for (int i = 0; i < obj.Length; i++)
     144          c ^= obj[i].GetHashCode();
     145        return c;
     146      }
     147    }
     148
    127149    protected abstract T CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality);
    128150
     
    131153        bool refPointDominatesPoint = true;
    132154        for (int i = 0; i < point.Length; i++) {
    133           refPointDominatesPoint &= IsBetter(refPoint[i], point[i], maximization[i]);
     155          refPointDominatesPoint &= IsBetterOrEqual(refPoint[i], point[i], maximization[i]);
    134156        }
    135157        if (refPointDominatesPoint) return false;
     
    137159      return true;
    138160    }
    139     private bool IsBetter(double lhs, double rhs, bool maximization) {
     161    private bool IsBetterOrEqual(double lhs, double rhs, bool maximization) {
    140162      if (maximization) return lhs > rhs;
    141163      else return lhs < rhs;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs

    r5722 r5742  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using System;
    3233
    3334namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    120121        if (IsNonDominated(qualities[i], trainingBestQualities, maximization) &&
    121122          IsNonDominated(qualities[i], qualities, maximization)) {
    122           newNonDominatedQualities.Add(qualities[i]);
    123           nonDominatedIndexes.Add(i);
     123          if (!newNonDominatedQualities.Contains(qualities[i], new DoubleArrayComparer())) {
     124            newNonDominatedQualities.Add(qualities[i]);
     125            nonDominatedIndexes.Add(i);
     126          }
    124127        }
    125128      }
     
    138141        for (int i = 0; i < trainingBestQualities.Count; i++) {
    139142          if (IsNonDominated(trainingBestQualities[i], newNonDominatedQualities, maximization)) {
    140             nonDominatedSolutions.Add(ValidationBestSolutions[i]);
    141             nonDominatedQualities.Add(ValidationBestSolutionQualities[i]);
     143            if (!newNonDominatedQualities.Contains(trainingBestQualities[i], new DoubleArrayComparer())) {
     144              nonDominatedSolutions.Add(ValidationBestSolutions[i]);
     145              nonDominatedQualities.Add(ValidationBestSolutionQualities[i]);
     146            }
    142147          }
    143148        }
     
    166171      else return lhs < rhs;
    167172    }
     173
     174    private class DoubleArrayComparer : IEqualityComparer<double[]> {
     175      public bool Equals(double[] x, double[] y) {
     176        if (y.Length != x.Length) throw new ArgumentException();
     177        for (int i = 0; i < x.Length; i++) {
     178          if (!x[i].IsAlmost(y[i])) return false;
     179        }
     180        return true;
     181      }
     182
     183      public int GetHashCode(double[] obj) {
     184        int c = obj.Length;
     185        for (int i = 0; i < obj.Length; i++)
     186          c ^= obj[i].GetHashCode();
     187        return c;
     188      }
     189    }
     190
    168191  }
    169192}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineCovarianceEvaluator.cs

    r5564 r5742  
    3030    public double Covariance {
    3131      get {
    32         if (n < 1)
    33           throw new InvalidOperationException("No elements");
    34         else
    35           return Cn / n;
     32        return n > 0 ? Cn / n : 0.0;
    3633      }
    3734    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAbsolutePercentageErrorEvaluator.cs

    r5564 r5742  
    3131    public double MeanAbsolutePercentageError {
    3232      get {
    33         if (n < 1)
    34           throw new InvalidOperationException("No elements");
    35         else
    36           return sre / n;
     33        return n > 0 ? sre / n : 0.0;
    3734      }
    3835    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredEvaluator.cs

    r5564 r5742  
    6666    #endregion
    6767
    68     private bool IsInvalidValue(double x) {
     68    private static bool IsInvalidValue(double x) {
    6969      return double.IsNaN(x) || double.IsInfinity(x);
    7070    }
     
    7979        double estimated = secondEnumerator.Current;
    8080        double original = firstEnumerator.Current;
    81         rSquaredEvaluator.Add(original, estimated);
     81        if (!IsInvalidValue(estimated) && !IsInvalidValue(original))
     82          rSquaredEvaluator.Add(original, estimated);
    8283      }
    8384
Note: See TracChangeset for help on using the changeset viewer.