Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs @ 17590

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

#2875: Removed years in copyrights

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