Free cookie consent management tool by TermsFeed Policy Generator

source: branches/M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/LeafTypes/LogisticLeaf.cs @ 15470

Last change on this file since 15470 was 15430, checked in by bwerth, 6 years ago

#2847 first implementation of M5'-regression

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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.Linq;
24using System.Threading;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.DataAnalysis;
31
32namespace HeuristicLab.Algorithms.DataAnalysis {
33  [StorableClass]
34  [Item("LogisticLeaf", "A leaf type that uses linear models with a logistic dampening as leaf models. Dampening reduces prediction values far outside the observed target values.")]
35  public class LogisticLeaf : ParameterizedNamedItem, ILeafType<IConfidenceRegressionModel> {
36    private const string DampeningParameterName = "Dampening";
37    public IFixedValueParameter<DoubleValue> DampeningParameter {
38      get { return Parameters[DampeningParameterName] as IFixedValueParameter<DoubleValue>; }
39    }
40    public double Dampening {
41      get { return DampeningParameter.Value.Value; }
42    }
43
44    #region Constructors & Cloning
45    [StorableConstructor]
46    private LogisticLeaf(bool deserializing) : base(deserializing) { }
47    private LogisticLeaf(LogisticLeaf original, Cloner cloner) : base(original, cloner) { }
48    public LogisticLeaf() {
49      Parameters.Add(new FixedValueParameter<DoubleValue>(DampeningParameterName, "Determines the strenght of the logistic dampening. Must be  > 0.0. Larger numbers make more conservative predictions.", new DoubleValue(1.5)));
50    }
51    public override IDeepCloneable Clone(Cloner cloner) {
52      return new LogisticLeaf(this, cloner);
53    }
54    #endregion
55
56    #region IModelType
57    public IConfidenceRegressionModel BuildModel(IRegressionProblemData pd, IRandom random, CancellationToken cancellation, out int noParameters) {
58      if (pd.Dataset.Rows < MinLeafSize(pd)) throw new ArgumentException("The number of training instances is too small to create a linear model");
59      double rmse, cvRmse;
60      noParameters = pd.AllowedInputVariables.Count() + 1;
61      return new DampenedLinearModel(PreconstructedLinearModel.CreateConfidenceLinearModel(pd, out rmse, out cvRmse), pd, Dampening);
62    }
63
64    public int MinLeafSize(IRegressionProblemData pd) {
65      return pd.AllowedInputVariables.Count() + 2;
66    }
67    #endregion
68  }
69}
Note: See TracBrowser for help on using the repository browser.