Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11861


Ignore:
Timestamp:
02/02/15 16:14:45 (9 years ago)
Author:
mkommend
Message:

#2175: Merged trunk changes.

Location:
branches/DataAnalysis.ComplexityAnalyzer
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r11407 r11861  
    1111    <RootNamespace>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-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>
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r11310 r11861  
    155155      eval: Math.Tan,
    156156      diff: x => 1 + Math.Tan(x) * Math.Tan(x));
    157     private static readonly Func<Term, UnaryFunc> square = UnaryFunc.Factory(
    158        eval: x => x * x,
    159        diff: x => 2 * x);
    160157    private static readonly Func<Term, UnaryFunc> erf = UnaryFunc.Factory(
    161158      eval: alglib.errorfunction,
     
    378375          return true;
    379376        }
     377      }
     378      if (node.Symbol is Square) {
     379        AutoDiff.Term t;
     380        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
     381          term = null;
     382          return false;
     383        } else {
     384          term = AutoDiff.TermBuilder.Power(t, 2.0);
     385          return true;
     386        }
     387      } if (node.Symbol is SquareRoot) {
     388        AutoDiff.Term t;
     389        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
     390          term = null;
     391          return false;
     392        } else {
     393          term = AutoDiff.TermBuilder.Power(t, 0.5);
     394          return true;
     395        }
    380396      } if (node.Symbol is Sine) {
    381397        AutoDiff.Term t;
     
    403419        } else {
    404420          term = tan(t);
    405           return true;
    406         }
    407       }
    408       if (node.Symbol is Square) {
    409         AutoDiff.Term t;
    410         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    411           term = null;
    412           return false;
    413         } else {
    414           term = square(t);
    415421          return true;
    416422        }
     
    464470         !(n.Symbol is Logarithm) &&
    465471         !(n.Symbol is Exponential) &&
     472         !(n.Symbol is SquareRoot) &&
     473         !(n.Symbol is Square) &&
    466474         !(n.Symbol is Sine) &&
    467475         !(n.Symbol is Cosine) &&
    468476         !(n.Symbol is Tangent) &&
    469          !(n.Symbol is Square) &&
    470477         !(n.Symbol is Erf) &&
    471478         !(n.Symbol is Norm) &&
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r11310 r11861  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2627using HeuristicLab.Optimization;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    107108    public SymbolicRegressionSolution(ISymbolicRegressionModel model, IRegressionProblemData problemData)
    108109      : base(model, problemData) {
     110      foreach (var node in model.SymbolicExpressionTree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTopLevelNode>())
     111        node.SetGrammar(null);
     112
    109113      Add(new Result(ModelLengthResultName, "Length of the symbolic regression model.", new IntValue()));
    110114      Add(new Result(ModelDepthResultName, "Depth of the symbolic regression model.", new IntValue()));
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisModelComplexityAnalyzer.cs

    r11407 r11861  
    5252            double complexity = 1;
    5353            for (int i = 0; i < node.SubtreeCount; i++) {
    54               complexity *= CalculateComplexity(node.GetSubtree(i));
     54              var nodeComplexity = CalculateComplexity(node.GetSubtree(i));
     55              complexity *=  nodeComplexity > 2 ? nodeComplexity : 2;
     56             
    5557            }
    5658            return complexity == 1 ? node.SubtreeCount : complexity;
     
    5961            double complexity = 1;
    6062            for (int i = 0; i < node.SubtreeCount; i++) {
    61               complexity *= CalculateComplexity(node.GetSubtree(i));
     63              var nodeComplexity = CalculateComplexity(node.GetSubtree(i));
     64              complexity *= nodeComplexity > 2 ? nodeComplexity : 2;
    6265            }
    63             return complexity;
     66            return complexity == 1 ? node.SubtreeCount : complexity;
    6467          }
    6568        case OpCodes.Sin: {
    6669            double complexity = CalculateComplexity(node.GetSubtree(0));
    67             return complexity * 10;
     70            return Math.Exp(complexity);
    6871          }
    6972        case OpCodes.Cos: {
    7073            double complexity = CalculateComplexity(node.GetSubtree(0));
    71             return complexity * 10;
     74            return Math.Exp(complexity);
    7275          }
    7376        case OpCodes.Tan: {
    7477            double complexity = CalculateComplexity(node.GetSubtree(0));
    75             return complexity * 10;
     78            return Math.Exp(complexity);
    7679          }
    7780        case OpCodes.Exp: {
    7881            double complexity = CalculateComplexity(node.GetSubtree(0));
    79             return complexity * 10;
    80           }
     82          return Math.Exp(complexity);
     83        }
    8184        case OpCodes.Log: {
    8285            double complexity = CalculateComplexity(node.GetSubtree(0));
    83             return complexity * 10;
     86            return Math.Exp(complexity);
    8487          }
    8588        case OpCodes.Square: {
    8689            double complexity = CalculateComplexity(node.GetSubtree(0));
    87             return 2 * complexity;
     90            return complexity * complexity;
    8891          }
    8992        case OpCodes.SquareRoot: {
    9093            double complexity = CalculateComplexity(node.GetSubtree(0));
    91             return 10 * complexity;
     94            return complexity * complexity * complexity;
    9295          }
    9396        case OpCodes.Power: {
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs

    r11310 r11861  
    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/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r11310 r11861  
    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/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11310 r11861  
    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>
     
    191197      <SubType>Code</SubType>
    192198    </Compile>
     199    <Compile Include="Importer\SymbolicExpressionImporter.cs" />
     200    <Compile Include="Importer\Token.cs" />
    193201    <Compile Include="Interfaces\IModelBacktransformator.cs" />
    194202    <Compile Include="Matching\SymbolicExpressionTreeCanonicalSorter.cs" />
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMatching.cs

    r10562 r11861  
    1 using System;
     1#region License Information
     2
     3/* HeuristicLab
     4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     5 *
     6 * This file is part of HeuristicLab.
     7 *
     8 * HeuristicLab is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * HeuristicLab is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
     22#endregion
     23
     24using System;
    225using System.Collections.Generic;
    326using System.Linq;
     
    4568      return matrix[m, n] + 1;
    4669    }
     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    }
    47124  }
    48125}
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r11310 r11861  
    949949    private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) {
    950950      var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees);
     951      prod.
    951952      while (prod.Subtrees.Count() > 0) prod.RemoveSubtree(0);
    952953      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
Note: See TracChangeset for help on using the changeset viewer.