Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14255 for trunk/sources


Ignore:
Timestamp:
08/16/16 12:04:56 (8 years ago)
Author:
pfleck
Message:

#2632

  • Added the name of the target variable in plots and charts (scatter, line, ...).
  • Renamed MathSymbolicDataAnalysisModelView and added two subclasses for regression and classification that shows the name of the target variable in the equation. (added and used a new Format method to the LatexFormatter that uses the actual target name when encountering the StartSymbol)
Location:
trunk/sources
Files:
11 edited
4 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.csproj

    r14125 r14255  
    144144    <Compile Include="SymbolicDiscriminantFunctionClassificationSolutionView.Designer.cs">
    145145      <DependentUpon>SymbolicDiscriminantFunctionClassificationSolutionView.cs</DependentUpon>
     146    </Compile>
     147    <Compile Include="SymbolicClassificationModelMathView.cs">
     148      <SubType>UserControl</SubType>
     149    </Compile>
     150    <Compile Include="SymbolicClassificationModelMathView.designer.cs">
     151      <DependentUpon>SymbolicClassificationModelMathView.cs</DependentUpon>
    146152    </Compile>
    147153    <None Include="HeuristicLab.snk" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicClassificationModelMathView.cs

    r14250 r14255  
    2020#endregion
    2121
    22 using System;
    23 using System.IO;
    24 using System.Windows.Forms;
    2522using HeuristicLab.MainForm;
    26 using HeuristicLab.MainForm.WindowsForms;
     23using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    2724
    28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     25namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views {
    2926  [View("Mathematical Representation")]
    30   [Content(typeof(ISymbolicDataAnalysisModel))]
    31   public partial class MathSymbolicDataAnalysisModelView : AsynchronousContentView {
    32     private SymbolicDataAnalysisExpressionLatexFormatter formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
    33     public MathSymbolicDataAnalysisModelView()
    34       : base() {
    35       InitializeComponent();
    36       webBrowser.ScrollBarsEnabled = true;
    37       webBrowser.ScriptErrorsSuppressed = false;
     27  [Content(typeof(ISymbolicClassificationModel))]
     28  public partial class SymbolicClassificationModelMathView : SymbolicDataAnalysisModelMathView {
    3829
    39       // update for the first time after page has loaded
    40       webBrowser.DocumentCompleted += (sender, args) => RefreshHtmlPage();
     30    public SymbolicClassificationModelMathView() : base() { }
    4131
    42       string hlDir = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory);
    43       webBrowser.Navigate("file://" + Path.Combine(hlDir, "displayModelFrame.html"));
    44     }
    45 
    46     public new ISymbolicDataAnalysisModel Content {
    47       get { return (ISymbolicDataAnalysisModel)base.Content; }
     32    public new ISymbolicClassificationModel Content {
     33      get { return (ISymbolicClassificationModel)base.Content; }
    4834      set { base.Content = value; }
    4935    }
    5036
    51     protected override void OnContentChanged() {
    52       base.OnContentChanged();
    53       RefreshHtmlPage();
    54     }
    55 
    56     private void RefreshHtmlPage() {
    57       // only update if the page has loaded already
    58       if (webBrowser.Document == null || webBrowser.Document.Body == null) return;
    59 
    60       if (Content != null) {
    61         HtmlElement newElement = webBrowser.Document.GetElementById("model");
    62         newElement.InnerText = formatter.Format(Content.SymbolicExpressionTree);
    63         webBrowser.Document.InvokeScript("refreshModel");
    64       } else {
    65         HtmlElement newElement = webBrowser.Document.GetElementById("model");
    66         newElement.InnerText = string.Empty;
    67       }
     37    protected override string GetFormattedTree() {
     38      return Formatter.Format(Content.SymbolicExpressionTree, Content.TargetVariable);
    6839    }
    6940  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicClassificationModelMathView.designer.cs

    r14250 r14255  
    2020#endregion
    2121
    22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    23   partial class MathSymbolicDataAnalysisModelView {
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views {
     23  partial class SymbolicClassificationModelMathView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views-3.4.csproj

    r14125 r14255  
    121121    <Compile Include="InteractiveSymbolicRegressionSolutionSimplifierView.Designer.cs">
    122122      <DependentUpon>InteractiveSymbolicRegressionSolutionSimplifierView.cs</DependentUpon>
     123    </Compile>
     124    <Compile Include="SymbolicRegressionModelMathView.cs">
     125      <SubType>UserControl</SubType>
     126    </Compile>
     127    <Compile Include="SymbolicRegressionModelMathView.designer.cs">
     128      <DependentUpon>SymbolicRegressionModelMathView.cs</DependentUpon>
    123129    </Compile>
    124130    <Compile Include="Plugin.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionModelMathView.cs

    r14250 r14255  
    2020#endregion
    2121
    22 using System;
    23 using System.IO;
    24 using System.Windows.Forms;
    2522using HeuristicLab.MainForm;
    26 using HeuristicLab.MainForm.WindowsForms;
     23using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    2724
    28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     25namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    2926  [View("Mathematical Representation")]
    30   [Content(typeof(ISymbolicDataAnalysisModel))]
    31   public partial class MathSymbolicDataAnalysisModelView : AsynchronousContentView {
    32     private SymbolicDataAnalysisExpressionLatexFormatter formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
    33     public MathSymbolicDataAnalysisModelView()
    34       : base() {
    35       InitializeComponent();
    36       webBrowser.ScrollBarsEnabled = true;
    37       webBrowser.ScriptErrorsSuppressed = false;
     27  [Content(typeof(ISymbolicRegressionModel))]
     28  public partial class SymbolicRegressionModelMathView : SymbolicDataAnalysisModelMathView {
    3829
    39       // update for the first time after page has loaded
    40       webBrowser.DocumentCompleted += (sender, args) => RefreshHtmlPage();
     30    public SymbolicRegressionModelMathView() : base() { }
    4131
    42       string hlDir = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory);
    43       webBrowser.Navigate("file://" + Path.Combine(hlDir, "displayModelFrame.html"));
    44     }
    45 
    46     public new ISymbolicDataAnalysisModel Content {
    47       get { return (ISymbolicDataAnalysisModel)base.Content; }
     32    public new ISymbolicRegressionModel Content {
     33      get { return (ISymbolicRegressionModel)base.Content; }
    4834      set { base.Content = value; }
    4935    }
    5036
    51     protected override void OnContentChanged() {
    52       base.OnContentChanged();
    53       RefreshHtmlPage();
    54     }
    55 
    56     private void RefreshHtmlPage() {
    57       // only update if the page has loaded already
    58       if (webBrowser.Document == null || webBrowser.Document.Body == null) return;
    59 
    60       if (Content != null) {
    61         HtmlElement newElement = webBrowser.Document.GetElementById("model");
    62         newElement.InnerText = formatter.Format(Content.SymbolicExpressionTree);
    63         webBrowser.Document.InvokeScript("refreshModel");
    64       } else {
    65         HtmlElement newElement = webBrowser.Document.GetElementById("model");
    66         newElement.InnerText = string.Empty;
    67       }
     37    protected override string GetFormattedTree() {
     38      return Formatter.Format(Content.SymbolicExpressionTree, Content.TargetVariable);
    6839    }
    6940  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionModelMathView.designer.cs

    r14250 r14255  
    2020#endregion
    2121
    22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    23   partial class MathSymbolicDataAnalysisModelView {
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
     23  partial class SymbolicRegressionModelMathView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r12817 r14255  
    121121      <DependentUpon>InteractiveSymbolicExpressionTreeChart.cs</DependentUpon>
    122122    </Compile>
    123     <Compile Include="MathSymbolicDataAnalysisModelView.cs">
    124       <SubType>UserControl</SubType>
    125     </Compile>
    126     <Compile Include="MathSymbolicDataAnalysisModelView.designer.cs">
    127       <DependentUpon>MathSymbolicDataAnalysisModelView.cs</DependentUpon>
     123    <Compile Include="SymbolicDataAnalysisModelMathView.cs">
     124      <SubType>UserControl</SubType>
     125    </Compile>
     126    <Compile Include="SymbolicDataAnalysisModelMathView.designer.cs">
     127      <DependentUpon>SymbolicDataAnalysisModelMathView.cs</DependentUpon>
    128128    </Compile>
    129129    <Compile Include="Plugin.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisModelMathView.cs

    r14254 r14255  
    2929  [View("Mathematical Representation")]
    3030  [Content(typeof(ISymbolicDataAnalysisModel))]
    31   public partial class MathSymbolicDataAnalysisModelView : AsynchronousContentView {
    32     private SymbolicDataAnalysisExpressionLatexFormatter formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
    33     public MathSymbolicDataAnalysisModelView()
     31  public partial class SymbolicDataAnalysisModelMathView : AsynchronousContentView {
     32    protected readonly SymbolicDataAnalysisExpressionLatexFormatter Formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
     33    public SymbolicDataAnalysisModelMathView()
    3434      : base() {
    3535      InitializeComponent();
     
    6060      if (Content != null) {
    6161        HtmlElement newElement = webBrowser.Document.GetElementById("model");
    62         newElement.InnerText = formatter.Format(Content.SymbolicExpressionTree);
     62        newElement.InnerText = GetFormattedTree();
    6363        webBrowser.Document.InvokeScript("refreshModel");
    6464      } else {
     
    6767      }
    6868    }
     69
     70    protected virtual string GetFormattedTree() {
     71      return Formatter.Format(Content.SymbolicExpressionTree);
     72    }
    6973  }
    7074}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisModelMathView.designer.cs

    r14250 r14255  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    23   partial class MathSymbolicDataAnalysisModelView {
     23  partial class SymbolicDataAnalysisModelMathView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r14185 r14255  
    3636    private int targetCount;
    3737    private int currentLag;
     38    private string targetVariable;
     39    private bool containsTimeSeriesSymbol;
    3840
    3941    [StorableConstructor]
     
    5557
    5658    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     59      return Format(symbolicExpressionTree, null);
     60    }
     61    public string Format(ISymbolicExpressionTree symbolicExpressionTree, string targetVariable) {
    5762      try {
    5863        StringBuilder strBuilder = new StringBuilder();
    5964        constants.Clear();
     65        this.targetVariable = targetVariable;
     66        containsTimeSeriesSymbol = symbolicExpressionTree.IterateNodesBreadth().Any(n => IsTimeSeriesSymbol(n.Symbol));
    6067        strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root));
    6168        return strBuilder.ToString();
     
    6471        return ex.Message + Environment.NewLine + ex.StackTrace;
    6572      }
     73    }
     74    static bool IsTimeSeriesSymbol(ISymbol s) {
     75      return s is TimeLag || s is Integral || s is Derivative || s is LaggedVariable;
    6676    }
    6777
     
    197207        strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
    198208      } else if (node.Symbol is StartSymbol) {
    199         strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
     209        FormatStartSymbol(strBuilder);
    200210      } else if (node.Symbol is Argument) {
    201211        var argSym = node.Symbol as Argument;
     
    303313      } else if (node.Symbol is StartSymbol) {
    304314        strBuilder.Append(@"\\" + Environment.NewLine);
    305         strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
     315        FormatStartSymbol(strBuilder);
    306316      } else if (node.Symbol is Power) {
    307317        strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
     
    433443    }
    434444
     445    private void FormatStartSymbol(StringBuilder strBuilder) {
     446      strBuilder.Append(targetVariable ?? "target_" + (targetCount++));
     447      if (containsTimeSeriesSymbol)
     448        strBuilder.Append("(t)");
     449      strBuilder.Append(" & = ");
     450    }
     451
    435452    private string LagToString(int lag) {
    436453      if (lag < 0) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs

    r14185 r14255  
    7676          dataGridView.RowCount = 1;
    7777          dataGridView.ColumnCount = 1;
     78          dataGridView.TopLeftHeaderCell.Value = string.Empty;
    7879        } else {
    7980          dataGridView.ColumnCount = Content.ProblemData.Classes + 1;
     
    9192          dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
    9293          dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
     94
     95          dataGridView.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
     96          dataGridView.TopLeftHeaderCell.Value = Content.Model.TargetVariable;
    9397
    9498          FillDataGridView();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r14185 r14255  
    120120          IEnumerator<double> classValueEnumerator = Content.ProblemData.ClassValues.OrderBy(x => x).GetEnumerator();
    121121          while (classNameEnumerator.MoveNext() && classValueEnumerator.MoveNext()) {
    122             Series series = new Series(classNameEnumerator.Current);
     122            Series series = new Series(Content.Model.TargetVariable + ": " + classNameEnumerator.Current);
    123123            series.ChartType = SeriesChartType.FastPoint;
    124124            series.Tag = classValueEnumerator.Current;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/ConfidenceRegressionSolutionLineChartView.cs

    r14185 r14255  
    2828using HeuristicLab.Problems.DataAnalysis;
    2929using HeuristicLab.Problems.DataAnalysis.Views;
     30using HeuristicLab.Visualization.ChartControlsExtensions;
    3031
    3132namespace HeuristicLab.Algorithms.DataAnalysis.Views {
     
    109110        // target
    110111        this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
    111         this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;
     112        this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME;
    112113        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    113114        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
     
    126127        var s3Color = chart.Series[3].Color;
    127128        this.chart.PaletteCustomColors = new Color[] { s1Color, s2Color, s3Color, s0Color };
     129
     130        // set the y-axis
     131        var axisY = this.chart.ChartAreas[0].AxisY;
     132        axisY.Title = Content.ProblemData.TargetVariable;
     133        double min = double.MaxValue, max = double.MinValue;
     134        foreach (var point in chart.Series.SelectMany(x => x.Points)) {
     135          if (!point.YValues.Any() || double.IsInfinity(point.YValues[0]) || double.IsNaN(point.YValues[0]))
     136            continue;
     137          var y = point.YValues[0];
     138          if (y < min)
     139            min = y;
     140          if (y > max)
     141            max = y;
     142        }
     143
     144        double axisMin, axisMax, axisInterval;
     145        ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval);
     146        axisY.Minimum = axisMin;
     147        axisY.Maximum = axisMax;
     148        axisY.Interval = axisInterval;
    128149
    129150        UpdateCursorInterval();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r14185 r14255  
    154154      }
    155155
    156       chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString();
     156      chart.ChartAreas[0].AxisX.Title = string.Format("{0} ({1})", residualComboBox.SelectedItem, Content.ProblemData.TargetVariable);
    157157    }
    158158
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r14185 r14255  
    6464
    6565        this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
    66         this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;
     66        this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME;
    6767        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    6868        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
     
    9797        this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
    9898
    99         // set the y-axis bounds
     99        // set the y-axis
    100100        var axisY = this.chart.ChartAreas[0].AxisY;
     101        axisY.Title = Content.ProblemData.TargetVariable;
    101102        double min = double.MaxValue, max = double.MinValue;
    102103        foreach (var point in chart.Series.SelectMany(x => x.Points)) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs

    r14185 r14255  
    9696
    9797        ChartArea chartArea = chart.ChartAreas[0];
     98        chartArea.AxisX.Title = string.Format("Residuals ({0})", Content.ProblemData.TargetVariable);
    9899        chartArea.AxisX.Minimum = -roundedMax - intervalWidth;
    99100        chartArea.AxisX.Maximum = roundedMax + intervalWidth;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs

    r14185 r14255  
    172172        double axisMin, axisMax, axisInterval;
    173173        ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval);
     174        this.chart.ChartAreas[0].AxisX.Title = "Estimated " + targetVariableName;
    174175        this.chart.ChartAreas[0].AxisX.Maximum = axisMax;
    175176        this.chart.ChartAreas[0].AxisX.Minimum = axisMin;
    176177        this.chart.ChartAreas[0].AxisX.Interval = axisInterval;
     178        this.chart.ChartAreas[0].AxisY.Title = targetVariableName;
    177179        this.chart.ChartAreas[0].AxisY.Maximum = axisMax;
    178180        this.chart.ChartAreas[0].AxisY.Minimum = axisMin;
Note: See TracChangeset for help on using the changeset viewer.