Changeset 18006 for branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
- Timestamp:
- 07/13/21 10:55:09 (3 years ago)
- Location:
- branches/3087_Ceres_Integration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3087_Ceres_Integration
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r17180 r18006 306 306 classNamesCache.Add(ClassNamesParameter.Value[i, 0]); 307 307 } 308 308 309 public override IDeepCloneable Clone(Cloner cloner) { 309 310 if (this == emptyProblemData) return emptyProblemData; … … 311 312 } 312 313 313 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable ) { }314 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable, Enumerable.Empty<string>()) { } 314 315 315 316 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 317 330 TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 318 331 TrainingPartition.End = classificationProblemData.TrainingPartition.End; … … 320 333 TestPartition.End = classificationProblemData.TestPartition.End; 321 334 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 328 335 for (int i = 0; i < Classes; i++) { 329 336 for (int j = 0; j < Classes; j++) { … … 333 340 } 334 341 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) 336 346 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 337 347 var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList(); … … 339 349 340 350 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())); 342 352 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)")); 343 353 Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "")); 344 354 345 355 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 } 347 380 } 348 381
Note: See TracChangeset
for help on using the changeset viewer.