Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/GP.Symbols.sln
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/GP.Symbols.sln (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/GP.Symbols.sln (revision 5051)
@@ -78,4 +78,5 @@
{6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x64.ActiveCfg = Debug|Any CPU
{6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x86.Build.0 = Debug|Any CPU
{6BB69BAC-FB8F-4E57-881A-557F350B7611}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BB69BAC-FB8F-4E57-881A-557F350B7611}.Release|Any CPU.Build.0 = Release|Any CPU
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj (revision 5051)
@@ -256,4 +256,10 @@
LaggedVariableView.cs
+
+
+ UserControl
+
+
+ TimeLagView.cs
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.Designer.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.Designer.cs (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.Designer.cs (revision 5051)
@@ -21,5 +21,5 @@
namespace HeuristicLab.Problems.DataAnalysis.Views.Symbolic.Symbols {
- partial class TimeLagView {
+ partial class LaggedSymbolView {
///
/// Required designer variable.
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.cs (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.cs (revision 5051)
@@ -22,19 +22,19 @@
using System;
using System.Windows.Forms;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
namespace HeuristicLab.Problems.DataAnalysis.Views.Symbolic.Symbols {
- [View("TimeLag View")]
- [Content(typeof(TimeLag), true)]
- public partial class TimeLagView : SymbolView {
- public new TimeLag Content {
- get { return (TimeLag)base.Content; }
+ [View("LaggedSymbol View")]
+ [Content(typeof(LaggedSymbol), true)]
+ public partial class LaggedSymbolView : SymbolView {
+ public new LaggedSymbol Content {
+ get { return (LaggedSymbol)base.Content; }
set { base.Content = value; }
}
- public TimeLagView() {
+ public LaggedSymbolView() {
InitializeComponent();
}
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj (revision 5051)
@@ -154,4 +154,6 @@
+
+
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs (revision 5051)
@@ -62,4 +62,9 @@
var timeLag = new TimeLag();
timeLag.InitialFrequency = 0.0;
+ var integral = new Integral();
+ integral.InitialFrequency = 0.0;
+ var derivativ = new Derivative();
+ derivativ.InitialFrequency = 0.0;
+
var constant = new Constant();
constant.MinValue = -20;
@@ -69,6 +74,6 @@
laggedVariable.InitialFrequency = 0.0;
- var allSymbols = new List() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, timeLag, constant, variableSymbol, laggedVariable };
- var unaryFunctionSymbols = new List() { sin, cos, tan, log, exp, not, timeLag };
+ var allSymbols = new List() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, timeLag, integral, derivativ, constant, variableSymbol, laggedVariable };
+ var unaryFunctionSymbols = new List() { sin, cos, tan, log, exp, not, timeLag, integral, derivativ };
var binaryFunctionSymbols = new List() { gt, lt };
var functionSymbols = new List() { add, sub, mul, div, mean, and, or };
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs (revision 5051)
@@ -22,4 +22,5 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
@@ -35,4 +36,9 @@
// not thread safe!
public sealed class SimpleArithmeticExpressionInterpreter : NamedItem, ISymbolicExpressionTreeInterpreter {
+ private struct InstructionEvaluation {
+ int instructionIndex;
+ int row;
+ }
+
private class OpCodes {
public const byte Add = 1;
@@ -68,4 +74,6 @@
public const byte TimeLag = 22;
+ public const byte Integral = 23;
+ public const byte Derivative = 24;
}
@@ -93,4 +101,6 @@
{ typeof(Argument), OpCodes.Arg },
{ typeof(TimeLag), OpCodes.TimeLag},
+ { typeof(Integral), OpCodes.Integral},
+ { typeof(Derivative), OpCodes.Derivative}
};
private const int ARGUMENT_STACK_SIZE = 1024;
@@ -102,4 +112,5 @@
private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
private int argStackPointer;
+ private Dictionary cachedEvaluations;
public override bool CanChangeName {
@@ -120,8 +131,10 @@
public SimpleArithmeticExpressionInterpreter()
: base() {
+ cachedEvaluations = new Dictionary();
}
public IEnumerable GetSymbolicExpressionTreeValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable rows) {
this.dataset = dataset;
+ cachedEvaluations.Clear();
var compiler = new SymbolicExpressionTreeCompiler();
compiler.AddInstructionPostProcessingHook(PostProcessInstruction);
@@ -133,4 +146,5 @@
yield return Evaluate();
}
+ cachedEvaluations.Clear();
}
@@ -295,12 +309,47 @@
case OpCodes.TimeLag: {
var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode;
+ if (row + timeLagTreeNode.Lag < 0 || row + timeLagTreeNode.Lag >= dataset.Rows)
+ return double.NaN;
+
row += timeLagTreeNode.Lag;
- if (row < 0 || row >= dataset.Rows) {
- row -= timeLagTreeNode.Lag;
- return double.NaN;
- }
double result = Evaluate();
row -= timeLagTreeNode.Lag;
return result;
+ }
+ case OpCodes.Integral: {
+ int nextPc = pc;
+ var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode;
+ if (row + timeLagTreeNode.Lag < 0 || row + timeLagTreeNode.Lag >= dataset.Rows)
+ return double.NaN;
+ double sum = 0.0;
+ if (timeLagTreeNode.IterateNodesPrefix().OfType().Any()) {
+ for (int i = 0; i < Math.Abs(timeLagTreeNode.Lag); i++) {
+ row += Math.Sign(timeLagTreeNode.Lag);
+ sum += Evaluate();
+ pc = nextPc;
+ }
+ row -= timeLagTreeNode.Lag;
+ sum += Evaluate();
+ } else sum = Math.Abs(timeLagTreeNode.Lag) * Evaluate();
+ return sum;
+ }
+
+ //mkommend: derivate calculation taken from:
+ //http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
+ //one sided smooth differentiatior, N = 4
+ // y' = 1/8h (f_i + 2f_i-1, -2 f_i-3 - f_i-4)
+ case OpCodes.Derivative: {
+ if (row - 4 < 0) return double.NaN;
+ int nextPc = pc;
+ double f_0 = Evaluate(); row--;
+ pc = nextPc;
+ double f_1 = Evaluate(); row -= 2;
+ pc = nextPc;
+ double f_3 = Evaluate(); row--;
+ pc = nextPc;
+ double f_4 = Evaluate();
+ row += 4;
+
+ return (f_0 + 2 * f_1 - 2 * f_3 - f_4) / 8; // h = 1
}
default: throw new NotSupportedException();
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Derivative.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Derivative.cs (revision 5051)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Derivative.cs (revision 5051)
@@ -0,0 +1,37 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
+ [StorableClass]
+ [Item("Derivative", "Represents the derivative over the specified subtree.")]
+ public sealed class Derivative : Symbol {
+ [StorableConstructor]
+ private Derivative(bool deserializing) : base(deserializing) { }
+ private Derivative(Derivative original, Cloner cloner) : base(original, cloner) { }
+ public override IDeepCloneable Clone(Cloner cloner) { return new Derivative(this, cloner); }
+
+ public Derivative() : base("Derivative", "Represents the derivative over the specified subtree.") { }
+ }
+}
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Integral.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Integral.cs (revision 5051)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Integral.cs (revision 5051)
@@ -0,0 +1,36 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
+ [StorableClass]
+ [Item("Integral", "Represents the integral over the specified subtree.")]
+ public sealed class Integral : LaggedSymbol {
+ [StorableConstructor]
+ private Integral(bool deserializing) : base(deserializing) { }
+ protected Integral(Integral original, Cloner cloner) : base(original, cloner) { }
+ public override IDeepCloneable Clone(Cloner cloner) { return new Integral(this, cloner); }
+
+ public Integral() : base("Integral", "Represents the integral over the specified subtree.") { }
+ }
+}
Index: /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/TimeLag.cs
===================================================================
--- /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/TimeLag.cs (revision 5050)
+++ /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/TimeLag.cs (revision 5051)
@@ -31,7 +31,6 @@
private TimeLag(bool deserializing) : base(deserializing) { }
private TimeLag(TimeLag original, Cloner cloner) : base(original, cloner) { }
- public override IDeepCloneable Clone(Cloner cloner) {
- return new TimeLag(this, cloner);
- }
+ public override IDeepCloneable Clone(Cloner cloner) { return new TimeLag(this, cloner); }
+
public TimeLag() : base("TimeLag", "Represents a symblol whose evaluation is shifted.") { }
}