Changeset 5051
- Timestamp:
- 12/07/10 10:23:58 (14 years ago)
- Location:
- branches/GP.Symbols (TimeLag, Diff, Integral)
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Symbols (TimeLag, Diff, Integral)/GP.Symbols.sln
r5026 r5051 78 78 {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x64.ActiveCfg = Debug|Any CPU 79 79 {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x86.ActiveCfg = Debug|Any CPU 80 {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x86.Build.0 = Debug|Any CPU 80 81 {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 82 {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Release|Any CPU.Build.0 = Release|Any CPU -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj
r5026 r5051 256 256 <Compile Include="Symbolic\Symbols\LaggedVariableView.Designer.cs"> 257 257 <DependentUpon>LaggedVariableView.cs</DependentUpon> 258 </Compile> 259 <Compile Include="Symbolic\Symbols\TimeLagView.cs"> 260 <SubType>UserControl</SubType> 261 </Compile> 262 <Compile Include="Symbolic\Symbols\TimeLagView.Designer.cs"> 263 <DependentUpon>TimeLagView.cs</DependentUpon> 258 264 </Compile> 259 265 <Compile Include="Symbolic\Symbols\VariableView.cs"> -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.Designer.cs
r5026 r5051 21 21 22 22 namespace HeuristicLab.Problems.DataAnalysis.Views.Symbolic.Symbols { 23 partial class TimeLagView {23 partial class LaggedSymbolView { 24 24 /// <summary> 25 25 /// Required designer variable. -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.cs
r5026 r5051 22 22 using System; 23 23 using System.Windows.Forms; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; 24 25 using HeuristicLab.MainForm; 25 26 using HeuristicLab.MainForm.WindowsForms; 26 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Views.Symbolic.Symbols { 30 [View(" TimeLagView")]31 [Content(typeof( TimeLag), true)]32 public partial class TimeLagView : SymbolView {33 public new TimeLagContent {34 get { return ( TimeLag)base.Content; }30 [View("LaggedSymbol View")] 31 [Content(typeof(LaggedSymbol), true)] 32 public partial class LaggedSymbolView : SymbolView { 33 public new LaggedSymbol Content { 34 get { return (LaggedSymbol)base.Content; } 35 35 set { base.Content = value; } 36 36 } 37 37 38 public TimeLagView() {38 public LaggedSymbolView() { 39 39 InitializeComponent(); 40 40 } -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
r5026 r5051 154 154 </ItemGroup> 155 155 <ItemGroup> 156 <Compile Include="Symbolic\Symbols\Derivative.cs" /> 157 <Compile Include="Symbolic\Symbols\Integral.cs" /> 156 158 <Compile Include="TableFileParser.cs" /> 157 159 <None Include="HeuristicLab.snk" /> -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs
r5026 r5051 62 62 var timeLag = new TimeLag(); 63 63 timeLag.InitialFrequency = 0.0; 64 var integral = new Integral(); 65 integral.InitialFrequency = 0.0; 66 var derivativ = new Derivative(); 67 derivativ.InitialFrequency = 0.0; 68 64 69 var constant = new Constant(); 65 70 constant.MinValue = -20; … … 69 74 laggedVariable.InitialFrequency = 0.0; 70 75 71 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, timeLag, constant, variableSymbol, laggedVariable };72 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not, timeLag };76 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, timeLag, integral, derivativ, constant, variableSymbol, laggedVariable }; 77 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not, timeLag, integral, derivativ }; 73 78 var binaryFunctionSymbols = new List<Symbol>() { gt, lt }; 74 79 var functionSymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or }; -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs
r5026 r5051 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 35 36 // not thread safe! 36 37 public sealed class SimpleArithmeticExpressionInterpreter : NamedItem, ISymbolicExpressionTreeInterpreter { 38 private struct InstructionEvaluation { 39 int instructionIndex; 40 int row; 41 } 42 37 43 private class OpCodes { 38 44 public const byte Add = 1; … … 68 74 69 75 public const byte TimeLag = 22; 76 public const byte Integral = 23; 77 public const byte Derivative = 24; 70 78 } 71 79 … … 93 101 { typeof(Argument), OpCodes.Arg }, 94 102 { typeof(TimeLag), OpCodes.TimeLag}, 103 { typeof(Integral), OpCodes.Integral}, 104 { typeof(Derivative), OpCodes.Derivative} 95 105 }; 96 106 private const int ARGUMENT_STACK_SIZE = 1024; … … 102 112 private double[] argumentStack = new double[ARGUMENT_STACK_SIZE]; 103 113 private int argStackPointer; 114 private Dictionary<InstructionEvaluation, double> cachedEvaluations; 104 115 105 116 public override bool CanChangeName { … … 120 131 public SimpleArithmeticExpressionInterpreter() 121 132 : base() { 133 cachedEvaluations = new Dictionary<InstructionEvaluation, double>(); 122 134 } 123 135 124 136 public IEnumerable<double> GetSymbolicExpressionTreeValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 125 137 this.dataset = dataset; 138 cachedEvaluations.Clear(); 126 139 var compiler = new SymbolicExpressionTreeCompiler(); 127 140 compiler.AddInstructionPostProcessingHook(PostProcessInstruction); … … 133 146 yield return Evaluate(); 134 147 } 148 cachedEvaluations.Clear(); 135 149 } 136 150 … … 295 309 case OpCodes.TimeLag: { 296 310 var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode; 311 if (row + timeLagTreeNode.Lag < 0 || row + timeLagTreeNode.Lag >= dataset.Rows) 312 return double.NaN; 313 297 314 row += timeLagTreeNode.Lag; 298 if (row < 0 || row >= dataset.Rows) {299 row -= timeLagTreeNode.Lag;300 return double.NaN;301 }302 315 double result = Evaluate(); 303 316 row -= timeLagTreeNode.Lag; 304 317 return result; 318 } 319 case OpCodes.Integral: { 320 int nextPc = pc; 321 var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode; 322 if (row + timeLagTreeNode.Lag < 0 || row + timeLagTreeNode.Lag >= dataset.Rows) 323 return double.NaN; 324 double sum = 0.0; 325 if (timeLagTreeNode.IterateNodesPrefix().OfType<VariableTreeNode>().Any()) { 326 for (int i = 0; i < Math.Abs(timeLagTreeNode.Lag); i++) { 327 row += Math.Sign(timeLagTreeNode.Lag); 328 sum += Evaluate(); 329 pc = nextPc; 330 } 331 row -= timeLagTreeNode.Lag; 332 sum += Evaluate(); 333 } else sum = Math.Abs(timeLagTreeNode.Lag) * Evaluate(); 334 return sum; 335 } 336 337 //mkommend: derivate calculation taken from: 338 //http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/ 339 //one sided smooth differentiatior, N = 4 340 // y' = 1/8h (f_i + 2f_i-1, -2 f_i-3 - f_i-4) 341 case OpCodes.Derivative: { 342 if (row - 4 < 0) return double.NaN; 343 int nextPc = pc; 344 double f_0 = Evaluate(); row--; 345 pc = nextPc; 346 double f_1 = Evaluate(); row -= 2; 347 pc = nextPc; 348 double f_3 = Evaluate(); row--; 349 pc = nextPc; 350 double f_4 = Evaluate(); 351 row += 4; 352 353 return (f_0 + 2 * f_1 - 2 * f_3 - f_4) / 8; // h = 1 305 354 } 306 355 default: throw new NotSupportedException(); -
branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/TimeLag.cs
r5026 r5051 31 31 private TimeLag(bool deserializing) : base(deserializing) { } 32 32 private TimeLag(TimeLag original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new TimeLag(this, cloner); 35 } 33 public override IDeepCloneable Clone(Cloner cloner) { return new TimeLag(this, cloner); } 34 36 35 public TimeLag() : base("TimeLag", "Represents a symblol whose evaluation is shifted.") { } 37 36 }
Note: See TracChangeset
for help on using the changeset viewer.