Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs @ 13083

Last change on this file since 13083 was 13083, checked in by gkronber, 8 years ago

#1998: merged changesets r10551:13081 (only on HeuristicLab.Problems.DataAnalysis) from trunk to branch

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.DataAnalysis {
31  [StorableClass]
32  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
33  public class ConstantRegressionModel : NamedItem, IRegressionModel, IStringConvertibleValue {
34    [Storable]
35    private double constant;
36    public double Constant {
37      get { return constant; }
38      // setter not implemented because manipulation of the constant is not allowed
39    }
40
41    [StorableConstructor]
42    protected ConstantRegressionModel(bool deserializing) : base(deserializing) { }
43    protected ConstantRegressionModel(ConstantRegressionModel original, Cloner cloner)
44      : base(original, cloner) {
45      this.constant = original.constant;
46    }
47    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantRegressionModel(this, cloner); }
48
49    public ConstantRegressionModel(double constant)
50      : base() {
51      this.name = ItemName;
52      this.description = ItemDescription;
53      this.constant = constant;
54      this.ReadOnly = true; // changing a constant regression model is not supported
55    }
56
57    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
58      return rows.Select(row => Constant);
59    }
60
61    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
62      return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
63    }
64
65    public override string ToString() {
66      return string.Format("Constant: {0}", GetValue());
67    }
68
69    #region IStringConvertibleValue
70    public bool ReadOnly { get; private set; }
71    public bool Validate(string value, out string errorMessage) {
72      throw new NotSupportedException(); // changing a constant regression model is not supported
73    }
74
75    public string GetValue() {
76      return string.Format("{0:E4}", constant);
77    }
78
79    public bool SetValue(string value) {
80      throw new NotSupportedException(); // changing a constant regression model is not supported
81    }
82
83    public event EventHandler ValueChanged;
84    #endregion
85  }
86}
Note: See TracBrowser for help on using the repository browser.