Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/PhenotypicSimilarityCalculator.cs @ 11271

Last change on this file since 11271 was 11271, checked in by bburlacu, 10 years ago

#1772: Added specialized diversity analyzers (phenotypic and bottom-up) and phenotypic similarity calculator.

File size: 1.5 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Optimization.Operators;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
8  [Item("PhenotypicSimilarityCalculator", "An operator that calculates the similarity betweeon two trees based on the correlation of their outputs.")]
9  [StorableClass]
10  public class PhenotypicSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
11    public PhenotypicSimilarityCalculator(PhenotypicSimilarityCalculator original, Cloner cloner)
12      : base(original, cloner) {
13    }
14
15    public PhenotypicSimilarityCalculator() { }
16
17    [StorableConstructor]
18    protected PhenotypicSimilarityCalculator(bool deserializing) : base(deserializing) { }
19
20    public override IDeepCloneable Clone(Cloner cloner) {
21      return new PhenotypicSimilarityCalculator(this, cloner);
22    }
23
24    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
25      var leftValues = (DoubleArray)leftSolution.Variables["EstimatedValues"].Value;
26      var rightValues = (DoubleArray)rightSolution.Variables["EstimatedValues"].Value;
27      OnlineCalculatorError error;
28      var r2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error);
29
30      if (r2 > 1.0)
31        r2 = 1.0; // sometimes due to fp errors it can happen that the r2 is over 1 (like 1.0000000009)
32
33      return error != OnlineCalculatorError.None ? 0 : r2;
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.