Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/20/21 18:13:55 (3 years ago)
Author:
dpiringe
Message:

#3026

  • merged trunk into branch
Location:
branches/3026_IntegrationIntoSymSpace
Files:
1 deleted
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs

    r17928 r18027  
    784784      } else if (IsExp(node)) {
    785785        return MakeExp(MakeProduct(node.GetSubtree(0), MakeConstant(2.0))); // sqr(exp(x)) = exp(2x)
     786      } else if (IsSquare(node)) {
     787        return MakePower(node.GetSubtree(0), MakeConstant(4));
    786788      } else if (IsCube(node)) {
    787789        return MakePower(node.GetSubtree(0), MakeConstant(6));
     
    809811      } else if (IsSquare(node)) {
    810812        return MakePower(node.GetSubtree(0), MakeConstant(6));
     813      } else if (IsCube(node)) {
     814        return MakePower(node.GetSubtree(0), MakeConstant(9));
    811815      } else {
    812816        var cubeNode = cubeSymbol.CreateTreeNode();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionPythonFormatter.cs

    r17928 r18027  
    5858    }
    5959
    60     private string GenerateHeader(ISymbolicExpressionTree symbolicExpressionTree) {
     60    private static string GenerateHeader(ISymbolicExpressionTree symbolicExpressionTree) {
    6161      StringBuilder strBuilder = new StringBuilder();
    6262
     
    102102    }
    103103
    104     private string GenerateNecessaryImports(int mathLibCounter, int statisticLibCounter) {
     104    private static string GenerateNecessaryImports(int mathLibCounter, int statisticLibCounter) {
    105105      StringBuilder strBuilder = new StringBuilder();
    106106      if (mathLibCounter > 0 || statisticLibCounter > 0) {
     
    115115    }
    116116
    117     private string GenerateIfThenElseSource(int evaluateIfCounter) {
     117    private static string GenerateIfThenElseSource(int evaluateIfCounter) {
    118118      StringBuilder strBuilder = new StringBuilder();
    119119      if (evaluateIfCounter > 0) {
     
    128128    }
    129129
    130     private string GenerateModelEvaluationFunction(ISet<string> variables) {
     130    private static string GenerateModelEvaluationFunction(ISet<string> variables) {
    131131      StringBuilder strBuilder = new StringBuilder();
    132132      strBuilder.Append("def evaluate(");
     
    142142    }
    143143
    144     private void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     144    private static void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    145145      ISymbol symbol = node.Symbol;
    146146      if (symbol is ProgramRootSymbol)
     
    208208    }
    209209
    210     private string VariableName2Identifier(string variableName) => variableName.Replace(" ", "_");
    211 
    212     private void FormatNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string prefixSymbol = "", string openingSymbol = "(", string closingSymbol = ")", string infixSymbol = ",") {
     210    private static string VariableName2Identifier(string variableName) => variableName.Replace(" ", "_");
     211
     212    private static void FormatNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string prefixSymbol = "", string openingSymbol = "(", string closingSymbol = ")", string infixSymbol = ",") {
    213213      strBuilder.Append($"{prefixSymbol}{openingSymbol}");
    214214      foreach (var child in node.Subtrees) {
     
    220220    }
    221221
    222     private void FormatVariableTreeNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     222    private static void FormatVariableTreeNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    223223      var varNode = node as VariableTreeNode;
    224224      var formattedVariable = VariableName2Identifier(varNode.VariableName);
     
    227227    }
    228228
    229     private void FormatConstantTreeNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     229    private static void FormatConstantTreeNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    230230      var constNode = node as ConstantTreeNode;
    231231      strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
    232232    }
    233233
    234     private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
     234    private static void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
    235235      strBuilder.Append("math.pow(");
    236236      FormatRecursively(node.GetSubtree(0), strBuilder);
     
    238238    }
    239239
    240     private void FormatRoot(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     240    private static void FormatRoot(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    241241      strBuilder.Append("math.pow(");
    242242      FormatRecursively(node.GetSubtree(0), strBuilder);
     
    246246    }
    247247
    248     private void FormatSubtraction(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     248    private static void FormatSubtraction(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    249249      if (node.SubtreeCount == 1) {
    250250        strBuilder.Append("-");
     
    256256    }
    257257
    258     private void FormatDivision(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     258    private static void FormatDivision(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    259259      strBuilder.Append("(");
    260260      if (node.SubtreeCount == 1) {
     
    273273    }
    274274
    275     private void FormatAnalyticQuotient(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     275    private static void FormatAnalyticQuotient(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    276276      strBuilder.Append("(");
    277277      FormatRecursively(node.GetSubtree(0), strBuilder);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17928 r18027  
    9999  </PropertyGroup>
    100100  <ItemGroup>
    101     <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    102       <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath>
     101    <Reference Include="ALGLIB-3.17.0, Version=3.17.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     102      <SpecificVersion>False</SpecificVersion>
     103      <HintPath>..\..\bin\ALGLIB-3.17.0.dll</HintPath>
    103104      <Private>False</Private>
    104105    </Reference>
     
    158159    <Compile Include="Formatters\SymbolicDataAnalysisExpressionCSharpFormatter.cs" />
    159160    <Compile Include="Grammars\DataAnalysisGrammar.cs" />
    160     <Compile Include="Grammars\IntervalArithmeticGrammar.cs" />
     161    <Compile Include="Grammars\LinearScalingGrammar.cs" />
    161162    <Compile Include="Hashing\HashExtensions.cs" />
    162163    <Compile Include="Hashing\HashUtil.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs

    r17928 r18027  
    223223            break;
    224224          }
     225        case OpCodes.Power: {
     226          var a = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     227          var b = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     228          // support only integer powers
     229          if (b.LowerBound == b.UpperBound && Math.Truncate(b.LowerBound) == b.LowerBound) {
     230            result = Interval.Power(a, (int)b.LowerBound);
     231          } else {
     232            throw new NotSupportedException("Interval is only supported for integer powers");
     233          }
     234          break;
     235        }
    225236        case OpCodes.Absolute: {
    226237            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     
    329340          !(n.Symbol is Cube) &&
    330341          !(n.Symbol is CubeRoot) &&
     342          !(n.Symbol is Power) &&
    331343          !(n.Symbol is Absolute) &&
    332344          !(n.Symbol is AnalyticQuotient)
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17928 r18027  
    283283            break;
    284284          }
     285        case OpCodes.Power: {
     286            var a = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     287            var b = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     288            // support only integer powers
     289            if (b.LowerBound == b.UpperBound && Math.Truncate(b.LowerBound) == b.LowerBound) {
     290              result = Interval.Power(a, (int)b.LowerBound);
     291            } else {
     292              throw new NotSupportedException("Interval is only supported for integer powers");
     293            }
     294            break;
     295          }
     296
    285297        case OpCodes.Absolute: {
    286298            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     
    309321
    310322    public static bool IsCompatible(ISymbolicExpressionTree tree) {
    311       var containsUnknownSymbols = (
    312         from n in tree.Root.GetSubtree(0).IterateNodesPrefix()
    313         where
     323      foreach (var n in tree.Root.GetSubtree(0).IterateNodesPrefix()) {
     324        if (
    314325          !(n.Symbol is Variable) &&
    315326          !(n.Symbol is Constant) &&
     
    329340          !(n.Symbol is Cube) &&
    330341          !(n.Symbol is CubeRoot) &&
     342          !(n.Symbol is Power) &&
    331343          !(n.Symbol is Absolute) &&
    332           !(n.Symbol is AnalyticQuotient)
    333         select n).Any();
    334       return !containsUnknownSymbols;
     344          !(n.Symbol is AnalyticQuotient)) return false;
     345
     346        else if (n.Symbol is Power) {
     347          // only integer exponents are supported
     348          var exp = n.GetSubtree(1) as ConstantTreeNode;
     349          if (exp == null || exp.Value != Math.Truncate(exp.Value)) return false;
     350        }
     351      }
     352      return true;
    335353    }
    336354  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r17180 r18027  
    144144      { typeof(Cosine), OpCodes.Cos },
    145145      { typeof(Tangent), OpCodes.Tan },
    146       { typeof (HyperbolicTangent), OpCodes.Tanh},
     146      { typeof(HyperbolicTangent), OpCodes.Tanh},
    147147      { typeof(Logarithm), OpCodes.Log },
    148148      { typeof(Exponential), OpCodes.Exp },
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame

    r17184 r18027  
    2828  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.12.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.17.0")]
    3131  [PluginDependency("HeuristicLab.AutoDiff", "1.0")]
    3232  [PluginDependency("HeuristicLab.Analysis", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.