Changeset 11887 for branches/HeuristicLab.BottomUpTreeDistance
- Timestamp:
- 02/04/15 14:51:00 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic (added) merged: 11384,11392,11457,11523,11623,11675,11827
- Property svn:mergeinfo changed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs
r11171 r11887 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/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r11171 r11887 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("(("); 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/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11486 r11887 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> … … 212 218 <SubType>Code</SubType> 213 219 </Compile> 220 <Compile Include="Importer\SymbolicExpressionImporter.cs" /> 221 <Compile Include="Importer\Token.cs" /> 214 222 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 215 223 <Compile Include="Matching\SymbolicExpressionTreeCanonicalSorter.cs" /> -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMatching.cs
r11239 r11887 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 21 20 22 #endregion 21 23 … … 66 68 return matrix[m, n] + 1; 67 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 } 68 124 } 69 125 }
Note: See TracChangeset
for help on using the changeset viewer.