Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisModel.cs @ 16628

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

#2971: made branch compile with current version of trunk

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;
27using HEAL.Attic;
28
29namespace HeuristicLab.Problems.DataAnalysis {
30  [StorableType("1CD73B5F-82EF-4FA1-A85E-0394EBD05BF4")]
31  [Item("DataAnalysisModel", "Base class for data analysis models.")]
32  public abstract class DataAnalysisModel : NamedItem, IDataAnalysisModel {
33    [StorableConstructor]
34    protected DataAnalysisModel(StorableConstructorFlag _) : base(_) { }
35    protected DataAnalysisModel(DataAnalysisModel original, Cloner cloner)
36      : base(original, cloner) { }
37    protected DataAnalysisModel() { }
38    protected DataAnalysisModel(string name) : base(name) { }
39    protected DataAnalysisModel(string name, string description) : base(name, description) { }
40
41    public abstract IEnumerable<string> VariablesUsedForPrediction { get; }
42
43    public virtual bool IsDatasetCompatible(IDataset dataset, out string errorMessage) {
44      if (dataset == null) throw new ArgumentNullException("dataset", "The provided dataset is null.");
45      return IsDatasetCompatible(this, dataset, out errorMessage);
46    }
47
48    public abstract bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage);
49
50    public static bool IsDatasetCompatible(IDataAnalysisModel model, IDataset dataset, out string errorMessage) {
51      if(model == null) throw new ArgumentNullException("model", "The provided model is null.");
52      if (dataset == null) throw new ArgumentNullException("dataset", "The provided dataset is null.");
53      errorMessage = string.Empty;
54
55      foreach (var variable in model.VariablesUsedForPrediction) {
56        if (!dataset.ContainsVariable(variable)) {
57          if (string.IsNullOrEmpty(errorMessage)) {
58            errorMessage = "The following variables must be present in the dataset for model evaluation:";
59          }
60          errorMessage += System.Environment.NewLine + " " + variable;
61        }
62      }
63
64      return string.IsNullOrEmpty(errorMessage);
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.