Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/21 15:45:17 (4 years ago)
Author:
gkronber
Message:

#3073: merge r17835, r17845 from trunk to branch

Location:
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis

  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs

    r17180 r17874  
    7373
    7474    public ClassificationEnsembleProblemData() : base() { }
     75
    7576    public ClassificationEnsembleProblemData(IClassificationProblemData classificationProblemData)
    76       : base(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
    77       this.TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
    78       this.TrainingPartition.End = classificationProblemData.TrainingPartition.End;
    79       this.TestPartition.Start = classificationProblemData.TestPartition.Start;
    80       this.TestPartition.End = classificationProblemData.TestPartition.End;
    81       this.PositiveClass = classificationProblemData.PositiveClass;
     77      : base(classificationProblemData) {
    8278    }
    8379
     
    8581      : base(dataset, allowedInputVariables, targetVariable) {
    8682    }
     83
     84    public ClassificationEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<string> classNames, string positiveClass = null)
     85      : base(dataset, allowedInputVariables, targetVariable, classNames, positiveClass) {
     86    }
    8787  }
    8888}
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r17180 r17874  
    260260      evaluationCache.Clear();
    261261
    262       IClassificationProblemData problemData = new ClassificationProblemData(ProblemData.Dataset,
    263                                                                      ProblemData.AllowedInputVariables,
    264                                                                      ProblemData.TargetVariable);
    265       problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start;
    266       problemData.TrainingPartition.End = ProblemData.TrainingPartition.End;
    267       problemData.TestPartition.Start = ProblemData.TestPartition.Start;
    268       problemData.TestPartition.End = ProblemData.TestPartition.End;
     262      IClassificationProblemData problemData = new ClassificationProblemData(ProblemData);
    269263
    270264      foreach (var solution in ClassificationSolutions) {
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r17180 r17874  
    306306        classNamesCache.Add(ClassNamesParameter.Value[i, 0]);
    307307    }
     308
    308309    public override IDeepCloneable Clone(Cloner cloner) {
    309310      if (this == emptyProblemData) return emptyProblemData;
     
    311312    }
    312313
    313     public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { }
     314    public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable, Enumerable.Empty<string>()) { }
    314315
    315316    public ClassificationProblemData(IClassificationProblemData classificationProblemData)
    316       : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
     317      : this(classificationProblemData, classificationProblemData.Dataset) {
     318    }
     319
     320    /// <summary>
     321    /// This method satisfies a common use case: making a copy of the problem but providing a different dataset.
     322    /// One must be careful here that the dataset passed is not modified, as that would invalidate the problem data internals.
     323    /// Passing a ModifiableDataset to this constructor is therefore discouraged.
     324    /// </summary>
     325    /// <param name="classificationProblemData">The original instance of classification problem data.</param>
     326    /// <param name="dataset">The new dataset.</param>
     327    public ClassificationProblemData(IClassificationProblemData classificationProblemData, IDataset dataset)
     328    : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable, classificationProblemData.ClassNames, classificationProblemData.PositiveClass) {
     329
    317330      TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
    318331      TrainingPartition.End = classificationProblemData.TrainingPartition.End;
     
    320333      TestPartition.End = classificationProblemData.TestPartition.End;
    321334
    322       for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)
    323         ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);
    324 
    325       //mkommend: The positive class depends on the class names and as a result must only be set after the classe names parameter.
    326       PositiveClass = classificationProblemData.PositiveClass;
    327 
    328335      for (int i = 0; i < Classes; i++) {
    329336        for (int j = 0; j < Classes; j++) {
     
    333340    }
    334341
    335     public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
     342    public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
     343      IEnumerable<string> classNames = null,
     344      string positiveClass = null, // can be null in which case it's set as the first class name
     345      IEnumerable<ITransformation> transformations = null)
    336346      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    337347      var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList();
     
    339349
    340350      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target));
    341       Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, ""));
     351      Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix()));
    342352      Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)"));
    343353      Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, ""));
    344354
    345355      RegisterParameterEvents();
    346       ResetTargetVariableDependentMembers();
     356      ResetTargetVariableDependentMembers(); // correctly set the values of the parameters added above
     357
     358      // set the class names
     359      if (classNames != null && classNames.Any()) {
     360        // better to allocate lists because we use these multiple times below
     361        var names = classNames.ToList();
     362        var values = ClassValuesCache;
     363
     364        if (names.Count != values.Count) {
     365          throw new ArgumentException();
     366        }
     367
     368        ((IStringConvertibleMatrix)ClassNamesParameter.Value).Columns = 1;
     369        ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = names.Count;
     370
     371        for (int i = 0; i < names.Count; ++i) {
     372          SetClassName(values[i], names[i]);
     373        }
     374      }
     375
     376      // set the positive class value
     377      if (positiveClass != null) {
     378        PositiveClass = positiveClass;
     379      }
    347380    }
    348381
Note: See TracChangeset for help on using the changeset viewer.