1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
31 | [StorableClass]
|
---|
32 | [Item("Confidence Constant Model", "A model that always returns the same constant mean value and variance regardless of the presented input data.")]
|
---|
33 | public class ConfidenceConstantModel : RegressionModel, IConfidenceRegressionModel, IStringConvertibleValue {
|
---|
34 | public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
|
---|
35 |
|
---|
36 |
|
---|
37 | [Storable]
|
---|
38 | private readonly double constant;
|
---|
39 | public double Constant {
|
---|
40 | get { return constant; }
|
---|
41 | // setter not implemented because manipulation of the constant is not allowed
|
---|
42 | }
|
---|
43 |
|
---|
44 | [Storable]
|
---|
45 | private readonly double variance;
|
---|
46 | public double Variance {
|
---|
47 | get { return variance; }
|
---|
48 | // setter not implemented because manipulation of the variance is not allowed
|
---|
49 | }
|
---|
50 |
|
---|
51 | [StorableConstructor]
|
---|
52 | protected ConfidenceConstantModel(bool deserializing) : base(deserializing) { }
|
---|
53 | protected ConfidenceConstantModel(ConfidenceConstantModel original, Cloner cloner)
|
---|
54 | : base(original, cloner) {
|
---|
55 | this.constant = original.constant;
|
---|
56 | this.variance = original.variance;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override IDeepCloneable Clone(Cloner cloner) { return new ConfidenceConstantModel(this, cloner); }
|
---|
60 |
|
---|
61 | public ConfidenceConstantModel(double constant, double variance, string targetVariable)
|
---|
62 | : base(targetVariable) {
|
---|
63 | this.name = ItemName;
|
---|
64 | this.description = ItemDescription;
|
---|
65 | this.constant = constant;
|
---|
66 | this.variance = variance;
|
---|
67 | this.ReadOnly = true; // changing a constant regression model is not supported
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
|
---|
71 | return rows.Select(row => Constant);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public IEnumerable<double> GetEstimatedVariances(IDataset dataset, IEnumerable<int> rows) {
|
---|
75 | return rows.Select(x => Variance);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
|
---|
79 | return new ConfidenceRegressionSolution(this, new RegressionProblemData(problemData));
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override string ToString() {
|
---|
83 | return string.Format("Constant: {0:E4}, Variance: {1:E4}", Constant, Variance);
|
---|
84 | }
|
---|
85 |
|
---|
86 | #region IStringConvertibleValue
|
---|
87 | public bool ReadOnly { get; private set; }
|
---|
88 | public bool Validate(string value, out string errorMessage) {
|
---|
89 | throw new NotSupportedException(); // changing a constant regression model is not supported
|
---|
90 | }
|
---|
91 |
|
---|
92 | public string GetValue() {
|
---|
93 | return string.Format("{0:E4}", constant);
|
---|
94 | }
|
---|
95 |
|
---|
96 | public bool SetValue(string value) {
|
---|
97 | throw new NotSupportedException(); // changing a constant regression model is not supported
|
---|
98 | }
|
---|
99 |
|
---|
100 | #pragma warning disable 0067
|
---|
101 | public event EventHandler ValueChanged;
|
---|
102 | #pragma warning restore 0067
|
---|
103 | #endregion
|
---|
104 | }
|
---|
105 | }
|
---|