Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/12/14 13:26:18 (10 years ago)
Author:
pfleck
Message:
  • Merged trunk into preprocessing branch.
Location:
branches/DataPreprocessing
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing

  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis

  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

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

    r10922 r11009  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Text;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
     
    179180      if (listeners != null) listeners(this, EventArgs.Empty);
    180181    }
     182
     183    protected virtual bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     184      errorMessage = string.Empty;
     185      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     186
     187      //check allowed input variables
     188      StringBuilder message = new StringBuilder();
     189      var variables = new HashSet<string>(problemData.InputVariables.Select(x => x.Value));
     190      foreach (var item in AllowedInputVariables) {
     191        if (!variables.Contains(item))
     192          message.AppendLine("Input variable '" + item + "' is not present in the new problem data.");
     193      }
     194
     195      if (message.Length != 0) {
     196        errorMessage = message.ToString();
     197        return false;
     198      }
     199      return true;
     200
     201    }
     202
     203    public virtual void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {
     204      DataAnalysisProblemData data = problemData as DataAnalysisProblemData;
     205      if (data == null) throw new ArgumentException("The problem data is not a data analysis problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     206
     207      string errorMessage;
     208      if (!data.IsProblemDataCompatible(this, out errorMessage)) {
     209        throw new InvalidOperationException(errorMessage);
     210      }
     211
     212      foreach (var inputVariable in InputVariables) {
     213        var variable = data.InputVariables.FirstOrDefault(i => i.Value == inputVariable.Value);
     214        InputVariables.SetItemCheckedState(inputVariable, variable != null && data.InputVariables.ItemChecked(variable));
     215      }
     216
     217      TrainingPartition.Start = TrainingPartition.End = 0;
     218      TestPartition.Start = 0;
     219      TestPartition.End = Dataset.Rows;
     220    }
    181221  }
    182222}
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

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

    r9552 r11009  
    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}
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationProblemData.cs

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

    r10772 r11009  
    4646
    4747    event EventHandler Changed;
     48
     49    void AdjustProblemDataProperties(IDataAnalysisProblemData problemData);
    4850  }
    4951}
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r9456 r11009  
    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.