1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HEAL.Attic;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
29 | [StorableType("EF0EF64F-392A-448A-B30F-1AE113C6CC88")]
|
---|
30 | [Item("DataAnalysisModel", "Base class for data analysis models.")]
|
---|
31 | public abstract class DataAnalysisModel : NamedItem, IDataAnalysisModel {
|
---|
32 | [StorableConstructor]
|
---|
33 | protected DataAnalysisModel(StorableConstructorFlag _) : base(_) { }
|
---|
34 | protected DataAnalysisModel(DataAnalysisModel original, Cloner cloner)
|
---|
35 | : base(original, cloner) { }
|
---|
36 | protected DataAnalysisModel() { }
|
---|
37 | protected DataAnalysisModel(string name) : base(name) { }
|
---|
38 | protected DataAnalysisModel(string name, string description) : base(name, description) { }
|
---|
39 |
|
---|
40 | public abstract IEnumerable<string> VariablesUsedForPrediction { get; }
|
---|
41 |
|
---|
42 | public virtual bool IsDatasetCompatible(IDataset dataset, out string errorMessage) {
|
---|
43 | if (dataset == null) throw new ArgumentNullException("dataset", "The provided dataset is null.");
|
---|
44 | return IsDatasetCompatible(this, dataset, out errorMessage);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public abstract bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage);
|
---|
48 |
|
---|
49 | public static bool IsDatasetCompatible(IDataAnalysisModel model, IDataset dataset, out string errorMessage) {
|
---|
50 | if(model == null) throw new ArgumentNullException("model", "The provided model is null.");
|
---|
51 | if (dataset == null) throw new ArgumentNullException("dataset", "The provided dataset is null.");
|
---|
52 | errorMessage = string.Empty;
|
---|
53 |
|
---|
54 | foreach (var variable in model.VariablesUsedForPrediction) {
|
---|
55 | if (!dataset.ContainsVariable(variable)) {
|
---|
56 | if (string.IsNullOrEmpty(errorMessage)) {
|
---|
57 | errorMessage = "The following variables must be present in the dataset for model evaluation:";
|
---|
58 | }
|
---|
59 | errorMessage += System.Environment.NewLine + " " + variable;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | return string.IsNullOrEmpty(errorMessage);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|