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