Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/14 15:08:11 (10 years ago)
Author:
mkommend
Message:

#1758: Reimplemented functionality to load new problem data to data analysis solution and redesigned the according views.

  • Added setter for the target variable of regression and classification problem data.
  • Added functionality to check the compatibility of problem data.
  • Added functionality to adjust the properties of a problem data.
  • Added flowLayoutPanel with according buttons for loading a new problem data, simplifying and exporting data analysis solutions.
  • TradingProblemData currently throws a NotSupportedException when the properties should be adjusted.
Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r9456 r10540  
    221221    public string TargetVariable {
    222222      get { return TargetVariableParameter.Value.Value; }
     223      set {
     224        if (value == null) throw new ArgumentNullException("targetVariable", "The provided value for the targetVariable is null.");
     225        if (value == TargetVariable) return;
     226
     227
     228        var matchingParameterValue = TargetVariableParameter.ValidValues.FirstOrDefault(v => v.Value == value);
     229        if (matchingParameterValue == null) throw new ArgumentException("The provided value is not valid as the targetVariable.", "targetVariable");
     230        TargetVariableParameter.Value = matchingParameterValue;
     231      }
    223232    }
    224233
     
    408417    }
    409418    #endregion
     419
     420    protected override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     421      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     422      IClassificationProblemData classificationProblemData = problemData as IClassificationProblemData;
     423      if (classificationProblemData == null)
     424        throw new ArgumentException("The problem data is no classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     425
     426      var returnValue = base.IsProblemDataCompatible(classificationProblemData, out errorMessage);
     427      //check targetVariable
     428      if (classificationProblemData.InputVariables.All(var => var.Value != TargetVariable)) {
     429        errorMessage = string.Format("The target variable {0} is not present in the new problem data.", TargetVariable)
     430                       + Environment.NewLine + errorMessage;
     431        return false;
     432      }
     433
     434      var newClassValues = classificationProblemData.Dataset.GetDoubleValues(TargetVariable).Distinct().OrderBy(x => x);
     435      if (!newClassValues.SequenceEqual(ClassValues)) {
     436        errorMessage = errorMessage + string.Format("The class values differ in the provided classification problem data.");
     437        return false;
     438      }
     439
     440      return returnValue;
     441    }
     442
     443    public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {
     444      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     445      ClassificationProblemData classificationProblemData = problemData as ClassificationProblemData;
     446      if (classificationProblemData == null)
     447        throw new ArgumentException("The problem data is not a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     448
     449      base.AdjustProblemDataProperties(problemData);
     450      TargetVariable = classificationProblemData.TargetVariable;
     451      for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)
     452        ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);
     453
     454      for (int i = 0; i < Classes; i++) {
     455        for (int j = 0; j < Classes; j++) {
     456          ClassificationPenaltiesParameter.Value[i, j] = classificationProblemData.GetClassificationPenalty(ClassValuesCache[i], ClassValuesCache[j]);
     457        }
     458      }
     459    }
    410460  }
    411461}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r9456 r10540  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Text;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
     
    158159      if (listeners != null) listeners(this, EventArgs.Empty);
    159160    }
     161
     162    protected virtual bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     163      errorMessage = string.Empty;
     164      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     165
     166      //check allowed input variables
     167      StringBuilder message = new StringBuilder();
     168      var variables = new HashSet<string>(problemData.InputVariables.Select(x => x.Value));
     169      foreach (var item in AllowedInputVariables) {
     170        if (!variables.Contains(item))
     171          message.AppendLine("Input variable '" + item + "' is not present in the new problem data.");
     172      }
     173
     174      if (message.Length != 0) {
     175        errorMessage = message.ToString();
     176        return false;
     177      }
     178      return true;
     179
     180    }
     181
     182    public virtual void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {
     183      DataAnalysisProblemData data = problemData as DataAnalysisProblemData;
     184      if (data == null) throw new ArgumentException("The problem data is not a data analysis problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     185
     186      string errorMessage;
     187      if (!data.IsProblemDataCompatible(this, out errorMessage)) {
     188        throw new InvalidOperationException(errorMessage);
     189      }
     190
     191      foreach (var inputVariable in InputVariables) {
     192        var variable = data.InputVariables.FirstOrDefault(i => i.Value == inputVariable.Value);
     193        InputVariables.SetItemCheckedState(inputVariable, variable != null && data.InputVariables.ItemChecked(variable));
     194      }
     195
     196      TrainingPartition.Start = TrainingPartition.End = 0;
     197      TestPartition.Start = 0;
     198      TestPartition.End = Dataset.Rows;
     199    }
    160200  }
    161201}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r9456 r10540  
    100100    public string TargetVariable {
    101101      get { return TargetVariableParameter.Value.Value; }
     102      set {
     103        if (value == null) throw new ArgumentNullException("targetVariable", "The provided value for the targetVariable is null.");
     104        if (value == TargetVariable) return;
     105
     106        var matchingParameterValue = TargetVariableParameter.ValidValues.FirstOrDefault(v => v.Value == value);
     107        if (matchingParameterValue == null) throw new ArgumentException("The provided value is not valid as the targetVariable.", "targetVariable");
     108        TargetVariableParameter.Value = matchingParameterValue;
     109      }
    102110    }
    103111
     
    142150      OnChanged();
    143151    }
     152
     153    protected override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     154      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     155      IRegressionProblemData regressionProblemData = problemData as IRegressionProblemData;
     156      if (regressionProblemData == null)
     157        throw new ArgumentException("The problem data is not a regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     158
     159      var returnValue = base.IsProblemDataCompatible(problemData, out errorMessage);
     160      //check targetVariable
     161      if (problemData.InputVariables.All(var => var.Value != TargetVariable)) {
     162        errorMessage = string.Format("The target variable {0} is not present in the new problem data.", TargetVariable)
     163                       + Environment.NewLine + errorMessage;
     164        return false;
     165      }
     166      return returnValue;
     167    }
     168
     169    public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {
     170      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     171      RegressionProblemData regressionProblemData = problemData as RegressionProblemData;
     172      if (regressionProblemData == null)
     173        throw new ArgumentException("The problem data is not a regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     174
     175      base.AdjustProblemDataProperties(problemData);
     176      TargetVariable = regressionProblemData.TargetVariable;
     177    }
    144178  }
    145179}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs

    r9552 r10540  
    16211621    }
    16221622
     1623    public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {
     1624      TimeSeriesPrognosisProblemData timeSeriesProblemData = problemData as TimeSeriesPrognosisProblemData;
     1625      if (timeSeriesProblemData == null)
     1626        throw new ArgumentException("The problem data is not a timeseries problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     1627
     1628      base.AdjustProblemDataProperties(problemData);
     1629
     1630      TrainingHorizon = timeSeriesProblemData.TrainingHorizon;
     1631      TestHorizon = timeSeriesProblemData.TestHorizon;
     1632    }
     1633
    16231634  }
    16241635}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationProblemData.cs

    r9456 r10540  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface IClassificationProblemData : IDataAnalysisProblemData {
    25     string TargetVariable { get; }
     25    string TargetVariable { get; set; }
    2626
    2727    IEnumerable<string> ClassNames { get; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r9456 r10540  
    4343
    4444    event EventHandler Changed;
     45
     46    void AdjustProblemDataProperties(IDataAnalysisProblemData problemData);
    4547  }
    4648}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r9456 r10540  
    2222namespace HeuristicLab.Problems.DataAnalysis {
    2323  public interface IRegressionProblemData : IDataAnalysisProblemData {
    24     string TargetVariable { get; }
     24    string TargetVariable { get; set; }
    2525  }
    2626}
Note: See TracChangeset for help on using the changeset viewer.