Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/28/12 15:47:26 (12 years ago)
Author:
spimming
Message:

#1680: merged changes from trunk into branch

Location:
branches/HeuristicLab.Hive.Azure
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure

  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs

    r7270 r7669  
    8484      if (d == 0) return "";
    8585      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      }
    8795      for (int i = 0; i < tree.SubtreeCount; i++) {
    8896        builder.Append(" " + GetTextualRepresentationFromSubtreeOfDepth(tree.GetSubtree(i), d - 1));
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r7270 r7669  
    5757        StringBuilder strBuilder = new StringBuilder();
    5858        constants.Clear();
    59         strBuilder.AppendLine("% needs \\usepackage{amsmath}");
    60         strBuilder.AppendLine("\\begin{align*}");
    61         strBuilder.AppendLine("\\nonumber");
    6259        strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root));
    63         strBuilder.AppendLine("\\end{align*}");
    6460        return strBuilder.ToString();
    6561      }
     
    9288    private void FormatBegin(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    9389      if (node.Symbol is Addition) {
    94         strBuilder.Append(@" ( ");
     90        strBuilder.Append(@" \left( ");
    9591      } else if (node.Symbol is Subtraction) {
    9692        if (node.SubtreeCount == 1) {
    97           strBuilder.Append(@"- ( ");
     93          strBuilder.Append(@"- \left( ");
    9894        } else {
    99           strBuilder.Append(@" ( ");
     95          strBuilder.Append(@" \left( ");
    10096        }
    10197      } else if (node.Symbol is Multiplication) {
     
    111107          strBuilder.Append(@" \cfrac{1}{" + node.SubtreeCount + @"}");
    112108        }
    113         strBuilder.Append(@" ( ");
     109        strBuilder.Append(@" \left( ");
    114110      } else if (node.Symbol is Logarithm) {
    115         strBuilder.Append(@"\log ( ");
     111        strBuilder.Append(@"\log \left( ");
    116112      } else if (node.Symbol is Exponential) {
    117         strBuilder.Append(@"\exp ( ");
     113        strBuilder.Append(@"\exp \left( ");
    118114      } else if (node.Symbol is Sine) {
    119         strBuilder.Append(@"\sin ( ");
     115        strBuilder.Append(@"\sin \left( ");
    120116      } else if (node.Symbol is Cosine) {
    121         strBuilder.Append(@"\cos ( ");
     117        strBuilder.Append(@"\cos \left( ");
    122118      } else if (node.Symbol is Tangent) {
    123         strBuilder.Append(@"\tan ( ");
     119        strBuilder.Append(@"\tan \left( ");
    124120      } else if (node.Symbol is GreaterThan) {
    125         strBuilder.Append(@"  ( ");
     121        strBuilder.Append(@"  \left( ");
    126122      } else if (node.Symbol is LessThan) {
    127         strBuilder.Append(@"  ( ");
     123        strBuilder.Append(@"  \left( ");
    128124      } else if (node.Symbol is And) {
    129         strBuilder.Append(@"   ( ");
     125        strBuilder.Append(@"  \left( \left( ");
    130126      } else if (node.Symbol is Or) {
    131         strBuilder.Append(@"   ( ");
     127        strBuilder.Append(@"   \left( \left( ");
    132128      } else if (node.Symbol is Not) {
    133         strBuilder.Append(@" \neg ( ");
     129        strBuilder.Append(@" \neg \left( ");
    134130      } else if (node.Symbol is IfThenElse) {
    135         strBuilder.Append(@" \operatorname{if}  ( 0 < ");
     131        strBuilder.Append(@" \operatorname{if}  \left( ");
    136132      } else if (node.Symbol is Constant) {
    137133        strBuilder.Append("c_{" + constants.Count + "} ");
     
    156152        strBuilder.Append(LagToString(currentLag));
    157153      } else if (node.Symbol is ProgramRootSymbol) {
     154        strBuilder
     155          .AppendLine("\\begin{align*}")
     156          .AppendLine("\\nonumber");
    158157      } else if (node.Symbol is Defun) {
    159158        var defunNode = node as DefunTreeNode;
     
    161160      } else if (node.Symbol is InvokeFunction) {
    162161        var invokeNode = node as InvokeFunctionTreeNode;
    163         strBuilder.Append(invokeNode.Symbol.FunctionName + @" ( ");
     162        strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
    164163      } else if (node.Symbol is StartSymbol) {
    165164        strBuilder.Append("Result & = ");
     
    168167        strBuilder.Append(" ARG+" + argSym.ArgumentIndex + " ");
    169168      } else if (node.Symbol is Derivative) {
    170         strBuilder.Append(@" \cfrac{d ( ");
     169        strBuilder.Append(@" \cfrac{d \left( ");
    171170      } else if (node.Symbol is TimeLag) {
    172171        var laggedNode = node as ILaggedTreeNode;
    173172        currentLag += laggedNode.Lag;
    174173      } else if (node.Symbol is Power) {
    175         strBuilder.Append(@" ( ");
     174        strBuilder.Append(@" \left( ");
    176175      } else if (node.Symbol is Root) {
    177         strBuilder.Append(@" ( ");
     176        strBuilder.Append(@" \left( ");
    178177      } else if (node.Symbol is Integral) {
    179178        // actually a new variable for t is needed in all subtrees (TODO)
    180179        var laggedTreeNode = node as ILaggedTreeNode;
    181         strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 ( ");
     180        strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 \left( ");
    182181      } else if (node.Symbol is VariableCondition) {
    183182        var conditionTreeNode = node as VariableConditionTreeNode;
     
    186185        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"}   ";
    187186        constants.Add(conditionTreeNode.Threshold);
    188         strBuilder.Append(@" ( " + p + @"\cdot ");
     187        strBuilder.Append(@" \left( " + p + @"\cdot ");
    189188      } else {
    190189        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
     
    221220        strBuilder.Append(@" < ");
    222221      } else if (node.Symbol is And) {
    223         strBuilder.Append(@" > 0  ) \land (");
     222        strBuilder.Append(@" > 0  \right) \land \left(");
    224223      } else if (node.Symbol is Or) {
    225         strBuilder.Append(@" > 0  ) \lor (");
     224        strBuilder.Append(@" > 0  \right) \lor \left(");
    226225      } else if (node.Symbol is Not) {
    227226        throw new InvalidOperationException();
    228227      } else if (node.Symbol is IfThenElse) {
    229         strBuilder.Append(@" ) , (");
     228        strBuilder.Append(@" , ");
    230229      } else if (node.Symbol is ProgramRootSymbol) {
    231230        strBuilder.Append(@"\\" + Environment.NewLine);
     
    236235        strBuilder.Append(@"\\" + Environment.NewLine + " & ");
    237236      } else if (node.Symbol is Power) {
    238         strBuilder.Append(@") ^ { \operatorname{round} (");
     237        strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
    239238      } else if (node.Symbol is Root) {
    240         strBuilder.Append(@") ^ {  \cfrac{1}{ \operatorname{round} (");
     239        strBuilder.Append(@"\right) ^ {  \cfrac{1}{ \operatorname{round} \left(");
    241240      } else if (node.Symbol is VariableCondition) {
    242241        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 + "} ";
    244243        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)   ";
    246245        constants.Add(conditionTreeNode.Threshold);
    247         strBuilder.Append(@" +  ( 1 - " + p + @" ) \cdot ");
     246        strBuilder.Append(@" +  \left( 1 - " + p + @" \right) \cdot ");
    248247      } else {
    249248        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
     
    253252    private void FormatEnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    254253      if (node.Symbol is Addition) {
    255         strBuilder.Append(@" ) ");
     254        strBuilder.Append(@" \right) ");
    256255      } else if (node.Symbol is Subtraction) {
    257         strBuilder.Append(@" ) ");
     256        strBuilder.Append(@" \right) ");
    258257      } else if (node.Symbol is Multiplication) {
    259258      } else if (node.Symbol is Division) {
     
    262261          strBuilder.Append(" } ");
    263262      } else if (node.Symbol is Average) {
    264         strBuilder.Append(@" ) ");
     263        strBuilder.Append(@" \right) ");
    265264      } else if (node.Symbol is Logarithm) {
    266         strBuilder.Append(@" ) ");
     265        strBuilder.Append(@" \right) ");
    267266      } else if (node.Symbol is Exponential) {
    268         strBuilder.Append(@" ) ");
     267        strBuilder.Append(@" \right) ");
    269268      } else if (node.Symbol is Sine) {
    270         strBuilder.Append(@" ) ");
     269        strBuilder.Append(@" \right) ");
    271270      } else if (node.Symbol is Cosine) {
    272         strBuilder.Append(@" ) ");
     271        strBuilder.Append(@" \right) ");
    273272      } else if (node.Symbol is Tangent) {
    274         strBuilder.Append(@" ) ");
     273        strBuilder.Append(@" \right) ");
    275274      } else if (node.Symbol is GreaterThan) {
    276         strBuilder.Append(@" ) ");
     275        strBuilder.Append(@" \right) ");
    277276      } else if (node.Symbol is LessThan) {
    278         strBuilder.Append(@" ) ");
     277        strBuilder.Append(@" \right) ");
    279278      } else if (node.Symbol is And) {
    280         strBuilder.Append(@" > 0 ) ) ");
     279        strBuilder.Append(@" > 0 \right) \right) ");
    281280      } else if (node.Symbol is Or) {
    282         strBuilder.Append(@" > 0 ) ) ");
     281        strBuilder.Append(@" > 0 \right) \right) ");
    283282      } else if (node.Symbol is Not) {
    284         strBuilder.Append(@" ) ");
     283        strBuilder.Append(@" \right) ");
    285284      } else if (node.Symbol is IfThenElse) {
    286         strBuilder.Append(@" ) ) ");
     285        strBuilder.Append(@" \right) ");
    287286      } else if (node.Symbol is Constant) {
    288287      } else if (node.Symbol is LaggedVariable) {
    289288      } else if (node.Symbol is Variable) {
    290289      } else if (node.Symbol is ProgramRootSymbol) {
     290        strBuilder
     291          .AppendLine("\\end{align*}")
     292          .AppendLine("\\begin{align*}")
     293          .AppendLine("\\nonumber");
    291294        // output all constant values
    292295        if (constants.Count > 0) {
    293296          int i = 0;
    294297          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(@"\\");
    297304            i++;
    298305          }
    299306        }
     307        strBuilder.AppendLine("\\end{align*}");
    300308      } else if (node.Symbol is Defun) {
    301309      } else if (node.Symbol is InvokeFunction) {
    302         strBuilder.Append(@" ) ");
     310        strBuilder.Append(@" \right) ");
    303311      } else if (node.Symbol is StartSymbol) {
    304312      } else if (node.Symbol is Argument) {
    305313      } else if (node.Symbol is Derivative) {
    306         strBuilder.Append(@" ) }{dt} ");
     314        strBuilder.Append(@" \right) }{dt} ");
    307315      } else if (node.Symbol is TimeLag) {
    308316        var laggedNode = node as ILaggedTreeNode;
    309317        currentLag -= laggedNode.Lag;
    310318      } else if (node.Symbol is Power) {
    311         strBuilder.Append(@" ) } ");
     319        strBuilder.Append(@" \right) } ");
    312320      } else if (node.Symbol is Root) {
    313         strBuilder.Append(@" ) } ) } ");
     321        strBuilder.Append(@" \right) } } ");
    314322      } else if (node.Symbol is Integral) {
    315         var laggedTreeNode = node as ILaggedTreeNode;
    316         strBuilder.Append(@" ) ");
     323        strBuilder.Append(@" \right) ");
    317324      } else if (node.Symbol is VariableCondition) {
    318         strBuilder.Append(@"\left) ");
     325        strBuilder.Append(@"\right) ");
    319326      } else {
    320327        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
     
    331338
    332339    private string EscapeLatexString(string s) {
    333       return s.Replace(@"_", @"\_");
     340      return "\\text{" +
     341        s
     342         .Replace("\\", "\\\\")
     343         .Replace("{", "\\{")
     344         .Replace("}", "\\}")
     345        + "}";
    334346    }
    335347  }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs

    r7270 r7669  
    6767      currentLag = 0;
    6868      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();
    7093    }
    7194
     
    7598
    7699      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)
    103102        return FormatRecursively(node.GetSubtree(0));
    104 
    105       stringBuilder.Append("(");
    106 
    107       if (symbol is Addition) {
     103      else if (symbol is Addition) {
     104        stringBuilder.Append("(");
    108105        for (int i = 0; i < node.SubtreeCount; i++) {
    109106          if (i > 0) stringBuilder.Append("+");
    110107          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    111108        }
     109        stringBuilder.Append(")");
    112110      } else if (symbol is And) {
    113111        stringBuilder.Append("((");
     
    118116          stringBuilder.Append(")>0)");
    119117        }
    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.
    121120      } else if (symbol is Average) {
    122121        stringBuilder.Append("(1/");
     
    159158        stringBuilder.Append(">");
    160159        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.
    162162      } else if (symbol is IfThenElse) {
    163163        stringBuilder.Append("(");
     
    175175        stringBuilder.Append(laggedVariableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
    176176        stringBuilder.Append("*");
    177         stringBuilder.Append(laggedVariableTreeNode.VariableName + LagToString(currentLag + laggedVariableTreeNode.Lag));
     177        stringBuilder.Append(laggedVariableTreeNode.VariableName +
     178                             LagToString(currentLag + laggedVariableTreeNode.Lag));
    178179      } else if (symbol is LessThan) {
    179180        stringBuilder.Append("((");
     
    181182        stringBuilder.Append("<");
    182183        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.
    184186      } else if (symbol is Logarithm) {
    185187        stringBuilder.Append("log_(");
     
    203205          stringBuilder.Append(")>0)");
    204206        }
    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.
    206209      } else if (symbol is Sine) {
    207210        stringBuilder.Append("sin(");
     
    209212        stringBuilder.Append(")");
    210213      } else if (symbol is Subtraction) {
     214        stringBuilder.Append("(");
    211215        if (node.SubtreeCount == 1) {
    212           stringBuilder.Append("-1*");
     216          stringBuilder.Append("-");
    213217          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    214218        } else {
     
    219223          }
    220224        }
     225        stringBuilder.Append(")");
    221226      } else if (symbol is Tangent) {
    222227        stringBuilder.Append("tan(");
     
    262267        string prevCounterVariable = CurrentIndexVariable;
    263268        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                                 "))");
    265272        ReleaseIndexVariable();
    266273      } else if (symbol is TimeLag) {
     
    272279        stringBuilder.Append("ERROR");
    273280      }
    274 
    275       stringBuilder.Append(")");
    276281      return stringBuilder.ToString();
    277282    }
    278283
    279284
    280     private string LagToString(int lag) {
     285    private string LagToString(int lag)
     286    {
    281287      if (lag < 0) {
    282288        return "(" + CurrentIndexVariable + "" + lag + ")";
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r7215 r7669  
    126126    <Compile Include="Creators\SymbolicDataAnalysisExpressionRampedHalfAndHalfTreeCreator.cs" />
    127127    <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" />
    128136    <Compile Include="Plugin.cs" />
    129137    <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" />
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs

    r7270 r7669  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    27   public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem {
     28  public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem {
    2829    IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows);
     30    IntValue EvaluatedSolutions { get; set; }
    2931  }
    3032}
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r7270 r7669  
    2121
    2222using System;
    23 using System.Collections.ObjectModel;
     23using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Collections.Generic;
    2625using System.Reflection;
    2726using System.Reflection.Emit;
     
    4847    internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns);
    4948    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     49    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    5050    #region private classes
    5151    private class InterpreterState {
     
    156156      get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    157157    }
     158
     159    public IValueParameter<IntValue> EvaluatedSolutionsParameter {
     160      get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     161    }
    158162    #endregion
    159163
     
    162166      get { return CheckExpressionsWithIntervalArithmeticParameter.Value; }
    163167      set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
     168    }
     169
     170    public IntValue EvaluatedSolutions {
     171      get { return EvaluatedSolutionsParameter.Value; }
     172      set { EvaluatedSolutionsParameter.Value = value; }
    164173    }
    165174    #endregion
     
    176185      : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") {
    177186      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
    179205
    180206    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    181207      if (CheckExpressionsWithIntervalArithmetic.Value)
    182208        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     209      EvaluatedSolutions.Value++; // increment the evaluated solutions counter
    183210      var compiler = new SymbolicExpressionTreeCompiler();
    184211      Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode);
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r7270 r7669  
    3434  public sealed class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
    3535    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     36    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    3637    #region private classes
    3738    private class InterpreterState {
     
    176177      get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    177178    }
     179
     180    public IValueParameter<IntValue> EvaluatedSolutionsParameter {
     181      get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     182    }
    178183    #endregion
    179184
     
    183188      set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
    184189    }
     190
     191    public IntValue EvaluatedSolutions {
     192      get { return EvaluatedSolutionsParameter.Value; }
     193      set { EvaluatedSolutionsParameter.Value = value; }
     194    }
    185195    #endregion
    186 
    187196
    188197    [StorableConstructor]
     
    196205      : base("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.") {
    197206      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
    199224
    200225    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    201226      if (CheckExpressionsWithIntervalArithmetic.Value)
    202227        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     228      EvaluatedSolutions.Value++; // increment the evaluated solutions counter
    203229      var compiler = new SymbolicExpressionTreeCompiler();
    204230      Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode);
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r7270 r7669  
    198198    private void InitializeOperators() {
    199199      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
     200      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());
    200201      Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
    201202      Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
     
    268269
    269270    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();
    271272
    272273      foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
     
    307308        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName;
    308309      }
     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      }
    309319    }
    310320
Note: See TracChangeset for help on using the changeset viewer.