Changeset 5051


Ignore:
Timestamp:
12/07/10 10:23:58 (11 years ago)
Author:
mkommend
Message:

Added new symbols for GP (ticket #1256).

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  
    7878    {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x64.ActiveCfg = Debug|Any CPU
    7979    {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x86.ActiveCfg = Debug|Any CPU
     80    {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Debug|x86.Build.0 = Debug|Any CPU
    8081    {6BB69BAC-FB8F-4E57-881A-557F350B7611}.Release|Any CPU.ActiveCfg = Release|Any CPU
    8182    {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  
    256256    <Compile Include="Symbolic\Symbols\LaggedVariableView.Designer.cs">
    257257      <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>
    258264    </Compile>
    259265    <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  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Views.Symbolic.Symbols {
    23   partial class TimeLagView {
     23  partial class LaggedSymbolView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/TimeLagView.cs

    r5026 r5051  
    2222using System;
    2323using System.Windows.Forms;
     24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    2425using HeuristicLab.MainForm;
    2526using HeuristicLab.MainForm.WindowsForms;
    2627using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Views.Symbolic.Symbols {
    30   [View("TimeLag View")]
    31   [Content(typeof(TimeLag), true)]
    32   public partial class TimeLagView : SymbolView {
    33     public new TimeLag Content {
    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; }
    3535      set { base.Content = value; }
    3636    }
    3737
    38     public TimeLagView() {
     38    public LaggedSymbolView() {
    3939      InitializeComponent();
    4040    }
  • branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r5026 r5051  
    154154  </ItemGroup>
    155155  <ItemGroup>
     156    <Compile Include="Symbolic\Symbols\Derivative.cs" />
     157    <Compile Include="Symbolic\Symbols\Integral.cs" />
    156158    <Compile Include="TableFileParser.cs" />
    157159    <None Include="HeuristicLab.snk" />
  • branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs

    r5026 r5051  
    6262      var timeLag = new TimeLag();
    6363      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
    6469      var constant = new Constant();
    6570      constant.MinValue = -20;
     
    6974      laggedVariable.InitialFrequency = 0.0;
    7075
    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 };
    7378      var binaryFunctionSymbols = new List<Symbol>() { gt, lt };
    7479      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  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    3536  // not thread safe!
    3637  public sealed class SimpleArithmeticExpressionInterpreter : NamedItem, ISymbolicExpressionTreeInterpreter {
     38    private struct InstructionEvaluation {
     39      int instructionIndex;
     40      int row;
     41    }
     42
    3743    private class OpCodes {
    3844      public const byte Add = 1;
     
    6874
    6975      public const byte TimeLag = 22;
     76      public const byte Integral = 23;
     77      public const byte Derivative = 24;
    7078    }
    7179
     
    93101      { typeof(Argument), OpCodes.Arg },
    94102      { typeof(TimeLag), OpCodes.TimeLag},
     103      { typeof(Integral), OpCodes.Integral},
     104      { typeof(Derivative), OpCodes.Derivative}
    95105    };
    96106    private const int ARGUMENT_STACK_SIZE = 1024;
     
    102112    private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
    103113    private int argStackPointer;
     114    private Dictionary<InstructionEvaluation, double> cachedEvaluations;
    104115
    105116    public override bool CanChangeName {
     
    120131    public SimpleArithmeticExpressionInterpreter()
    121132      : base() {
     133      cachedEvaluations = new Dictionary<InstructionEvaluation, double>();
    122134    }
    123135
    124136    public IEnumerable<double> GetSymbolicExpressionTreeValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    125137      this.dataset = dataset;
     138      cachedEvaluations.Clear();
    126139      var compiler = new SymbolicExpressionTreeCompiler();
    127140      compiler.AddInstructionPostProcessingHook(PostProcessInstruction);
     
    133146        yield return Evaluate();
    134147      }
     148      cachedEvaluations.Clear();
    135149    }
    136150
     
    295309        case OpCodes.TimeLag: {
    296310            var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode;
     311            if (row + timeLagTreeNode.Lag < 0 || row + timeLagTreeNode.Lag >= dataset.Rows)
     312              return double.NaN;
     313
    297314            row += timeLagTreeNode.Lag;
    298             if (row < 0 || row >= dataset.Rows) {
    299               row -= timeLagTreeNode.Lag;
    300               return double.NaN;
    301             }
    302315            double result = Evaluate();
    303316            row -= timeLagTreeNode.Lag;
    304317            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
    305354          }
    306355        default: throw new NotSupportedException();
  • branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/TimeLag.cs

    r5026 r5051  
    3131    private TimeLag(bool deserializing) : base(deserializing) { }
    3232    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
    3635    public TimeLag() : base("TimeLag", "Represents a symblol whose evaluation is shifted.") { }
    3736  }
Note: See TracChangeset for help on using the changeset viewer.