- Timestamp:
- 03/28/12 15:47:26 (12 years ago)
- Location:
- branches/HeuristicLab.Hive.Azure
- Files:
-
- 9 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive.Azure
- Property svn:ignore
-
old new 3 3 *.resharper 4 4 *.suo 5 *.user 5 6 *.vsp 6 7 Doxygen 8 FxCopResults.txt 7 9 Google.ProtocolBuffers-0.9.1.dll 8 10 HeuristicLab 3.3.5.1.ReSharper.user
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs
r7270 r7669 84 84 if (d == 0) return ""; 85 85 StringBuilder builder = new StringBuilder(); 86 builder.Append("(" + tree.ToString()); 86 var varTreeNode = tree as VariableTreeNode; 87 var constTreeNode = tree as ConstantTreeNode; 88 if (varTreeNode != null) { 89 builder.Append("(var " + varTreeNode.VariableName); 90 } else if (constTreeNode != null) { 91 builder.Append("(const"); 92 } else { 93 builder.Append("(" + tree.ToString()); 94 } 87 95 for (int i = 0; i < tree.SubtreeCount; i++) { 88 96 builder.Append(" " + GetTextualRepresentationFromSubtreeOfDepth(tree.GetSubtree(i), d - 1)); -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r7270 r7669 57 57 StringBuilder strBuilder = new StringBuilder(); 58 58 constants.Clear(); 59 strBuilder.AppendLine("% needs \\usepackage{amsmath}");60 strBuilder.AppendLine("\\begin{align*}");61 strBuilder.AppendLine("\\nonumber");62 59 strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root)); 63 strBuilder.AppendLine("\\end{align*}");64 60 return strBuilder.ToString(); 65 61 } … … 92 88 private void FormatBegin(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 93 89 if (node.Symbol is Addition) { 94 strBuilder.Append(@" ( ");90 strBuilder.Append(@" \left( "); 95 91 } else if (node.Symbol is Subtraction) { 96 92 if (node.SubtreeCount == 1) { 97 strBuilder.Append(@"- ( ");93 strBuilder.Append(@"- \left( "); 98 94 } else { 99 strBuilder.Append(@" ( ");95 strBuilder.Append(@" \left( "); 100 96 } 101 97 } else if (node.Symbol is Multiplication) { … … 111 107 strBuilder.Append(@" \cfrac{1}{" + node.SubtreeCount + @"}"); 112 108 } 113 strBuilder.Append(@" ( ");109 strBuilder.Append(@" \left( "); 114 110 } else if (node.Symbol is Logarithm) { 115 strBuilder.Append(@"\log ( ");111 strBuilder.Append(@"\log \left( "); 116 112 } else if (node.Symbol is Exponential) { 117 strBuilder.Append(@"\exp ( ");113 strBuilder.Append(@"\exp \left( "); 118 114 } else if (node.Symbol is Sine) { 119 strBuilder.Append(@"\sin ( ");115 strBuilder.Append(@"\sin \left( "); 120 116 } else if (node.Symbol is Cosine) { 121 strBuilder.Append(@"\cos ( ");117 strBuilder.Append(@"\cos \left( "); 122 118 } else if (node.Symbol is Tangent) { 123 strBuilder.Append(@"\tan ( ");119 strBuilder.Append(@"\tan \left( "); 124 120 } else if (node.Symbol is GreaterThan) { 125 strBuilder.Append(@" ( ");121 strBuilder.Append(@" \left( "); 126 122 } else if (node.Symbol is LessThan) { 127 strBuilder.Append(@" ( ");123 strBuilder.Append(@" \left( "); 128 124 } else if (node.Symbol is And) { 129 strBuilder.Append(@" 125 strBuilder.Append(@" \left( \left( "); 130 126 } else if (node.Symbol is Or) { 131 strBuilder.Append(@" ( ");127 strBuilder.Append(@" \left( \left( "); 132 128 } else if (node.Symbol is Not) { 133 strBuilder.Append(@" \neg ( ");129 strBuilder.Append(@" \neg \left( "); 134 130 } else if (node.Symbol is IfThenElse) { 135 strBuilder.Append(@" \operatorname{if} ( 0 <");131 strBuilder.Append(@" \operatorname{if} \left( "); 136 132 } else if (node.Symbol is Constant) { 137 133 strBuilder.Append("c_{" + constants.Count + "} "); … … 156 152 strBuilder.Append(LagToString(currentLag)); 157 153 } else if (node.Symbol is ProgramRootSymbol) { 154 strBuilder 155 .AppendLine("\\begin{align*}") 156 .AppendLine("\\nonumber"); 158 157 } else if (node.Symbol is Defun) { 159 158 var defunNode = node as DefunTreeNode; … … 161 160 } else if (node.Symbol is InvokeFunction) { 162 161 var invokeNode = node as InvokeFunctionTreeNode; 163 strBuilder.Append(invokeNode.Symbol.FunctionName + @" ( ");162 strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( "); 164 163 } else if (node.Symbol is StartSymbol) { 165 164 strBuilder.Append("Result & = "); … … 168 167 strBuilder.Append(" ARG+" + argSym.ArgumentIndex + " "); 169 168 } else if (node.Symbol is Derivative) { 170 strBuilder.Append(@" \cfrac{d ( ");169 strBuilder.Append(@" \cfrac{d \left( "); 171 170 } else if (node.Symbol is TimeLag) { 172 171 var laggedNode = node as ILaggedTreeNode; 173 172 currentLag += laggedNode.Lag; 174 173 } else if (node.Symbol is Power) { 175 strBuilder.Append(@" ( ");174 strBuilder.Append(@" \left( "); 176 175 } else if (node.Symbol is Root) { 177 strBuilder.Append(@" ( ");176 strBuilder.Append(@" \left( "); 178 177 } else if (node.Symbol is Integral) { 179 178 // actually a new variable for t is needed in all subtrees (TODO) 180 179 var laggedTreeNode = node as ILaggedTreeNode; 181 strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 ( ");180 strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 \left( "); 182 181 } else if (node.Symbol is VariableCondition) { 183 182 var conditionTreeNode = node as VariableConditionTreeNode; … … 186 185 p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"} "; 187 186 constants.Add(conditionTreeNode.Threshold); 188 strBuilder.Append(@" ( " + p + @"\cdot ");187 strBuilder.Append(@" \left( " + p + @"\cdot "); 189 188 } else { 190 189 throw new NotImplementedException("Export of " + node.Symbol + " is not implemented."); … … 221 220 strBuilder.Append(@" < "); 222 221 } else if (node.Symbol is And) { 223 strBuilder.Append(@" > 0 ) \land(");222 strBuilder.Append(@" > 0 \right) \land \left("); 224 223 } else if (node.Symbol is Or) { 225 strBuilder.Append(@" > 0 ) \lor(");224 strBuilder.Append(@" > 0 \right) \lor \left("); 226 225 } else if (node.Symbol is Not) { 227 226 throw new InvalidOperationException(); 228 227 } else if (node.Symbol is IfThenElse) { 229 strBuilder.Append(@" ) , (");228 strBuilder.Append(@" , "); 230 229 } else if (node.Symbol is ProgramRootSymbol) { 231 230 strBuilder.Append(@"\\" + Environment.NewLine); … … 236 235 strBuilder.Append(@"\\" + Environment.NewLine + " & "); 237 236 } else if (node.Symbol is Power) { 238 strBuilder.Append(@" ) ^ { \operatorname{round}(");237 strBuilder.Append(@"\right) ^ { \operatorname{round} \left("); 239 238 } else if (node.Symbol is Root) { 240 strBuilder.Append(@" ) ^ { \cfrac{1}{ \operatorname{round}(");239 strBuilder.Append(@"\right) ^ { \cfrac{1}{ \operatorname{round} \left("); 241 240 } else if (node.Symbol is VariableCondition) { 242 241 var conditionTreeNode = node as VariableConditionTreeNode; 243 string p = @"1 / ( 1 + \exp( - c_{" + constants.Count + "} ";242 string p = @"1 / \left( 1 + \exp \left( - c_{" + constants.Count + "} "; 244 243 constants.Add(conditionTreeNode.Slope); 245 p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"} ) )) ";244 p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"} \right) \right) \right) "; 246 245 constants.Add(conditionTreeNode.Threshold); 247 strBuilder.Append(@" + ( 1 - " + p + @") \cdot ");246 strBuilder.Append(@" + \left( 1 - " + p + @" \right) \cdot "); 248 247 } else { 249 248 throw new NotImplementedException("Export of " + node.Symbol + " is not implemented."); … … 253 252 private void FormatEnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 254 253 if (node.Symbol is Addition) { 255 strBuilder.Append(@" ) ");254 strBuilder.Append(@" \right) "); 256 255 } else if (node.Symbol is Subtraction) { 257 strBuilder.Append(@" ) ");256 strBuilder.Append(@" \right) "); 258 257 } else if (node.Symbol is Multiplication) { 259 258 } else if (node.Symbol is Division) { … … 262 261 strBuilder.Append(" } "); 263 262 } else if (node.Symbol is Average) { 264 strBuilder.Append(@" ) ");263 strBuilder.Append(@" \right) "); 265 264 } else if (node.Symbol is Logarithm) { 266 strBuilder.Append(@" ) ");265 strBuilder.Append(@" \right) "); 267 266 } else if (node.Symbol is Exponential) { 268 strBuilder.Append(@" ) ");267 strBuilder.Append(@" \right) "); 269 268 } else if (node.Symbol is Sine) { 270 strBuilder.Append(@" ) ");269 strBuilder.Append(@" \right) "); 271 270 } else if (node.Symbol is Cosine) { 272 strBuilder.Append(@" ) ");271 strBuilder.Append(@" \right) "); 273 272 } else if (node.Symbol is Tangent) { 274 strBuilder.Append(@" ) ");273 strBuilder.Append(@" \right) "); 275 274 } else if (node.Symbol is GreaterThan) { 276 strBuilder.Append(@" ) ");275 strBuilder.Append(@" \right) "); 277 276 } else if (node.Symbol is LessThan) { 278 strBuilder.Append(@" ) ");277 strBuilder.Append(@" \right) "); 279 278 } else if (node.Symbol is And) { 280 strBuilder.Append(@" > 0 )) ");279 strBuilder.Append(@" > 0 \right) \right) "); 281 280 } else if (node.Symbol is Or) { 282 strBuilder.Append(@" > 0 )) ");281 strBuilder.Append(@" > 0 \right) \right) "); 283 282 } else if (node.Symbol is Not) { 284 strBuilder.Append(@" ) ");283 strBuilder.Append(@" \right) "); 285 284 } else if (node.Symbol is IfThenElse) { 286 strBuilder.Append(@" )) ");285 strBuilder.Append(@" \right) "); 287 286 } else if (node.Symbol is Constant) { 288 287 } else if (node.Symbol is LaggedVariable) { 289 288 } else if (node.Symbol is Variable) { 290 289 } else if (node.Symbol is ProgramRootSymbol) { 290 strBuilder 291 .AppendLine("\\end{align*}") 292 .AppendLine("\\begin{align*}") 293 .AppendLine("\\nonumber"); 291 294 // output all constant values 292 295 if (constants.Count > 0) { 293 296 int i = 0; 294 297 foreach (var constant in constants) { 295 strBuilder.AppendLine(@"\\"); 296 strBuilder.Append("c_{" + i + "} & = " + constant); 298 // replace "." with ".&" to align decimal points 299 var constStr = string.Format(System.Globalization.NumberFormatInfo.InvariantInfo, "{0:G5}", constant); 300 if (!constStr.Contains(".")) constStr = constStr + ".0"; 301 constStr = constStr.Replace(".", "\\negthickspace&."); // fix problem in rendering of aligned expressions 302 strBuilder.Append("c_{" + i + "}& = & " + constStr); 303 strBuilder.Append(@"\\"); 297 304 i++; 298 305 } 299 306 } 307 strBuilder.AppendLine("\\end{align*}"); 300 308 } else if (node.Symbol is Defun) { 301 309 } else if (node.Symbol is InvokeFunction) { 302 strBuilder.Append(@" ) ");310 strBuilder.Append(@" \right) "); 303 311 } else if (node.Symbol is StartSymbol) { 304 312 } else if (node.Symbol is Argument) { 305 313 } else if (node.Symbol is Derivative) { 306 strBuilder.Append(@" ) }{dt} ");314 strBuilder.Append(@" \right) }{dt} "); 307 315 } else if (node.Symbol is TimeLag) { 308 316 var laggedNode = node as ILaggedTreeNode; 309 317 currentLag -= laggedNode.Lag; 310 318 } else if (node.Symbol is Power) { 311 strBuilder.Append(@" ) } ");319 strBuilder.Append(@" \right) } "); 312 320 } else if (node.Symbol is Root) { 313 strBuilder.Append(@" ) } )} ");321 strBuilder.Append(@" \right) } } "); 314 322 } else if (node.Symbol is Integral) { 315 var laggedTreeNode = node as ILaggedTreeNode; 316 strBuilder.Append(@" ) "); 323 strBuilder.Append(@" \right) "); 317 324 } else if (node.Symbol is VariableCondition) { 318 strBuilder.Append(@"\ left) ");325 strBuilder.Append(@"\right) "); 319 326 } else { 320 327 throw new NotImplementedException("Export of " + node.Symbol + " is not implemented."); … … 331 338 332 339 private string EscapeLatexString(string s) { 333 return s.Replace(@"_", @"\_"); 340 return "\\text{" + 341 s 342 .Replace("\\", "\\\\") 343 .Replace("{", "\\{") 344 .Replace("}", "\\}") 345 + "}"; 334 346 } 335 347 } -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
r7270 r7669 67 67 currentLag = 0; 68 68 currentIndexNumber = 0; 69 return FormatRecursively(symbolicExpressionTree.Root); 69 70 var stringBuilder = new StringBuilder(); 71 stringBuilder.AppendLine("rows = ???"); 72 stringBuilder.AppendLine(FormatOnlyExpression(symbolicExpressionTree.Root) + ";"); 73 stringBuilder.AppendLine(); 74 stringBuilder.AppendLine("function y = log_(x)"); 75 stringBuilder.AppendLine(" if(x<=0) y = NaN;"); 76 stringBuilder.AppendLine(" else y = log(x);"); 77 stringBuilder.AppendLine(" end"); 78 stringBuilder.AppendLine("end"); 79 stringBuilder.AppendLine(); 80 stringBuilder.AppendLine("function y = fivePoint(f0, f1, f3, f4)"); 81 stringBuilder.AppendLine(" y = (f0 + 2*f1 - 2*f3 - f4) / 8;"); 82 stringBuilder.AppendLine("end"); 83 return stringBuilder.ToString(); 84 } 85 86 public string FormatOnlyExpression(ISymbolicExpressionTreeNode expressionNode) 87 { 88 var stringBuilder = new StringBuilder(); 89 stringBuilder.AppendLine(" for " + CurrentIndexVariable + " = 1:1:rows"); 90 stringBuilder.AppendLine(" estimated(" + CurrentIndexVariable + ") = " + FormatRecursively(expressionNode.GetSubtree(0)) + ";"); 91 stringBuilder.AppendLine(" end;"); 92 return stringBuilder.ToString(); 70 93 } 71 94 … … 75 98 76 99 if (symbol is ProgramRootSymbol) { 77 var variableNames = node.IterateNodesPostfix() 78 .OfType<VariableTreeNode>() 79 .Select(n => n.VariableName) 80 .Distinct() 81 .OrderBy(x => x); 82 stringBuilder.AppendLine("function test_model"); 83 foreach (string variableName in variableNames) 84 stringBuilder.AppendLine(" " + variableName + " = Data(:, ???);"); 85 stringBuilder.AppendLine(" for " + CurrentIndexVariable + " = size(Data,1):-1:1"); 86 stringBuilder.AppendLine(" Target_estimated(" + CurrentIndexVariable + ") = " + FormatRecursively(node.GetSubtree(0)) + ";"); 87 stringBuilder.AppendLine(" end"); 88 stringBuilder.AppendLine("end"); 89 stringBuilder.AppendLine(); 90 stringBuilder.AppendLine("function y = log_(x)"); 91 stringBuilder.AppendLine(" if(x<=0) y = NaN;"); 92 stringBuilder.AppendLine(" else y = log(x);"); 93 stringBuilder.AppendLine(" end"); 94 stringBuilder.AppendLine("end"); 95 stringBuilder.AppendLine(); 96 stringBuilder.AppendLine("function y = fivePoint(f0, f1, f3, f4)"); 97 stringBuilder.AppendLine(" y = (f0 + 2*f1 - 2*f3 - f4) / 8;"); 98 stringBuilder.AppendLine("end"); 99 return stringBuilder.ToString(); 100 } 101 102 if (symbol is StartSymbol) 100 stringBuilder.AppendLine(FormatRecursively(node.GetSubtree(0))); 101 } else if (symbol is StartSymbol) 103 102 return FormatRecursively(node.GetSubtree(0)); 104 105 stringBuilder.Append("("); 106 107 if (symbol is Addition) { 103 else if (symbol is Addition) { 104 stringBuilder.Append("("); 108 105 for (int i = 0; i < node.SubtreeCount; i++) { 109 106 if (i > 0) stringBuilder.Append("+"); 110 107 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 111 108 } 109 stringBuilder.Append(")"); 112 110 } else if (symbol is And) { 113 111 stringBuilder.Append("(("); … … 118 116 stringBuilder.Append(")>0)"); 119 117 } 120 stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 118 stringBuilder.Append(")-0.5)*2"); 119 // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 121 120 } else if (symbol is Average) { 122 121 stringBuilder.Append("(1/"); … … 159 158 stringBuilder.Append(">"); 160 159 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 161 stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 160 stringBuilder.Append(")-0.5)*2"); 161 // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 162 162 } else if (symbol is IfThenElse) { 163 163 stringBuilder.Append("("); … … 175 175 stringBuilder.Append(laggedVariableTreeNode.Weight.ToString(CultureInfo.InvariantCulture)); 176 176 stringBuilder.Append("*"); 177 stringBuilder.Append(laggedVariableTreeNode.VariableName + LagToString(currentLag + laggedVariableTreeNode.Lag)); 177 stringBuilder.Append(laggedVariableTreeNode.VariableName + 178 LagToString(currentLag + laggedVariableTreeNode.Lag)); 178 179 } else if (symbol is LessThan) { 179 180 stringBuilder.Append("(("); … … 181 182 stringBuilder.Append("<"); 182 183 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 183 stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 184 stringBuilder.Append(")-0.5)*2"); 185 // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 184 186 } else if (symbol is Logarithm) { 185 187 stringBuilder.Append("log_("); … … 203 205 stringBuilder.Append(")>0)"); 204 206 } 205 stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 207 stringBuilder.Append(")-0.5)*2"); 208 // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. 206 209 } else if (symbol is Sine) { 207 210 stringBuilder.Append("sin("); … … 209 212 stringBuilder.Append(")"); 210 213 } else if (symbol is Subtraction) { 214 stringBuilder.Append("("); 211 215 if (node.SubtreeCount == 1) { 212 stringBuilder.Append("- 1*");216 stringBuilder.Append("-"); 213 217 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 214 218 } else { … … 219 223 } 220 224 } 225 stringBuilder.Append(")"); 221 226 } else if (symbol is Tangent) { 222 227 stringBuilder.Append("tan("); … … 262 267 string prevCounterVariable = CurrentIndexVariable; 263 268 string counterVariable = AllocateIndexVariable(); 264 stringBuilder.AppendLine(" sum (map(@(" + counterVariable + ") " + FormatRecursively(node.GetSubtree(0)) + ", (" + prevCounterVariable + "+" + laggedNode.Lag + "):" + prevCounterVariable + "))"); 269 stringBuilder.AppendLine(" sum (map(@(" + counterVariable + ") " + FormatRecursively(node.GetSubtree(0)) + 270 ", (" + prevCounterVariable + "+" + laggedNode.Lag + "):" + prevCounterVariable + 271 "))"); 265 272 ReleaseIndexVariable(); 266 273 } else if (symbol is TimeLag) { … … 272 279 stringBuilder.Append("ERROR"); 273 280 } 274 275 stringBuilder.Append(")");276 281 return stringBuilder.ToString(); 277 282 } 278 283 279 284 280 private string LagToString(int lag) { 285 private string LagToString(int lag) 286 { 281 287 if (lag < 0) { 282 288 return "(" + CurrentIndexVariable + "" + lag + ")"; -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r7215 r7669 126 126 <Compile Include="Creators\SymbolicDataAnalysisExpressionRampedHalfAndHalfTreeCreator.cs" /> 127 127 <Compile Include="Creators\SymbolicDataAnalysisExpressionTreeCreator.cs" /> 128 <Compile Include="Crossovers\MultiSymbolicDataAnalysisExpressionCrossover.cs" /> 129 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionContextAwareCrossover.cs" /> 130 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionCrossover.cs" /> 131 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs" /> 132 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs" /> 133 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs" /> 134 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" /> 135 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" /> 128 136 <Compile Include="Plugin.cs" /> 129 137 <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" /> -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs
r7270 r7669 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 26 26 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem {28 public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem { 28 29 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows); 30 IntValue EvaluatedSolutions { get; set; } 29 31 } 30 32 } -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r7270 r7669 21 21 22 22 using System; 23 using System.Collections. ObjectModel;23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Collections.Generic;26 25 using System.Reflection; 27 26 using System.Reflection.Emit; … … 48 47 internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns); 49 48 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 49 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 50 50 #region private classes 51 51 private class InterpreterState { … … 156 156 get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 157 157 } 158 159 public IValueParameter<IntValue> EvaluatedSolutionsParameter { 160 get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 161 } 158 162 #endregion 159 163 … … 162 166 get { return CheckExpressionsWithIntervalArithmeticParameter.Value; } 163 167 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; } 168 } 169 170 public IntValue EvaluatedSolutions { 171 get { return EvaluatedSolutionsParameter.Value; } 172 set { EvaluatedSolutionsParameter.Value = value; } 164 173 } 165 174 #endregion … … 176 185 : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") { 177 186 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 178 } 187 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 188 } 189 190 [StorableHook(HookType.AfterDeserialization)] 191 private void AfterDeserialization() { 192 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 193 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 194 } 195 196 #region IStatefulItem 197 public void InitializeState() { 198 EvaluatedSolutions.Value = 0; 199 } 200 201 public void ClearState() { 202 EvaluatedSolutions.Value = 0; 203 } 204 #endregion 179 205 180 206 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 181 207 if (CheckExpressionsWithIntervalArithmetic.Value) 182 208 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 209 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 183 210 var compiler = new SymbolicExpressionTreeCompiler(); 184 211 Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode); -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r7270 r7669 34 34 public sealed class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { 35 35 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 36 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 36 37 #region private classes 37 38 private class InterpreterState { … … 176 177 get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 177 178 } 179 180 public IValueParameter<IntValue> EvaluatedSolutionsParameter { 181 get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 182 } 178 183 #endregion 179 184 … … 183 188 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; } 184 189 } 190 191 public IntValue EvaluatedSolutions { 192 get { return EvaluatedSolutionsParameter.Value; } 193 set { EvaluatedSolutionsParameter.Value = value; } 194 } 185 195 #endregion 186 187 196 188 197 [StorableConstructor] … … 196 205 : base("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.") { 197 206 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 198 } 207 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 208 } 209 210 [StorableHook(HookType.AfterDeserialization)] 211 private void AfterDeserialization() { 212 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 213 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 214 } 215 216 #region IStatefulItem 217 public void InitializeState() { 218 EvaluatedSolutions.Value = 0; 219 } 220 221 public void ClearState() { 222 } 223 #endregion 199 224 200 225 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 201 226 if (CheckExpressionsWithIntervalArithmetic.Value) 202 227 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 228 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 203 229 var compiler = new SymbolicExpressionTreeCompiler(); 204 230 Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode); -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r7270 r7669 198 198 private void InitializeOperators() { 199 199 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>()); 200 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>()); 200 201 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 201 202 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); … … 268 269 269 270 protected virtual void ParameterizeOperators() { 270 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators) ;271 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList(); 271 272 272 273 foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { … … 307 308 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName; 308 309 } 310 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 311 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameterName; 312 } 313 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 314 op.ProblemDataParameter.ActualName = ProblemDataParameter.Name; 315 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; 316 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 317 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 318 } 309 319 } 310 320
Note: See TracChangeset
for help on using the changeset viewer.