Changeset 11861 for branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 02/02/15 16:14:45 (10 years ago)
- Location:
- branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisModelComplexityAnalyzer.cs
r11407 r11861 52 52 double complexity = 1; 53 53 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 55 57 } 56 58 return complexity == 1 ? node.SubtreeCount : complexity; … … 59 61 double complexity = 1; 60 62 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; 62 65 } 63 return complexity ;66 return complexity == 1 ? node.SubtreeCount : complexity; 64 67 } 65 68 case OpCodes.Sin: { 66 69 double complexity = CalculateComplexity(node.GetSubtree(0)); 67 return complexity * 10;70 return Math.Exp(complexity); 68 71 } 69 72 case OpCodes.Cos: { 70 73 double complexity = CalculateComplexity(node.GetSubtree(0)); 71 return complexity * 10;74 return Math.Exp(complexity); 72 75 } 73 76 case OpCodes.Tan: { 74 77 double complexity = CalculateComplexity(node.GetSubtree(0)); 75 return complexity * 10;78 return Math.Exp(complexity); 76 79 } 77 80 case OpCodes.Exp: { 78 81 double complexity = CalculateComplexity(node.GetSubtree(0)); 79 return complexity * 10;80 82 return Math.Exp(complexity); 83 } 81 84 case OpCodes.Log: { 82 85 double complexity = CalculateComplexity(node.GetSubtree(0)); 83 return complexity * 10;86 return Math.Exp(complexity); 84 87 } 85 88 case OpCodes.Square: { 86 89 double complexity = CalculateComplexity(node.GetSubtree(0)); 87 return 2* complexity;90 return complexity * complexity; 88 91 } 89 92 case OpCodes.SquareRoot: { 90 93 double complexity = CalculateComplexity(node.GetSubtree(0)); 91 return 10* complexity;94 return complexity * complexity * complexity; 92 95 } 93 96 case OpCodes.Power: { -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs
r11310 r11861 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 36 37 [StorableClass] 37 38 public abstract class SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<T, U> : SymbolicDataAnalysisSingleObjectiveAnalyzer, 38 ISymbolicDataAnalysisValidationAnalyzer<T, U> 39 ISymbolicDataAnalysisValidationAnalyzer<T, U>, IStochasticOperator 39 40 where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U> 40 41 where U : class, IDataAnalysisProblemData { -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r11310 r11861 203 203 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 204 204 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)"); 205 261 } else { 206 262 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 11 11 <RootNamespace>HeuristicLab.Problems.DataAnalysis.Symbolic</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</AssemblyName> 13 <TargetFrameworkVersion>v4. 0</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> 14 14 <TargetFrameworkProfile> 15 15 </TargetFrameworkProfile> … … 46 46 <WarningLevel>4</WarningLevel> 47 47 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 48 <Prefer32Bit>false</Prefer32Bit> 48 49 </PropertyGroup> 49 50 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 55 56 <WarningLevel>4</WarningLevel> 56 57 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 58 <Prefer32Bit>false</Prefer32Bit> 57 59 </PropertyGroup> 58 60 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> … … 64 66 <ErrorReport>prompt</ErrorReport> 65 67 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 68 <Prefer32Bit>false</Prefer32Bit> 66 69 </PropertyGroup> 67 70 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> … … 73 76 <ErrorReport>prompt</ErrorReport> 74 77 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 78 <Prefer32Bit>false</Prefer32Bit> 75 79 </PropertyGroup> 76 80 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> … … 82 86 <ErrorReport>prompt</ErrorReport> 83 87 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 88 <Prefer32Bit>false</Prefer32Bit> 84 89 </PropertyGroup> 85 90 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> … … 91 96 <ErrorReport>prompt</ErrorReport> 92 97 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 98 <Prefer32Bit>false</Prefer32Bit> 93 99 </PropertyGroup> 94 100 <ItemGroup> … … 191 197 <SubType>Code</SubType> 192 198 </Compile> 199 <Compile Include="Importer\SymbolicExpressionImporter.cs" /> 200 <Compile Include="Importer\Token.cs" /> 193 201 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 194 202 <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 24 using System; 2 25 using System.Collections.Generic; 3 26 using System.Linq; … … 45 68 return matrix[m, n] + 1; 46 69 } 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 } 47 124 } 48 125 } -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r11310 r11861 949 949 private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) { 950 950 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees); 951 prod. 951 952 while (prod.Subtrees.Count() > 0) prod.RemoveSubtree(0); 952 953 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
Note: See TracChangeset
for help on using the changeset viewer.