Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisModel.cs @ 17912

Last change on this file since 17912 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 2.8 KB
RevLine 
[13941]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13941]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
[16243]22using System;
[13941]23using System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
[16565]26using HEAL.Attic;
[13941]27
28namespace HeuristicLab.Problems.DataAnalysis {
[16565]29  [StorableType("EF0EF64F-392A-448A-B30F-1AE113C6CC88")]
[13941]30  [Item("DataAnalysisModel", "Base class for data analysis models.")]
31  public abstract class DataAnalysisModel : NamedItem, IDataAnalysisModel {
32    [StorableConstructor]
[16565]33    protected DataAnalysisModel(StorableConstructorFlag _) : base(_) { }
[13941]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; }
[16243]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    }
[13941]65  }
66}
Note: See TracBrowser for help on using the repository browser.