Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7463 for branches


Ignore:
Timestamp:
02/07/12 12:35:42 (13 years ago)
Author:
gkronber
Message:

#1081 improved formatter, line chart view, simplifier for time series prognosis solutions

Location:
branches/HeuristicLab.TimeSeries
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r7183 r7463  
    7070      Dictionary<ISymbolicExpressionTreeNode, double> impactValues =
    7171        new Dictionary<ISymbolicExpressionTreeNode, double>();
    72       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows)
     72      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1)
    7373        .ToArray();
    7474      int i = 0;
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Interfaces/ISymbolicTimeSeriesPrognosisModel.cs

    r7129 r7463  
    2020#endregion
    2121
    22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2322namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis {
    2423  public interface ISymbolicTimeSeriesPrognosisModel : ITimeSeriesPrognosisModel, ISymbolicDataAnalysisModel {
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Plugin.cs.frame

    r7099 r7463  
    2828  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis","Provides classes to perform symbolic time-series prognosis.", "3.4.1.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.1")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.4")]
    3131  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3232  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/MathSymbolicDataAnalysisModelView.designer.cs

    r7460 r7463  
    5353      this.webBrowser.AllowNavigation = false;
    5454      this.webBrowser.AllowWebBrowserDrop = false;
    55       this.webBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
     55      this.webBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     56            | System.Windows.Forms.AnchorStyles.Left)
     57            | System.Windows.Forms.AnchorStyles.Right)));
    5658      this.webBrowser.IsWebBrowserContextMenuEnabled = false;
    57       this.webBrowser.Location = new System.Drawing.Point(0, 0);
     59      this.webBrowser.Location = new System.Drawing.Point(3, 3);
    5860      this.webBrowser.MinimumSize = new System.Drawing.Size(20, 20);
    5961      this.webBrowser.Name = "webBrowser";
    60       this.webBrowser.Size = new System.Drawing.Size(352, 413);
     62      this.webBrowser.Size = new System.Drawing.Size(346, 407);
    6163      this.webBrowser.TabIndex = 0;
    6264      this.webBrowser.WebBrowserShortcutsEnabled = false;
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r7460 r7463  
    3333  [StorableClass]
    3434  public sealed class SymbolicDataAnalysisExpressionLatexFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    35     private List<double> constants;
     35    private readonly List<double> constants;
     36    private int targetCount;
    3637    private int currentLag;
    3738
     
    5758        StringBuilder strBuilder = new StringBuilder();
    5859        constants.Clear();
     60        targetCount = 1;
    5961        strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root));
    6062        return strBuilder.ToString();
     
    9698      } else if (node.Symbol is Division) {
    9799        if (node.SubtreeCount == 1) {
    98           strBuilder.Append(@" \cfrac{1}{");
     100          strBuilder.Append(@" \cfrac{1");
    99101        } else {
    100102          strBuilder.Append(@" \cfrac{ ");
     
    160162        strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
    161163      } else if (node.Symbol is StartSymbol) {
    162         strBuilder.Append("Result & = ");
     164        strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
    163165      } else if (node.Symbol is Argument) {
    164166        var argSym = node.Symbol as Argument;
     
    197199        strBuilder.Append(@" \cdot ");
    198200      } else if (node.Symbol is Division) {
    199         strBuilder.Append(@" }{ \cfrac{ ");
     201        if (node.SubtreeCount <= 2)
     202          strBuilder.Append(@" }{ ");
     203        else
     204          strBuilder.Append(@" }{ \cfrac{ ");
    200205      } else if (node.Symbol is Average) {
    201206        strBuilder.Append(@" + ");
     
    228233        strBuilder.Append(" , ");
    229234      } else if (node.Symbol is StartSymbol) {
    230         strBuilder.Append(@"\\" + Environment.NewLine + " & ");
     235        strBuilder.Append(@"\\" + Environment.NewLine);
     236        strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
    231237      } else if (node.Symbol is Power) {
    232238        strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
     
    253259      } else if (node.Symbol is Division) {
    254260        strBuilder.Append("} ");
    255         if (node.SubtreeCount > 1)
    256           strBuilder.Append("{1} ");
    257         for (int i = 1; i < node.SubtreeCount; i++) {
     261        if (node.SubtreeCount == 1 || node.SubtreeCount == 2)
    258262          strBuilder.Append(" } ");
    259         }
     263        else
     264          for (int i = 0; i < node.SubtreeCount; i++) {
     265            strBuilder.Append(" } ");
     266          }
    260267      } else if (node.Symbol is Average) {
    261268        strBuilder.Append(@" \right) ");
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r7268 r7463  
    5151    private GreaterThan gtSymbol = new GreaterThan();
    5252    private LessThan ltSymbol = new LessThan();
     53    private Integral integralSymbol = new Integral();
     54    private LaggedVariable laggedVariableSymbol = new LaggedVariable();
     55    private TimeLag timeLagSymbol = new TimeLag();
    5356
    5457    public ISymbolicExpressionTree Simplify(ISymbolicExpressionTree originalTree) {
     
    175178    private bool IsConstant(ISymbolicExpressionTreeNode node) {
    176179      return node.Symbol is Constant;
     180    }
     181
     182    // dynamic
     183    private bool IsTimeLag(ISymbolicExpressionTreeNode node) {
     184      return node.Symbol is TimeLag;
     185    }
     186    private bool IsIntegral(ISymbolicExpressionTreeNode node) {
     187      return node.Symbol is Integral;
    177188    }
    178189
     
    223234      } else if (IsNot(original)) {
    224235        return SimplifyNot(original);
     236      } else if (IsTimeLag(original)) {
     237        return SimplifyTimeLag(original);
     238      } else if (IsIntegral(original)) {
     239        return SimplifyIntegral(original);
    225240      } else {
    226241        return SimplifyAny(original);
     
    359374      return MakePower(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)));
    360375    }
     376    private ISymbolicExpressionTreeNode SimplifyTimeLag(ISymbolicExpressionTreeNode original) {
     377      var laggedTreeNode = original as ILaggedTreeNode;
     378      var simplifiedSubtree = GetSimplifiedTree(original.GetSubtree(0));
     379      if (!ContainsVariableCondition(simplifiedSubtree)) {
     380        return AddLagToDynamicNodes(simplifiedSubtree, laggedTreeNode.Lag);
     381      } else {
     382        return MakeTimeLag(simplifiedSubtree, laggedTreeNode.Lag);
     383      }
     384    }
     385    private ISymbolicExpressionTreeNode SimplifyIntegral(ISymbolicExpressionTreeNode original) {
     386      var laggedTreeNode = original as ILaggedTreeNode;
     387      var simplifiedSubtree = GetSimplifiedTree(original.GetSubtree(0));
     388      if (IsConstant(simplifiedSubtree)) {
     389        return GetSimplifiedTree(MakeProduct(simplifiedSubtree, MakeConstant(-laggedTreeNode.Lag)));
     390      } else {
     391        return MakeIntegral(simplifiedSubtree, laggedTreeNode.Lag);
     392      }
     393    }
     394
    361395    #endregion
    362396
    363397    #region low level tree restructuring
     398    private ISymbolicExpressionTreeNode MakeTimeLag(ISymbolicExpressionTreeNode subtree, int lag) {
     399      if (lag == 0) return subtree;
     400      if (IsConstant(subtree)) return subtree;
     401      var lagNode = (LaggedTreeNode)timeLagSymbol.CreateTreeNode();
     402      lagNode.Lag = lag;
     403      lagNode.AddSubtree(subtree);
     404      return lagNode;
     405    }
     406
     407    private ISymbolicExpressionTreeNode MakeIntegral(ISymbolicExpressionTreeNode subtree, int lag) {
     408      if (lag == 0) return subtree;
     409      else if (lag == -1 || lag == 1) {
     410        return MakeSum(subtree, AddLagToDynamicNodes((ISymbolicExpressionTreeNode)subtree.Clone(), lag));
     411      } else {
     412        var node = (LaggedTreeNode)integralSymbol.CreateTreeNode();
     413        node.Lag = lag;
     414        node.AddSubtree(subtree);
     415        return node;
     416      }
     417    }
     418
    364419    private ISymbolicExpressionTreeNode MakeNot(ISymbolicExpressionTreeNode t) {
    365420      if (IsConstant(t)) {
     
    811866
    812867    #region helper functions
     868    private bool ContainsVariableCondition(ISymbolicExpressionTreeNode node) {
     869      if (node.Symbol is VariableCondition) return true;
     870      foreach (var subtree in node.Subtrees)
     871        if (ContainsVariableCondition(subtree)) return true;
     872      return false;
     873    }
     874
     875    private ISymbolicExpressionTreeNode AddLagToDynamicNodes(ISymbolicExpressionTreeNode node, int lag) {
     876      var laggedTreeNode = node as ILaggedTreeNode;
     877      var variableNode = node as VariableTreeNode;
     878      var variableConditionNode = node as VariableConditionTreeNode;
     879      if (laggedTreeNode != null)
     880        laggedTreeNode.Lag += lag;
     881      else if (variableNode != null) {
     882        var laggedVariableNode = (LaggedVariableTreeNode)laggedVariableSymbol.CreateTreeNode();
     883        laggedVariableNode.Lag = lag;
     884        laggedVariableNode.VariableName = variableNode.VariableName;
     885        return laggedVariableNode;
     886      } else if (variableConditionNode != null) {
     887        throw new NotSupportedException("Removal of time lags around variable condition symbols is not allowed.");
     888      }
     889      var subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
     890      while (node.SubtreeCount > 0) node.RemoveSubtree(0);
     891      foreach (var subtree in subtrees) {
     892        node.AddSubtree(AddLagToDynamicNodes(subtree, lag));
     893      }
     894      return node;
     895    }
    813896
    814897    private bool AreSameVariable(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionLineChartView.Designer.cs

    r7129 r7463  
    4444    /// </summary>
    4545    private void InitializeComponent() {
    46       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    47       System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
     46      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
     47      System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    4848      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    4949      this.targetVariableComboBox = new System.Windows.Forms.ComboBox();
     
    5555      // chart
    5656      //
    57       this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    58                   | System.Windows.Forms.AnchorStyles.Left)
    59                   | System.Windows.Forms.AnchorStyles.Right)));
    60       chartArea2.Name = "ChartArea";
    61       this.chart.ChartAreas.Add(chartArea2);
    62       legend2.Alignment = System.Drawing.StringAlignment.Center;
    63       legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    64       legend2.Name = "Default";
    65       this.chart.Legends.Add(legend2);
     57      this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     58            | System.Windows.Forms.AnchorStyles.Left)
     59            | System.Windows.Forms.AnchorStyles.Right)));
     60      chartArea1.Name = "ChartArea";
     61      this.chart.ChartAreas.Add(chartArea1);
     62      legend1.Alignment = System.Drawing.StringAlignment.Center;
     63      legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
     64      legend1.Name = "Default";
     65      this.chart.Legends.Add(legend1);
    6666      this.chart.Location = new System.Drawing.Point(0, 31);
    6767      this.chart.Name = "chart";
    68       this.chart.Size = new System.Drawing.Size(388, 194);
     68      this.chart.Size = new System.Drawing.Size(609, 194);
    6969      this.chart.TabIndex = 0;
    7070      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     
    9696      this.prognosedValuesCheckbox.Checked = true;
    9797      this.prognosedValuesCheckbox.CheckState = System.Windows.Forms.CheckState.Checked;
    98       this.prognosedValuesCheckbox.Location = new System.Drawing.Point(271, 7);
     98      this.prognosedValuesCheckbox.Location = new System.Drawing.Point(271, 6);
    9999      this.prognosedValuesCheckbox.Name = "prognosedValuesCheckbox";
    100100      this.prognosedValuesCheckbox.Size = new System.Drawing.Size(112, 17);
     
    114114      this.Controls.Add(this.chart);
    115115      this.Name = "TimeSeriesPrognosisSolutionLineChartView";
    116       this.Size = new System.Drawing.Size(388, 225);
     116      this.Size = new System.Drawing.Size(609, 225);
    117117      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    118118      this.ResumeLayout(false);
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionLineChartView.cs

    r7154 r7463  
    3636    private const string PROGNOSEDVALUES_TEST_SERIES_NAME = "Prognosed Values (test)";
    3737    private const string PROGNOSEDVALUES_ALL_SERIES_NAME = "Prognosed Values (all samples)";
    38     private string prevTargetVariable;
     38    private int testPrognosisStart;
    3939
    4040    public new ITimeSeriesPrognosisSolution Content {
     
    6262      targetVariableComboBox.Items.Clear();
    6363      if (Content != null) {
     64        if (testPrognosisStart < Content.ProblemData.TestPartition.Start || testPrognosisStart >= Content.ProblemData.TestPartition.End) {
     65          testPrognosisStart = Content.ProblemData.TestPartition.Start;
     66        }
    6467        foreach (var targetVariable in Content.ProblemData.TargetVariables)
    6568          targetVariableComboBox.Items.Add(targetVariable);
     
    107110        this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    108111        if (prognosedValuesCheckbox.Checked) {
     112          int offsetToStart = testPrognosisStart - Content.ProblemData.TestPartition.Start;
    109113          this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points
    110             .DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    111                         Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray());
     114            .DataBindXY(Content.ProblemData.TestIndizes.Skip(offsetToStart).ToArray(),
     115                        Content.GetPrognosedValues(Enumerable.Range(testPrognosisStart, 1), Content.ProblemData.TestPartition.End - testPrognosisStart)
     116                        .SelectMany(x => x.SelectMany(y => y))
     117                        .Skip(varIndex)
     118                        .TakeEvery(Content.ProblemData.TargetVariables.Count())
     119                        .ToArray());
    112120        } else {
    113121          this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points
    114122            .DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    115                         Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).SelectMany(x => x.Single()).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray());
     123                        Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1)
     124                        .SelectMany(x => x.Single())
     125                        .Skip(varIndex)
     126                        .TakeEvery(Content.ProblemData.TargetVariables.Count())
     127                        .ToArray());
    116128        }
    117129        this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Tag = Content;
     
    163175      RedrawChart();
    164176    }
    165 
    166 
    167177
    168178    private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) {
     
    246256            break;
    247257          case PROGNOSEDVALUES_TEST_SERIES_NAME:
     258            testPrognosisStart = Content.ProblemData.TestPartition.Start;
    248259            indizes = Content.ProblemData.TestIndizes.ToArray();
    249             Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery(
     260            predictedValues = Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery(
    250261              Content.ProblemData.TargetVariables.Count()).ToArray();
    251262            break;
     
    266277        Cursor = Cursors.Default;
    267278    }
     279
    268280    private void chart_MouseDown(object sender, MouseEventArgs e) {
    269281      HitTestResult result = chart.HitTest(e.X, e.Y);
    270282      if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME) {
    271283        ToggleSeriesData(result.Series);
     284      } else if (result.ChartElementType == ChartElementType.Axis || result.ChartElementType == ChartElementType.AxisLabels ||
     285        result.ChartElementType == ChartElementType.TickMarks) {
     286        chart.ChartAreas[0].CursorX.SetCursorPixelPosition(new Point(e.X, e.Y), true);
     287        int pos = (int)Math.Round(chart.ChartAreas[0].CursorX.Position);
     288        if (pos >= Content.ProblemData.TestPartition.Start && pos < Content.ProblemData.TestPartition.End) {
     289          testPrognosisStart = pos;
     290          RedrawChart();
     291        }
    272292      }
    273293    }
     
    280300      e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[PROGNOSEDVALUES_ALL_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
    281301    }
    282 
    283302  }
    284303}
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs

    r7099 r7463  
    2727namespace HeuristicLab.Problems.DataAnalysis {
    2828  public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator {
    29     private double prevEstimated;
    30     private double prevOriginal;
    3129    private int n;
    3230    private double correctSum;
     
    8987      correctSum = 0;
    9088      incorrectSum = 0;
    91       prevOriginal = double.NaN;
    92       prevEstimated = double.NaN;
    9389      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    9490    }
Note: See TracChangeset for help on using the changeset viewer.