Changeset 13062


Ignore:
Timestamp:
10/26/15 18:26:57 (4 years ago)
Author:
gkronber
Message:

#2452: merged r13002:13004 from trunk to stable

Location:
stable
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs

    r12009 r13062  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    24 using System.Windows.Forms;
    2525using HeuristicLab.Algorithms.DataAnalysis;
    2626using HeuristicLab.MainForm;
     
    3131  [Content(typeof(ISymbolicRegressionSolution))]
    3232  public partial class SymbolicRegressionSolutionErrorCharacteristicsCurveView : RegressionSolutionErrorCharacteristicsCurveView {
    33     private IRegressionSolution linearRegressionSolution;
    3433    public SymbolicRegressionSolutionErrorCharacteristicsCurveView() {
    3534      InitializeComponent();
     
    4140    }
    4241
    43     protected override void OnContentChanged() {
    44       if (Content != null)
    45         linearRegressionSolution = CreateLinearRegressionSolution();
    46       else
    47         linearRegressionSolution = null;
    48 
    49       base.OnContentChanged();
    50     }
    51 
    52     protected override void UpdateChart() {
    53       base.UpdateChart();
    54       if (Content == null || linearRegressionSolution == null) return;
    55       AddRegressionSolution(linearRegressionSolution);
    56     }
    57 
    5842    private IRegressionSolution CreateLinearRegressionSolution() {
    5943      if (Content == null) throw new InvalidOperationException();
    6044      double rmse, cvRmsError;
    6145      var problemData = (IRegressionProblemData)ProblemData.Clone();
    62       if(!problemData.TrainingIndices.Any()) return null; // don't create an LR model if the problem does not have a training set (e.g. loaded into an existing model)
     46      if (!problemData.TrainingIndices.Any()) return null; // don't create an LR model if the problem does not have a training set (e.g. loaded into an existing model)
    6347
    6448      //clear checked inputVariables
     
    7761
    7862      var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError);
    79       solution.Name = "Linear Model";
     63      solution.Name = "Baseline (linear subset)";
    8064      return solution;
    8165    }
    8266
    83     protected override void Content_ModelChanged(object sender, EventArgs e) {
    84       linearRegressionSolution = CreateLinearRegressionSolution();
    85       base.Content_ModelChanged(sender, e);
    86     }
    8767
    88     protected override void Content_ProblemDataChanged(object sender, EventArgs e) {
    89       linearRegressionSolution = CreateLinearRegressionSolution();
    90       base.Content_ProblemDataChanged(sender, e);
     68    protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() {
     69      foreach (var sol in base.CreateBaselineSolutions()) yield return sol;
     70      yield return CreateLinearRegressionSolution();
    9171    }
    9272  }
  • stable/HeuristicLab.Problems.DataAnalysis.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r12702 r13062  
    448448      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    449449      <Private>False</Private>
     450    </ProjectReference>
     451    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj">
     452      <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project>
     453      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name>
     454    </ProjectReference>
     455    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
     456      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
     457      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
    450458    </ProjectReference>
    451459    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Plugin.cs.frame

    r12751 r13062  
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Views-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
     31  [PluginDependency("HeuristicLab.Algorithms.DataAnalysis", "3.4")]
    3132  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3233  [PluginDependency("HeuristicLab.Collections", "3.3")]
     
    4445  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    4546  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
     47  [PluginDependency("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression", "3.4")]
    4648  [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]
    4749  public class HeuristicLabProblemsDataAnalysisViewsPlugin : PluginBase {
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.Designer.cs

    r12668 r13062  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
    48       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    49       System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
     48      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
     49      System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    5050      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    5151      this.label1 = new System.Windows.Forms.Label();
     
    5757      // chart
    5858      //
     59      this.chart.AllowDrop = true;
    5960      this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    6061            | System.Windows.Forms.AnchorStyles.Left)
    6162            | System.Windows.Forms.AnchorStyles.Right)));
    62       chartArea2.Name = "ChartArea1";
    63       this.chart.ChartAreas.Add(chartArea2);
    64       legend2.Alignment = System.Drawing.StringAlignment.Center;
    65       legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    66       legend2.Name = "Legend1";
    67       this.chart.Legends.Add(legend2);
     63      chartArea1.Name = "ChartArea1";
     64      this.chart.ChartAreas.Add(chartArea1);
     65      legend1.Alignment = System.Drawing.StringAlignment.Center;
     66      legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
     67      legend1.Name = "Legend1";
     68      this.chart.Legends.Add(legend1);
    6869      this.chart.Location = new System.Drawing.Point(6, 28);
    6970      this.chart.Name = "chart";
     
    7172      this.chart.TabIndex = 0;
    7273      this.chart.Text = "chart";
     74      this.chart.DragDrop += new System.Windows.Forms.DragEventHandler(this.chart_DragDrop);
     75      this.chart.DragEnter += new System.Windows.Forms.DragEventHandler(this.chart_DragEnter);
    7376      this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick);
    7477      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r12668 r13062  
    2525using System.Windows.Forms;
    2626using System.Windows.Forms.DataVisualization.Charting;
     27using HeuristicLab.Algorithms.DataAnalysis;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.MainForm;
     30using HeuristicLab.Optimization;
    2931
    3032namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    6264    }
    6365
     66    // the view holds one regression solution as content but also contains several other regression solutions for comparison
     67    // the following invariants must hold
     68    // (Solutions.IsEmpty && Content == null) ||
     69    // (Solutions[0] == Content && Solutions.All(s => s.ProblemData.TargetVariable == Content.TargetVariable))
     70
    6471    public new IRegressionSolution Content {
    6572      get { return (IRegressionSolution)base.Content; }
    6673      set { base.Content = value; }
    6774    }
     75
     76    private readonly IList<IRegressionSolution> solutions = new List<IRegressionSolution>();
     77    public IEnumerable<IRegressionSolution> Solutions {
     78      get { return solutions.AsEnumerable(); }
     79    }
     80
    6881    public IRegressionProblemData ProblemData {
    6982      get {
     
    8699    protected virtual void Content_ModelChanged(object sender, EventArgs e) {
    87100      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ModelChanged, sender, e);
    88       else UpdateChart();
     101      else {
     102        // recalculate baseline solutions (for symbolic regression models the features used in the model might have changed)
     103        solutions.Clear(); // remove all
     104        solutions.Add(Content); // re-add the first solution
     105        // and recalculate all other solutions
     106        foreach (var sol in CreateBaselineSolutions()) {
     107          solutions.Add(sol);
     108        }
     109        UpdateChart();
     110      }
    89111    }
    90112    protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) {
    91113      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ProblemDataChanged, sender, e);
    92114      else {
     115        // recalculate baseline solutions
     116        solutions.Clear(); // remove all
     117        solutions.Add(Content); // re-add the first solution
     118        // and recalculate all other solutions
     119        foreach (var sol in CreateBaselineSolutions()) {
     120          solutions.Add(sol);
     121        }
    93122        UpdateChart();
    94123      }
     
    96125    protected override void OnContentChanged() {
    97126      base.OnContentChanged();
     127      // the content object is always stored as the first element in solutions
     128      solutions.Clear();
     129      ReadOnly = Content == null;
     130      if (Content != null) {
     131        // recalculate all solutions
     132        solutions.Add(Content);
     133        if (ProblemData.TrainingIndices.Any()) {
     134          foreach (var sol in CreateBaselineSolutions())
     135            solutions.Add(sol);
     136          // more solutions can be added by drag&drop
     137        }
     138      }
    98139      UpdateChart();
    99140    }
     
    109150      if (cmbSamples.SelectedItem.ToString() == TestSamples && !ProblemData.TestIndices.Any()) return;
    110151
    111       if (Content.ProblemData.TrainingIndices.Any()) {
    112         AddRegressionSolution(CreateConstantSolution());
    113       }
    114 
    115       AddRegressionSolution(Content);
     152      foreach (var sol in Solutions) {
     153        AddSeries(sol);
     154      }
    116155
    117156      chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString();
    118157    }
    119158
    120     protected void AddRegressionSolution(IRegressionSolution solution) {
     159    protected void AddSeries(IRegressionSolution solution) {
    121160      if (chart.Series.Any(s => s.Name == solution.Name)) return;
    122161
     
    239278    }
    240279
    241     #region Baseline
    242280    private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) {
    243281      HitTestResult result = chart.HitTest(e.X, e.Y);
     
    247285    }
    248286
    249     private ConstantRegressionSolution CreateConstantSolution() {
     287    protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() {
     288      yield return CreateConstantSolution();
     289      yield return CreateLinearSolution();
     290    }
     291
     292    private IRegressionSolution CreateConstantSolution() {
    250293      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average();
    251294      var model = new ConstantRegressionModel(averageTrainingTarget);
    252295      var solution = new ConstantRegressionSolution(model, (IRegressionProblemData)ProblemData.Clone());
    253       solution.Name = "Baseline";
     296      solution.Name = "Baseline (constant)";
    254297      return solution;
    255298    }
    256     #endregion
     299    private IRegressionSolution CreateLinearSolution() {
     300      double rmsError, cvRmsError;
     301      var solution = LinearRegression.CreateLinearRegressionSolution((IRegressionProblemData)ProblemData.Clone(), out rmsError, out cvRmsError);
     302      solution.Name = "Baseline (linear)";
     303      return solution;
     304    }
    257305
    258306    private void chart_MouseMove(object sender, MouseEventArgs e) {
     
    265313    }
    266314
     315    private void chart_DragDrop(object sender, DragEventArgs e) {
     316      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
     317
     318        var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     319        var dataAsRegressionSolution = data as IRegressionSolution;
     320        var dataAsResult = data as IResult;
     321
     322        if (dataAsRegressionSolution != null) {
     323          solutions.Add((IRegressionSolution)dataAsRegressionSolution.Clone());
     324        } else if (dataAsResult != null && dataAsResult.Value is IRegressionSolution) {
     325          solutions.Add((IRegressionSolution)dataAsResult.Value.Clone());
     326        }
     327
     328        UpdateChart();
     329      }
     330    }
     331
     332    private void chart_DragEnter(object sender, DragEventArgs e) {
     333      e.Effect = DragDropEffects.None;
     334      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return;
     335
     336      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     337      var dataAsRegressionSolution = data as IRegressionSolution;
     338      var dataAsResult = data as IResult;
     339
     340      if (!ReadOnly &&
     341        (dataAsRegressionSolution != null || (dataAsResult != null && dataAsResult.Value is IRegressionSolution))) {
     342        e.Effect = DragDropEffects.Copy;
     343      }
     344    }
     345
    267346    private void residualComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    268347      UpdateChart();
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs

    r12009 r13062  
    2828  [Content(typeof(ITimeSeriesPrognosisSolution))]
    2929  public partial class TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView : RegressionSolutionErrorCharacteristicsCurveView {
    30 
    31 
    3230    public TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView()
    3331      : base() {
     
    4644    }
    4745
    48     protected override void UpdateChart() {
    49       base.UpdateChart();
    50       if (Content == null) return;
     46    protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() {
     47      foreach (var sol in base.CreateBaselineSolutions())
     48        yield return sol;
    5149
    5250      IEnumerable<double> trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Select(r => r - 1).Where(r => r > 0)).ToList();
    53       if (trainingStartValues.Any()) {
    54         //AR1 model
    55         double alpha, beta;
    56         OnlineCalculatorError errorState;
    57         OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState);
    58         var ar1model = new TimeSeriesPrognosisAutoRegressiveModel(ProblemData.TargetVariable, new double[] { beta }, alpha).CreateTimeSeriesPrognosisSolution(ProblemData);
    59         ar1model.Name = "AR(1) Model";
    60         AddRegressionSolution(ar1model);
    61       }
     51      //AR1 model
     52      double alpha, beta;
     53      OnlineCalculatorError errorState;
     54      OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState);
     55      var ar1Solution = new TimeSeriesPrognosisAutoRegressiveModel(ProblemData.TargetVariable, new double[] { beta }, alpha).CreateTimeSeriesPrognosisSolution(ProblemData);
     56      ar1Solution.Name = "AR(1)";
     57      yield return ar1Solution;
    6258    }
    6359  }
Note: See TracChangeset for help on using the changeset viewer.