Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs @ 16640

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

#2971: merged r16565:16631 from trunk/HeuristicLab.Problems.DataAnalysis to branch/HeuristicLab.Problems.DataAnalysis (resolving all conflicts)

File size: 3.5 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HEAL.Attic;
29using HEAL.Attic;
30
31namespace HeuristicLab.Problems.DataAnalysis {
32  [StorableType("E4C0D707-F668-428F-951C-F82A475177BE")]
33  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
34  [Obsolete]
35  public class ConstantRegressionModel : RegressionModel, IStringConvertibleValue {
36    public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
37
38    [Storable]
39    private double constant;
40    public double Constant {
41      get { return constant; }
42      // setter not implemented because manipulation of the constant is not allowed
43    }
44
45    [StorableConstructor]
46    protected ConstantRegressionModel(StorableConstructorFlag _) : base(_) { }
47    protected ConstantRegressionModel(ConstantRegressionModel original, Cloner cloner)
48      : base(original, cloner) {
49      this.constant = original.constant;
50    }
51
52    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantRegressionModel(this, cloner); }
53
54    public ConstantRegressionModel(double constant, string targetVariable)
55      : base(targetVariable) {
56      this.name = ItemName;
57      this.description = ItemDescription;
58      this.constant = constant;
59      this.ReadOnly = true; // changing a constant regression model is not supported
60    }
61
62    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
63      return rows.Select(row => Constant);
64    }
65
66    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
67      return new ConstantRegressionSolution(new ConstantModel(constant, TargetVariable), new RegressionProblemData(problemData));
68    }
69
70    public override string ToString() {
71      return string.Format("Constant: {0}", GetValue());
72    }
73
74    #region IStringConvertibleValue
75    public bool ReadOnly { get; private set; }
76    public bool Validate(string value, out string errorMessage) {
77      throw new NotSupportedException(); // changing a constant regression model is not supported
78    }
79
80    public string GetValue() {
81      return string.Format("{0:E4}", constant);
82    }
83
84    public bool SetValue(string value) {
85      throw new NotSupportedException(); // changing a constant regression model is not supported
86    }
87
88#pragma warning disable 0067
89    public event EventHandler ValueChanged;
90#pragma warning restore 0067
91    #endregion
92  }
93}
Note: See TracBrowser for help on using the repository browser.