[13368] | 1 | #region License Information
|
---|
[7043] | 2 | /* HeuristicLab
|
---|
[13083] | 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 |
|
---|
[13083] | 22 | using System;
|
---|
[7043] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[13083] | 27 | using HeuristicLab.Data;
|
---|
[7043] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
[13368] | 31 | [StorableClass("529C52FD-3D61-434D-BDD6-CCB92AA7BF5B")]
|
---|
[13098] | 32 | [Item("Constant Model", "A model that always returns the same constant value regardless of the presented input data.")]
|
---|
| 33 | public class ConstantModel : NamedItem, IRegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {
|
---|
[7043] | 34 | [Storable]
|
---|
[13083] | 35 | private double constant;
|
---|
[7043] | 36 | public double Constant {
|
---|
| 37 | get { return constant; }
|
---|
[13083] | 38 | // setter not implemented because manipulation of the constant is not allowed
|
---|
[7043] | 39 | }
|
---|
| 40 |
|
---|
| 41 | [StorableConstructor]
|
---|
[13098] | 42 | protected ConstantModel(bool deserializing) : base(deserializing) { }
|
---|
| 43 | protected ConstantModel(ConstantModel original, Cloner cloner)
|
---|
[7043] | 44 | : base(original, cloner) {
|
---|
| 45 | this.constant = original.constant;
|
---|
| 46 | }
|
---|
[13098] | 47 | public override IDeepCloneable Clone(Cloner cloner) { return new ConstantModel(this, cloner); }
|
---|
[7043] | 48 |
|
---|
[13098] | 49 | public ConstantModel(double constant)
|
---|
[7043] | 50 | : base() {
|
---|
| 51 | this.name = ItemName;
|
---|
| 52 | this.description = ItemDescription;
|
---|
| 53 | this.constant = constant;
|
---|
[13083] | 54 | this.ReadOnly = true; // changing a constant regression model is not supported
|
---|
[7043] | 55 | }
|
---|
| 56 |
|
---|
[13083] | 57 | public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
|
---|
[7043] | 58 | return rows.Select(row => Constant);
|
---|
| 59 | }
|
---|
[13098] | 60 | public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
|
---|
| 61 | return GetEstimatedValues(dataset, rows);
|
---|
| 62 | }
|
---|
| 63 | public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {
|
---|
| 64 | return rows.Select(_ => horizons.Select(__ => Constant));
|
---|
| 65 | }
|
---|
[7043] | 66 |
|
---|
| 67 | public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
|
---|
[8528] | 68 | return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
|
---|
[7043] | 69 | }
|
---|
[13098] | 70 | public IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
|
---|
| 71 | return new ConstantClassificationSolution(this, new ClassificationProblemData(problemData));
|
---|
| 72 | }
|
---|
| 73 | public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) {
|
---|
| 74 | return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData));
|
---|
| 75 | }
|
---|
[13083] | 76 |
|
---|
| 77 | public override string ToString() {
|
---|
| 78 | return string.Format("Constant: {0}", GetValue());
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | #region IStringConvertibleValue
|
---|
| 82 | public bool ReadOnly { get; private set; }
|
---|
| 83 | public bool Validate(string value, out string errorMessage) {
|
---|
[13097] | 84 | throw new NotSupportedException(); // changing a constant regression model is not supported
|
---|
[13083] | 85 | }
|
---|
| 86 |
|
---|
| 87 | public string GetValue() {
|
---|
| 88 | return string.Format("{0:E4}", constant);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public bool SetValue(string value) {
|
---|
[13097] | 92 | throw new NotSupportedException(); // changing a constant regression model is not supported
|
---|
[13083] | 93 | }
|
---|
| 94 |
|
---|
| 95 | public event EventHandler ValueChanged;
|
---|
| 96 | #endregion
|
---|
[13098] | 97 |
|
---|
[7043] | 98 | }
|
---|
| 99 | }
|
---|