Changeset 7028


Ignore:
Timestamp:
11/21/11 19:08:06 (8 years ago)
Author:
gkronber
Message:

#1621: fixed bugs in response function view and added scatter plot of original data as a reference.

Location:
trunk/sources
Files:
2 edited
4 moved

Legend:

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

    r6866 r7028  
    117117    </Compile>
    118118    <Compile Include="Plugin.cs" />
     119    <Compile Include="SymbolicDataAnalysisSolutionResponseFunctionView.cs">
     120      <SubType>UserControl</SubType>
     121    </Compile>
     122    <Compile Include="SymbolicDataAnalysisSolutionResponseFunctionView.Designer.cs">
     123      <DependentUpon>SymbolicDataAnalysisSolutionResponseFunctionView.cs</DependentUpon>
     124    </Compile>
    119125    <Compile Include="SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs">
    120126      <SubType>UserControl</SubType>
     
    128134    <Compile Include="SymbolicRegressionSolutionView.Designer.cs">
    129135      <DependentUpon>SymbolicRegressionSolutionView.cs</DependentUpon>
     136    </Compile>
     137    <Compile Include="VariableTrackbar.cs">
     138      <SubType>UserControl</SubType>
     139    </Compile>
     140    <Compile Include="VariableTrackbar.Designer.cs">
     141      <DependentUpon>VariableTrackbar.cs</DependentUpon>
    130142    </Compile>
    131143    <None Include="HeuristicLab.snk" />
     
    262274      <Install>true</Install>
    263275    </BootstrapperPackage>
     276  </ItemGroup>
     277  <ItemGroup>
     278    <EmbeddedResource Include="SymbolicDataAnalysisSolutionResponseFunctionView.resx">
     279      <DependentUpon>SymbolicDataAnalysisSolutionResponseFunctionView.cs</DependentUpon>
     280    </EmbeddedResource>
    264281  </ItemGroup>
    265282  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicDataAnalysisSolutionResponseFunctionView.Designer.cs

    r7020 r7028  
    2020#endregion
    2121
    22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    2323  partial class SymbolicDataAnalysisSolutionResponseFunctionView {
    2424    /// <summary>
     
    4848      System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    4949      System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
     50      System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
     51      System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series();
     52      System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series();
     53      System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series();
    5054      this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
    5155      this.responseChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
     
    8084      this.responseChart.Name = "responseChart";
    8185      series1.ChartArea = "ChartArea";
    82       series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
     86      series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint;
    8387      series1.Legend = "Legend";
     88      series1.MarkerColor = System.Drawing.Color.Gold;
    8489      series1.MarkerSize = 3;
    85       series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Cross;
    86       series1.Name = "Model Response";
     90      series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
     91      series1.Name = "Training Data (edge)";
     92      series2.ChartArea = "ChartArea";
     93      series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint;
     94      series2.Legend = "Legend";
     95      series2.MarkerColor = System.Drawing.Color.OrangeRed;
     96      series2.MarkerSize = 3;
     97      series2.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
     98      series2.Name = "Test Data (edge)";
     99      series3.ChartArea = "ChartArea";
     100      series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint;
     101      series3.Legend = "Legend";
     102      series3.MarkerColor = System.Drawing.Color.Gold;
     103      series3.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
     104      series3.Name = "Training Data";
     105      series4.ChartArea = "ChartArea";
     106      series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint;
     107      series4.Legend = "Legend";
     108      series4.MarkerColor = System.Drawing.Color.OrangeRed;
     109      series4.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
     110      series4.Name = "Test Data";
     111      series5.BorderWidth = 3;
     112      series5.ChartArea = "ChartArea";
     113      series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
     114      series5.Color = System.Drawing.Color.DodgerBlue;
     115      series5.Legend = "Legend";
     116      series5.MarkerSize = 1;
     117      series5.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Cross;
     118      series5.Name = "Model Response";
     119      series5.ShadowColor = System.Drawing.Color.DodgerBlue;
    87120      this.responseChart.Series.Add(series1);
     121      this.responseChart.Series.Add(series2);
     122      this.responseChart.Series.Add(series3);
     123      this.responseChart.Series.Add(series4);
     124      this.responseChart.Series.Add(series5);
    88125      this.responseChart.Size = new System.Drawing.Size(258, 166);
    89126      this.responseChart.TabIndex = 3;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicDataAnalysisSolutionResponseFunctionView.cs

    r7020 r7028  
    3030using HeuristicLab.MainForm.WindowsForms;
    3131
    32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     32namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    3333  [View("Response Function View")]
    34   [Content(typeof(RegressionSolutionBase), false)]
     34  [Content(typeof(ISymbolicRegressionSolution), false)]
    3535  public partial class SymbolicDataAnalysisSolutionResponseFunctionView : AsynchronousContentView {
    3636    private Dictionary<string, List<ISymbolicExpressionTreeNode>> variableNodes;
     
    4444    }
    4545
    46     public new ISymbolicDataAnalysisSolution Content {
    47       get { return (ISymbolicDataAnalysisSolution)base.Content; }
     46    public new ISymbolicRegressionSolution Content {
     47      get { return (ISymbolicRegressionSolution)base.Content; }
    4848      set { base.Content = value; }
    4949    }
     
    122122        constNode.Value = value;
    123123
    124       UpdateChart();
    125     }
    126 
    127     private void UpdateChart() {
     124      UpdateResponseSeries();
     125    }
     126
     127    private void UpdateScatterPlot() {
    128128      string freeVariable = (string)comboBox.SelectedItem;
    129129      IEnumerable<string> fixedVariables = comboBox.Items.OfType<string>()
    130130        .Except(new string[] { freeVariable });
     131     
     132      // scatter plots for subset of samples that have values near the median values for all variables
     133      Func<int, bool> NearMedianValue = (r) => {
     134        foreach (var fixedVar in fixedVariables) {
     135          double med = medianValues[fixedVar];
     136          if (!(Content.ProblemData.Dataset.GetDoubleValue(fixedVar, r) < med + 0.1 * Math.Abs(med) &&
     137            Content.ProblemData.Dataset.GetDoubleValue(fixedVar, r) > med - 0.1 * Math.Abs(med)))
     138            return false;
     139        }
     140        return true;
     141      };
     142
     143      var mainTrainingIndizes = (from row in Content.ProblemData.TrainingIndizes
     144                                 where NearMedianValue(row)
     145                                 select row)
     146        .ToArray();
     147      var mainTestIndizes = (from row in Content.ProblemData.TestIndizes
     148                             where NearMedianValue(row)
     149                             select row)
     150        .ToArray();
     151
     152      var freeVariableValues = Content.ProblemData.Dataset.GetDoubleValues(freeVariable, mainTrainingIndizes).ToArray();
     153      var trainingValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable,
     154                                                                     mainTrainingIndizes).ToArray();
     155      Array.Sort(freeVariableValues, trainingValues);
     156      responseChart.Series["Training Data"].Points.DataBindXY(freeVariableValues, trainingValues);
     157
     158      freeVariableValues = Content.ProblemData.Dataset.GetDoubleValues(freeVariable, mainTestIndizes).ToArray();
     159      var testValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable,
     160                                                                     mainTestIndizes).ToArray();
     161      Array.Sort(freeVariableValues, testValues);
     162      responseChart.Series["Test Data"].Points.DataBindXY(freeVariableValues, testValues);
     163
     164      // draw scatter plots of remaining values
     165      freeVariableValues = Content.ProblemData.Dataset.GetDoubleValues(freeVariable, Content.ProblemData.TrainingIndizes).ToArray();
     166      trainingValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable,
     167                                                                     Content.ProblemData.TrainingIndizes).ToArray();
     168      Array.Sort(freeVariableValues, trainingValues);
     169      responseChart.Series["Training Data (edge)"].Points.DataBindXY(freeVariableValues, trainingValues);
     170
     171      freeVariableValues = Content.ProblemData.Dataset.GetDoubleValues(freeVariable, Content.ProblemData.TestIndizes).ToArray();
     172      testValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable,
     173                                                                     Content.ProblemData.TestIndizes).ToArray();
     174      Array.Sort(freeVariableValues, testValues);
     175      responseChart.Series["Test Data (edge)"].Points.DataBindXY(freeVariableValues, testValues);
     176
     177
     178
     179      responseChart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(freeVariableValues.Max());
     180      responseChart.ChartAreas[0].AxisX.Minimum = Math.Floor(freeVariableValues.Min());
     181      responseChart.ChartAreas[0].AxisY.Maximum = Math.Ceiling(Math.Max(testValues.Max(), trainingValues.Max()));
     182      responseChart.ChartAreas[0].AxisY.Minimum = Math.Floor(Math.Min(testValues.Min(), trainingValues.Min()));
     183    }
     184
     185    private void UpdateResponseSeries() {
     186      string freeVariable = (string)comboBox.SelectedItem;
    131187
    132188      var freeVariableValues = Content.ProblemData.Dataset.GetDoubleValues(freeVariable, Content.ProblemData.TrainingIndizes).ToArray();
    133189      var responseValues = Content.Model.Interpreter.GetSymbolicExpressionTreeValues(clonedTree,
    134190                                                                              Content.ProblemData.Dataset,
    135                                                                               Content.ProblemData.TrainingIndizes).ToArray();
     191                                                                              Content.ProblemData.TrainingIndizes)
     192                                                                              .ToArray();
    136193      Array.Sort(freeVariableValues, responseValues);
    137194      responseChart.Series["Model Response"].Points.DataBindXY(freeVariableValues, responseValues);
     195    }
     196
     197    private void ComboBoxSelectedIndexChanged(object sender, EventArgs e) {
     198      string freeVariable = (string)comboBox.SelectedItem;
     199      IEnumerable<string> fixedVariables = comboBox.Items.OfType<string>()
     200        .Except(new string[] { freeVariable });
     201
     202      variableNodes.Clear();
     203      clonedTree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
     204
     205      foreach (var varNode in clonedTree.IterateNodesPrefix().OfType<VariableTreeNode>()) {
     206        if (fixedVariables.Contains(varNode.VariableName)) {
     207          if (!variableNodes.ContainsKey(varNode.VariableName))
     208            variableNodes.Add(varNode.VariableName, new List<ISymbolicExpressionTreeNode>());
     209
     210          int childIndex = varNode.Parent.IndexOfSubtree(varNode);
     211          var replacementNode = MakeConstantTreeNode(medianValues[varNode.VariableName]);
     212          var parent = varNode.Parent;
     213          parent.RemoveSubtree(childIndex);
     214          parent.InsertSubtree(childIndex, MakeProduct(replacementNode, varNode.Weight));
     215          variableNodes[varNode.VariableName].Add(replacementNode);
     216        }
     217      }
     218
     219      CreateSliders(fixedVariables);
     220      UpdateScatterPlot();
     221      UpdateResponseSeries();
     222    }
     223
     224    private ISymbolicExpressionTreeNode MakeProduct(ConstantTreeNode c, double weight) {
     225      var mul = new Multiplication();
     226      var prod = mul.CreateTreeNode();
     227      prod.AddSubtree(MakeConstantTreeNode(weight));
     228      prod.AddSubtree(c);
     229      return prod;
    138230    }
    139231
     
    146238      return constantTreeNode;
    147239    }
    148 
    149     private void ComboBoxSelectedIndexChanged(object sender, EventArgs e) {
    150       string freeVariable = (string)comboBox.SelectedItem;
    151       IEnumerable<string> fixedVariables = comboBox.Items.OfType<string>()
    152         .Except(new string[] { freeVariable });
    153 
    154       variableNodes.Clear();
    155       clonedTree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
    156 
    157       foreach (var varNode in clonedTree.IterateNodesPrefix().OfType<VariableTreeNode>()) {
    158         if (fixedVariables.Contains(varNode.VariableName)) {
    159           if (!variableNodes.ContainsKey(varNode.VariableName))
    160             variableNodes.Add(varNode.VariableName, new List<ISymbolicExpressionTreeNode>());
    161 
    162           int childIndex = varNode.Parent.IndexOfSubtree(varNode);
    163           var replacementNode = MakeConstantTreeNode(medianValues[varNode.VariableName]);
    164           var parent = varNode.Parent;
    165           parent.RemoveSubtree(childIndex);
    166           parent.InsertSubtree(childIndex, replacementNode);
    167           variableNodes[varNode.VariableName].Add(replacementNode);
    168         }
    169       }
    170 
    171       CreateSliders(fixedVariables);
    172       UpdateChart();
    173     }
    174240  }
    175241}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/VariableTrackbar.Designer.cs

    r7020 r7028  
    1 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     1namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    22  partial class VariableTrackbar {
    33    /// <summary>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/VariableTrackbar.cs

    r7020 r7028  
    1010using HeuristicLab.Common;
    1111
    12 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     12namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    1313  public partial class VariableTrackbar : UserControl {
    1414    private readonly string variableName;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r7021 r7028  
    115115  <ItemGroup>
    116116    <Compile Include="Plugin.cs" />
    117     <Compile Include="SymbolicDataAnalysisSolutionResponseFunctionView.cs">
    118       <SubType>UserControl</SubType>
    119     </Compile>
    120     <Compile Include="SymbolicDataAnalysisSolutionResponseFunctionView.Designer.cs">
    121       <DependentUpon>SymbolicDataAnalysisSolutionResponseFunctionView.cs</DependentUpon>
    122     </Compile>
    123117    <Compile Include="TextualSymbolicDataAnalysisModelView.cs">
    124118      <SubType>UserControl</SubType>
     
    168162    <Compile Include="Symbols\VariableView.Designer.cs">
    169163      <DependentUpon>VariableView.cs</DependentUpon>
    170     </Compile>
    171     <Compile Include="VariableTrackbar.cs">
    172       <SubType>UserControl</SubType>
    173     </Compile>
    174     <Compile Include="VariableTrackbar.Designer.cs">
    175       <DependentUpon>VariableTrackbar.cs</DependentUpon>
    176164    </Compile>
    177165    <None Include="HeuristicLab.snk" />
Note: See TracChangeset for help on using the changeset viewer.