Index: /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAnalyser.cs
===================================================================
--- /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAnalyser.cs	(revision 5554)
+++ /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAnalyser.cs	(revision 5555)
@@ -41,6 +41,6 @@
 
     #region parameter properties
-    public ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter {
-      get { return (ILookupParameter<ItemArray<SymbolicExpressionTree>>)Parameters[SymbolicExpressionTreeParameterName]; }
+    public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
+      get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
     }
     public ILookupParameter<ResultCollection> ResultCollectionParameter {
@@ -49,5 +49,5 @@
     #endregion
     #region properties
-    public ItemArray<SymbolicExpressionTree> SymbolicExpressionTrees {
+    public ItemArray<ISymbolicExpressionTree> SymbolicExpressionTrees {
       get { return SymbolicExpressionTreeParameter.ActualValue; }
     }
@@ -63,5 +63,5 @@
     public SymbolicDataAnalysisAnalyzer()
       : base() {
-      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees that should be analyzed."));
+      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees that should be analyzed."));
       Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection to store the analysis results."));
     }
Index: /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/VariableFrequencyAnalyser.cs
===================================================================
--- /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/VariableFrequencyAnalyser.cs	(revision 5554)
+++ /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/VariableFrequencyAnalyser.cs	(revision 5555)
@@ -38,5 +38,5 @@
   [Item("VariableFrequencyAnalyser", "Calculates the accumulated frequencies of variable-symbols over all trees in the population.")]
   [StorableClass]
-  public class VariableFrequencyAnalyser : SymbolicDataAnalysisAnalyzer {
+  public sealed class VariableFrequencyAnalyser : SymbolicDataAnalysisAnalyzer {
     private const string VariableFrequenciesParameterName = "VariableFrequencies";
     private const string AggregateLaggedVariablesParameterName = "AggregateLaggedVariables";
@@ -60,6 +60,6 @@
     #endregion
     [StorableConstructor]
-    protected VariableFrequencyAnalyser(bool deserializing) : base(deserializing) { }
-    protected VariableFrequencyAnalyser(VariableFrequencyAnalyser original, Cloner cloner)
+    private VariableFrequencyAnalyser(bool deserializing) : base(deserializing) { }
+    private VariableFrequencyAnalyser(VariableFrequencyAnalyser original, Cloner cloner)
       : base(original, cloner) {
     }
@@ -69,7 +69,11 @@
       Parameters.Add(new ValueLookupParameter<BoolValue>(AggregateLaggedVariablesParameterName, "Switch that determines whether all references to a variable should be aggregated regardless of time-offsets. Turn off to analyze all variable references with different time offsets separately.", new BoolValue(true)));
     }
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new VariableFrequencyAnalyser(this, cloner);
+    }
+
 
     public override IOperation Apply() {
-      ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
+      ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
       ResultCollection results = ResultCollection;
 
@@ -98,10 +102,4 @@
         row.Values.Add(0.0);
 
-
-      //foreach (var pair in VariableFrequencyAnalyser.CalculateVariableFrequencies(expressions, inputVariables)) {
-      //  VariableFrequencies.Rows[pair.Key].Values.Add(pair.Value);
-      //  results["Variable frequencies"].Value = VariableFrequencies;
-      //}
-
       return base.Apply();
     }
@@ -114,6 +112,4 @@
         var variableReferences = GetVariableReferences(tree, aggregateLaggedVariables);
         foreach (var pair in variableReferences) {
-          if (variableFrequencies.ContainsKey(pair.Key)) {
-          }
           totalNumberOfSymbols += pair.Value;
         }
@@ -124,31 +120,58 @@
     }
 
-    //public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<SymbolicExpressionTree> trees) {
-    //  Dictionary<string, double> variableReferencesSum = new Dictionary<string, double>();
-    //  Dictionary<string, double> variableFrequencies = new Dictionary<string, double>();
-    //  foreach (var inputVariable in inputVariables)
-    //    variableReferencesSum[inputVariable] = 0.0;
-    //  foreach (var tree in trees) {
-    //    var variableReferences = GetVariableReferenceCount(tree, inputVariables);
-    //    foreach (var pair in variableReferences) {
-    //      variableReferencesSum[pair.Key] += pair.Value;
-    //    }
-    //  }
-    //  double totalVariableReferences = variableReferencesSum.Values.Sum();
-    //  foreach (string inputVariable in inputVariables) {
-    //    double relFreq = variableReferencesSum[inputVariable] / totalVariableReferences;
-    //    variableFrequencies.Add(inputVariable, relFreq);
-    //  }
-    //  return variableFrequencies;
-    //}
-
     private static IEnumerable<KeyValuePair<string, int>> GetVariableReferences(ISymbolicExpressionTree tree, bool aggregateLaggedVariables = true) {
       Dictionary<string, int> references = new Dictionary<string, int>();
-      int currentTimeLag = 0;
-      tree.Root.ForEachNodePrefix(n => {
-        if (n.Symbol is LaggedVariable) {
+      if (aggregateLaggedVariables) {
+        tree.Root.ForEachNodePrefix(node => {
+          if (node.Symbol is Variable) {
+            var varNode = node as VariableTreeNode;
+            IncReferenceCount(references, varNode.VariableName);
+          } else if (node.Symbol is VariableCondition) {
+            var varCondNode = node as VariableConditionTreeNode;
+            IncReferenceCount(references, varCondNode.VariableName);
+          }
+        });
+      } else {
+        GetVariableReferences(references, tree.Root, 0);
+      }
+      return references;
+    }
+
+    private static void GetVariableReferences(Dictionary<string, int> references, ISymbolicExpressionTreeNode node, int currentLag) {
+      if (node.Symbol is LaggedVariable) {
+        var laggedVarNode = node as LaggedVariableTreeNode;
+        IncReferenceCount(references, laggedVarNode.VariableName, currentLag + laggedVarNode.Lag);
+      } else if (node.Symbol is Variable) {
+        var varNode = node as VariableTreeNode;
+        IncReferenceCount(references, varNode.VariableName, currentLag);
+      } else if (node.Symbol is VariableCondition) {
+        var varCondNode = node as VariableConditionTreeNode;
+        IncReferenceCount(references, varCondNode.VariableName, currentLag);
+        GetVariableReferences(references, node.GetSubTree(0), currentLag);
+        GetVariableReferences(references, node.GetSubTree(1), currentLag);
+      } else if (node.Symbol is Integral) {
+        var laggedNode = node as LaggedTreeNode;
+        for (int l = laggedNode.Lag; l <= 0; l++) {
+          GetVariableReferences(references, node.GetSubTree(0), currentLag + l);
         }
-      });
-      return references;
+      } else if (node.Symbol is Derivative) {
+        var laggedNode = node as LaggedTreeNode;
+        for (int l = laggedNode.Lag; l <= 0; l++) {
+          GetVariableReferences(references, node.GetSubTree(0), currentLag + l);
+        }
+      } else if (node.Symbol is TimeLag) {
+        var laggedNode = node as LaggedTreeNode;
+        GetVariableReferences(references, node.GetSubTree(0), currentLag + laggedNode.Lag);
+      }
+    }
+
+    private static void IncReferenceCount(Dictionary<string, int> references, string variableName, int timeLag = 0) {
+      string referenceId = variableName +
+        (timeLag == 0 ? "" : timeLag < 0 ? "(t" + timeLag + ")" : "(t+" + timeLag + ")");
+      if (references.ContainsKey(referenceId)) {
+        references[referenceId]++;
+      } else {
+        references[referenceId] = 1;
+      }
     }
   }
Index: /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisAnalyzer.cs
===================================================================
--- /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisAnalyzer.cs	(revision 5554)
+++ /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisAnalyzer.cs	(revision 5555)
@@ -23,7 +23,8 @@
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
 using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
   public interface ISymbolicDataAnalysisAnalyzer : IAnalyzer {
-    ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
+    IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
     ILookupParameter<ResultCollection> ResultCollectionParameter { get; }
   }
