Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14943


Ignore:
Timestamp:
05/05/17 20:27:21 (8 years ago)
Author:
gkronber
Message:

#2779: cleaned code and added absolute residual and error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualAnalysisView.cs

    r14889 r14943  
    2222using System.Drawing;
    2323using System.Linq;
    24 using System.Runtime.Remoting.Contexts;
    25 using System.Threading.Tasks;
    2624using HeuristicLab.Data;
    2725using HeuristicLab.MainForm;
     
    3129  [View("Residual Analysis")]
    3230  [Content(typeof(IRegressionSolution))]
    33   public partial class RegressionSolutionResidualAnalysisView : DataAnalysisSolutionEvaluationView {
     31  public sealed partial class RegressionSolutionResidualAnalysisView : DataAnalysisSolutionEvaluationView {
     32
     33    // names should be relatively save to prevent collisions with variable names in the dataset
     34    private const string PredictionLabel = "> Prediction";
     35    private const string ResidualLabel = "> Residual";
     36    private const string AbsResidualLabel = "> Residual (abs.)";
     37    private const string RelativeErrorLabel = "> Relative Error";
     38    private const string AbsRelativeErrorLabel = "> Relative Error (abs.)";
     39    private const string PartitionLabel = "> Partition";
    3440
    3541    public new IRegressionSolution Content {
    3642      get { return (IRegressionSolution)base.Content; }
    37       set {
    38         base.Content = value;
    39       }
     43      set { base.Content = value; }
    4044    }
    4145
    42     public RegressionSolutionResidualAnalysisView()
    43       : base() {
     46    public RegressionSolutionResidualAnalysisView() : base() {
    4447      InitializeComponent();
    4548    }
     
    5861    }
    5962
    60     protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) {
     63    private void Content_ProblemDataChanged(object sender, EventArgs e) {
    6164      OnContentChanged();
    6265    }
    6366
    64     protected virtual void Content_ModelChanged(object sender, EventArgs e) {
     67    private void Content_ModelChanged(object sender, EventArgs e) {
    6568      OnContentChanged();
    6669    }
     
    8689      var predictedValuesTrain = Content.EstimatedTrainingValues.ToArray();
    8790      int j = 0; // idx for predictedValues array
    88       var partitionId = "Partition";
    89       while (ds.VariableNames.Contains(partitionId)) partitionId += "_";
    9091      foreach (var i in problemData.TrainingIndices) {
    9192        var run = CreateRunForIdx(i, problemData);
    9293        var targetValue = ds.GetDoubleValue(problemData.TargetVariable, i);
    9394        AddErrors(run, predictedValuesTrain[j++], targetValue);
    94         run.Results.Add(partitionId, new StringValue("Training"));
     95        run.Results.Add(PartitionLabel, new StringValue("Training"));
    9596        run.Color = Color.Gold;
    9697        runs.Add(run);
     
    102103        var targetValue = ds.GetDoubleValue(problemData.TargetVariable, i);
    103104        AddErrors(run, predictedValuesTest[j++], targetValue);
    104         run.Results.Add(partitionId, new StringValue("Test"));
     105        run.Results.Add(PartitionLabel, new StringValue("Test"));
    105106        run.Color = Color.Red;
    106107        runs.Add(run);
     
    119120      var residual = target - pred;
    120121      var relError = residual / target;
    121       var predId = "Prediction";
    122       while (run.Results.ContainsKey(predId)) predId += "_";
    123       var resId = "Residual";
    124       while (run.Results.ContainsKey(resId)) resId += "_";
    125       var relErrorId = "Rel. Error";
    126       while (run.Results.ContainsKey(relErrorId)) relErrorId+= "_";
    127       run.Results.Add(predId, new DoubleValue(pred));
    128       run.Results.Add(resId, new DoubleValue(residual));
    129       run.Results.Add(relErrorId, new DoubleValue(relError));
     122      run.Results.Add(PredictionLabel, new DoubleValue(pred));
     123      run.Results.Add(ResidualLabel, new DoubleValue(residual));
     124      run.Results.Add(AbsResidualLabel, new DoubleValue(Math.Abs(residual)));
     125      run.Results.Add(RelativeErrorLabel, new DoubleValue(relError));
     126      run.Results.Add(AbsRelativeErrorLabel, new DoubleValue(Math.Abs(relError)));
    130127    }
    131128
Note: See TracChangeset for help on using the changeset viewer.