Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisModel.cs @ 16332

Last change on this file since 16332 was 16332, checked in by gkronber, 5 years ago

#2915: merged r16241:16309 (current HEAD) from HL trunk to branch

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.DataAnalysis {
29  [StorableClass]
30  [Item("DataAnalysisModel", "Base class for data analysis models.")]
31  public abstract class DataAnalysisModel : NamedItem, IDataAnalysisModel {
32    [StorableConstructor]
33    protected DataAnalysisModel(bool deserializing) : base(deserializing) { }
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}
Note: See TracBrowser for help on using the repository browser.