Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/15 14:51:00 (9 years ago)
Author:
mkommend
Message:

#2215: Merged trunk changes into bottom up similarity calculator branch.

Location:
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
5 edited
1 copied

Legend:

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

  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs

    r11171 r11887  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3637  [StorableClass]
    3738  public abstract class SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<T, U> : SymbolicDataAnalysisSingleObjectiveAnalyzer,
    38     ISymbolicDataAnalysisValidationAnalyzer<T, U>
     39    ISymbolicDataAnalysisValidationAnalyzer<T, U>, IStochasticOperator
    3940    where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U>
    4041    where U : class, IDataAnalysisProblemData {
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r11171 r11887  
    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("((");
     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.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11486 r11887  
    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>
     
    212218      <SubType>Code</SubType>
    213219    </Compile>
     220    <Compile Include="Importer\SymbolicExpressionImporter.cs" />
     221    <Compile Include="Importer\Token.cs" />
    214222    <Compile Include="Interfaces\IModelBacktransformator.cs" />
    215223    <Compile Include="Matching\SymbolicExpressionTreeCanonicalSorter.cs" />
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMatching.cs

    r11239 r11887  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022#endregion
    2123
     
    6668      return matrix[m, n] + 1;
    6769    }
     70
     71    /// <summary>
     72    /// Calculates the difference between two symbolic expression trees.
     73    /// </summary>
     74    /// <param name="tree">The first symbolic expression tree</param>
     75    /// <param name="other">The second symbolic expression tree</param>
     76    /// <returns>Returns the root of the subtree (from T1) by which T1 differs from T2, or null if no difference is found.</returns>
     77    public static ISymbolicExpressionTreeNode Difference(this ISymbolicExpressionTree tree, ISymbolicExpressionTree other) {
     78      return Difference(tree.Root, other.Root);
     79    }
     80
     81    public static ISymbolicExpressionTreeNode Difference(this ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode other) {
     82      var a = node.IterateNodesPrefix().ToList();
     83      var b = other.IterateNodesPrefix().ToList();
     84      var list = new List<ISymbolicExpressionTreeNode>();
     85      for (int i = 0, j = 0; i < a.Count && j < b.Count; ++i, ++j) {
     86        var s1 = a[i].ToString();
     87        var s2 = b[j].ToString();
     88        if (s1 == s2) continue;
     89        list.Add(a[i]);
     90        // skip subtrees since the parents are already different
     91        i += a[i].SubtreeCount;
     92        j += b[j].SubtreeCount;
     93      }
     94      ISymbolicExpressionTreeNode result = list.Count > 0 ? LowestCommonAncestor(node, list) : null;
     95      return result;
     96    }
     97
     98    private static ISymbolicExpressionTreeNode LowestCommonAncestor(ISymbolicExpressionTreeNode root, List<ISymbolicExpressionTreeNode> nodes) {
     99      if (nodes.Count == 0)
     100        throw new ArgumentException("The nodes list should contain at least one element.");
     101
     102      if (nodes.Count == 1)
     103        return nodes[0];
     104
     105      int minLevel = nodes.Min(x => root.GetBranchLevel(x));
     106
     107      // bring the nodes in the nodes to the same level (relative to the root)
     108      for (int i = 0; i < nodes.Count; ++i) {
     109        var node = nodes[i];
     110        var level = root.GetBranchLevel(node);
     111        for (int j = minLevel; j < level; ++j)
     112          node = node.Parent;
     113        nodes[i] = node;
     114      }
     115
     116      // while not all the elements in the nodes are equal, go one level up
     117      while (nodes.Any(x => x != nodes[0])) {
     118        for (int i = 0; i < nodes.Count; ++i)
     119          nodes[i] = nodes[i].Parent;
     120      }
     121
     122      return nodes[0];
     123    }
    68124  }
    69125}
Note: See TracChangeset for help on using the changeset viewer.