Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/21 15:20:42 (3 years ago)
Author:
bburlacu
Message:

#3102: Add constructor taking original problem data and new dataset.

File:
1 edited

Legend:

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

    r17835 r17845  
    306306        classNamesCache.Add(ClassNamesParameter.Value[i, 0]);
    307307    }
     308
    308309    public override IDeepCloneable Clone(Cloner cloner) {
    309310      if (this == emptyProblemData) return emptyProblemData;
     
    314315
    315316    public ClassificationProblemData(IClassificationProblemData classificationProblemData)
    316       : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable, classificationProblemData.ClassNames, classificationProblemData.PositiveClass) {
    317      
     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
    318330      TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
    319331      TrainingPartition.End = classificationProblemData.TrainingPartition.End;
    320332      TestPartition.Start = classificationProblemData.TestPartition.Start;
    321333      TestPartition.End = classificationProblemData.TestPartition.End;
    322      
     334
    323335      for (int i = 0; i < Classes; i++) {
    324336        for (int j = 0; j < Classes; j++) {
     
    328340    }
    329341
    330     public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
    331       : this(dataset, allowedInputVariables, targetVariable, Enumerable.Empty<string>(), null, transformations) { }
    332 
    333342    public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
    334       IEnumerable<string> classNames,
     343      IEnumerable<string> classNames = null,
    335344      string positiveClass = null, // can be null in which case it's set as the first class name
    336345      IEnumerable<ITransformation> transformations = null)
     
    348357
    349358      // set the class names
    350       if (classNames.Any()) {
     359      if (classNames != null && classNames.Any()) {
    351360        // better to allocate lists because we use these multiple times below
    352361        var names = classNames.ToList();
    353         var values = ClassValues.ToList();
     362        var values = ClassValuesCache;
    354363
    355364        if (names.Count != values.Count) {
Note: See TracChangeset for help on using the changeset viewer.