Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/03/14 17:04:46 (9 years ago)
Author:
bburlacu
Message:

#1772: Merged trunk changes. Updated PhenotypicSimilarityCalculator, updated FragmentGraphView.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisUsefulGenesAnalyzer.cs

    r11462 r11638  
    219219      }
    220220
    221       avgQualityImprovement /= replacedTrees;
    222       avgLengthReduction = (int)Math.Round((double)avgLengthReduction / replacedTrees);
     221      avgQualityImprovement = replacedTrees == 0 ? 0 : avgQualityImprovement / replacedTrees;
     222      avgLengthReduction = replacedTrees == 0 ? 0 : (int)Math.Round((double)avgLengthReduction / replacedTrees);
    223223
    224224      var results = ResultCollectionParameter.ActualValue;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r11208 r11638  
    203203        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    204204        stringBuilder.Append(",0))");
     205      } else if (symbol is IfThenElse) {
     206        stringBuilder.Append("IF(");
     207        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + " ) > 0");
     208        stringBuilder.Append(",");
     209        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     210        stringBuilder.Append(",");
     211        stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
     212        stringBuilder.Append(")");
     213      } else if (symbol is VariableCondition) {
     214        VariableConditionTreeNode variableConditionTreeNode = node as VariableConditionTreeNode;
     215        double threshold = variableConditionTreeNode.Threshold;
     216        double slope = variableConditionTreeNode.Slope;
     217        string p = "(1 / (1 + EXP(-" + slope.ToString(CultureInfo.InvariantCulture) + "* (" + GetColumnToVariableName(variableConditionTreeNode.VariableName) + "-" + threshold.ToString(CultureInfo.InvariantCulture) + "))))";
     218        stringBuilder.Append("INT((");
     219        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     220        stringBuilder.Append("*");
     221        stringBuilder.Append(p);
     222        stringBuilder.Append(") + (");
     223        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     224        stringBuilder.Append("*(");
     225        stringBuilder.Append("1 - " + p + ")");
     226        stringBuilder.Append("))");
     227      } else if (symbol is Xor) {
     228        stringBuilder.Append("IF(");
     229        stringBuilder.Append("XOR(");
     230        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + ") > 0,");
     231        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(1)) + ") > 0");
     232        stringBuilder.Append("), 1.0, -1.0)");
     233      } else if (symbol is Or) {
     234        stringBuilder.Append("IF(");
     235        stringBuilder.Append("OR(");
     236        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + ") > 0,");
     237        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(1)) + ") > 0");
     238        stringBuilder.Append("), 1.0, -1.0)");
     239      } else if (symbol is And) {
     240        stringBuilder.Append("IF(");
     241        stringBuilder.Append("AND(");
     242        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + ") > 0,");
     243        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(1)) + ") > 0");
     244        stringBuilder.Append("), 1.0, -1.0)");
     245      } else if (symbol is Not) {
     246        stringBuilder.Append("IF(");
     247        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     248        stringBuilder.Append(" > 0, -1.0, 1.0)");
     249      } else if (symbol is GreaterThan) {
     250        stringBuilder.Append("IF((");
     251        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     252        stringBuilder.Append(") > (");
     253        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     254        stringBuilder.Append("), 1.0, -1.0)");
     255      } else if (symbol is LessThan) {
     256        stringBuilder.Append("IF((");
     257        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     258        stringBuilder.Append(") < (");
     259        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     260        stringBuilder.Append("), 1.0, -1.0)");
    205261      } else {
    206262        throw new NotImplementedException("Excel export of " + node.Symbol + " is not implemented.");
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11482 r11638  
    1111    <RootNamespace>HeuristicLab.Problems.DataAnalysis.Symbolic</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</AssemblyName>
    13     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    1414    <TargetFrameworkProfile>
    1515    </TargetFrameworkProfile>
     
    4646    <WarningLevel>4</WarningLevel>
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     48    <Prefer32Bit>false</Prefer32Bit>
    4849  </PropertyGroup>
    4950  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    5556    <WarningLevel>4</WarningLevel>
    5657    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     58    <Prefer32Bit>false</Prefer32Bit>
    5759  </PropertyGroup>
    5860  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
     
    6466    <ErrorReport>prompt</ErrorReport>
    6567    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     68    <Prefer32Bit>false</Prefer32Bit>
    6669  </PropertyGroup>
    6770  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
     
    7376    <ErrorReport>prompt</ErrorReport>
    7477    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     78    <Prefer32Bit>false</Prefer32Bit>
    7579  </PropertyGroup>
    7680  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     
    8286    <ErrorReport>prompt</ErrorReport>
    8387    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     88    <Prefer32Bit>false</Prefer32Bit>
    8489  </PropertyGroup>
    8590  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     
    9196    <ErrorReport>prompt</ErrorReport>
    9297    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     98    <Prefer32Bit>false</Prefer32Bit>
    9399  </PropertyGroup>
    94100  <ItemGroup>
     
    194200    </Compile>
    195201    <Compile Include="Analyzers\SymbolicDataAnalysisUsefulGenesAnalyzer.cs" />
     202    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDiversityPreservingCrossover.cs" />
    196203    <Compile Include="Importer\SymbolicExpressionImporter.cs" />
    197204    <Compile Include="Importer\Token.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeNodeComparer.cs

    r10650 r11638  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    324
     
    930  public class SymbolicExpressionTreeNodeComparer : ISymbolicExpressionTreeNodeComparer {
    1031    public int Compare(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    11       if (!(a is SymbolicExpressionTreeTerminalNode)) {
    12         return b is SymbolicExpressionTreeTerminalNode
    13           ? -1
    14           : string.Compare(a.Symbol.Name, b.Symbol.Name, StringComparison.Ordinal);
    15       }
    16       if (!(b is SymbolicExpressionTreeTerminalNode)) return 1;
    17       // at this point we know a and b are terminal nodes
     32      var ta = a as SymbolicExpressionTreeTerminalNode;
     33      var tb = b as SymbolicExpressionTreeTerminalNode;
     34
     35      if (ta == null)
     36        return tb == null ? String.CompareOrdinal(a.Symbol.Name, b.Symbol.Name) : -1;
     37
     38      if (tb == null)
     39        return 1;
     40
     41      // at this point we know a and b are both terminals
    1842      var va = a as VariableTreeNode;
    19       if (va != null) {
    20         if (b is ConstantTreeNode) return -1;
    21         var vb = (VariableTreeNode)b;
    22         return (va.VariableName.Equals(vb.VariableName)
    23           ? va.Weight.CompareTo(vb.Weight)
    24           : string.Compare(va.VariableName, vb.VariableName, StringComparison.Ordinal));
    25       }
    26       // at this point we know for sure that a is a constant tree node
    27       if (b is VariableTreeNode) return 1;
    28       var ca = (ConstantTreeNode)a;
    29       var cb = (ConstantTreeNode)b;
    30       return ca.Value.CompareTo(cb.Value);
     43      var vb = b as VariableTreeNode;
     44
     45      if (va != null)
     46        return vb == null ? -1 : CompareVariables(va, vb);
     47
     48      if (vb != null)
     49        return 1;
     50
     51      // at this point we know a and b are not variables
     52      var ca = a as ConstantTreeNode;
     53      var cb = b as ConstantTreeNode;
     54
     55      if (ca != null && cb != null)
     56        return ca.Value.CompareTo(cb.Value);
     57
     58      // for other unknown terminal types, compare strings
     59      return string.CompareOrdinal(a.ToString(), b.ToString());
     60    }
     61
     62    private static int CompareVariables(VariableTreeNode a, VariableTreeNode b) {
     63      int result = string.CompareOrdinal(a.VariableName, b.VariableName);
     64      return result == 0 ? a.Weight.CompareTo(b.Weight) : result;
    3165    }
    3266  }
     67
    3368}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculatorsmergedeligible
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5471-5473
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5815-6180
      /branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10598
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10085-11101
      /branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators9511-9585
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5060
      /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10331-10358
      /branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators9271-9826
      /branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators7098-8789
      /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators8388-8942
      /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5138-5162
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators6828
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators6829-6865
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators5959-6341
      /stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10032-10033,​11170,​11173
      /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators10269-11210
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpSimilarityCalculator.cs

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/PhenotypicSimilarityCalculator.cs

    r11458 r11638  
    3131  [StorableClass]
    3232  public class PhenotypicSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {
     33    public IDataAnalysisProblemData ProblemData { get; set; }
     34    public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get; set; }
     35
    3336    public PhenotypicSimilarityCalculator(PhenotypicSimilarityCalculator original, Cloner cloner)
    3437      : base(original, cloner) {
     
    4548
    4649    public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
    47       throw new System.NotImplementedException();
     50      var v1 = Interpreter.GetSymbolicExpressionTreeValues(t1, ProblemData.Dataset, ProblemData.TrainingIndices);
     51      var v2 = Interpreter.GetSymbolicExpressionTreeValues(t2, ProblemData.Dataset, ProblemData.TrainingIndices);
     52
     53      OnlineCalculatorError error;
     54      var r2 = OnlinePearsonsRSquaredCalculator.Calculate(v1, v2, out error);
     55
     56      if (r2 > 1.0)
     57        r2 = 1.0;
     58
     59      return error == OnlineCalculatorError.None ? r2 : 0;
    4860    }
    4961
     
    5769        r2 = 1.0; // sometimes due to fp errors it can happen that the r2 is over 1 (like 1.0000000009)
    5870
    59       return error != OnlineCalculatorError.None ? 0 : r2;
     71      return error == OnlineCalculatorError.None ? r2 : 0;
    6072    }
    6173  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r11503 r11638  
    9090        var fragment = (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data;
    9191        if (fragment == null) {
     92          //          if (parents.Count == 2)
     93          //            throw new Exception("There should always be a crossover fragment.");
    9294          // the node is either an elite node or (in rare cases) no fragment was transferred
    9395          g = parents[0];
Note: See TracChangeset for help on using the changeset viewer.