Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13001


Ignore:
Timestamp:
10/14/15 17:46:45 (9 years ago)
Author:
gkronber
Message:

#1736: implemented IStringConvertibleValue interface for ConstantRegressionModel (so a view is automatically available)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r12509 r13001  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    2931  [StorableClass]
    3032  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
    31   public class ConstantRegressionModel : NamedItem, IRegressionModel {
     33  public class ConstantRegressionModel : NamedItem, IRegressionModel, IStringConvertibleValue {
    3234    [Storable]
    33     protected double constant;
     35    private double constant;
    3436    public double Constant {
    3537      get { return constant; }
     38      // setter not implemented because manipulation of the constant is not allowed
    3639    }
    3740
     
    4952      this.description = ItemDescription;
    5053      this.constant = constant;
     54      this.ReadOnly = true; // changing a constant regression model is not supported
    5155    }
    5256
     
    5862      return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
    5963    }
     64
     65    public override string ToString() {
     66      return string.Format("Constant: {0}", GetValue());
     67    }
     68
     69    #region IStringConvertibleValue
     70    public bool ReadOnly { get; private set; }
     71    public bool Validate(string value, out string errorMessage) {
     72      throw new NotSupportedException(); // changing a constant regression model is not supported
     73    }
     74
     75    public string GetValue() {
     76      return string.Format("{0:E4}", constant);
     77    }
     78
     79    public bool SetValue(string value) {
     80      throw new NotSupportedException(); // changing a constant regression model is not supported
     81    }
     82
     83    public event EventHandler ValueChanged;
     84    #endregion
    6085  }
    6186}
Note: See TracChangeset for help on using the changeset viewer.