Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15157 for trunk


Ignore:
Timestamp:
07/06/17 13:21:00 (7 years ago)
Author:
gkronber
Message:

#2699: added events for BetaChanged and DistanceChanged

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/IKernel.cs

    r14936 r15157  
    2121
    2222
     23using System;
     24
    2325namespace HeuristicLab.Algorithms.DataAnalysis {
    2426  public interface IKernel : ICovarianceFunction {
    2527    double? Beta { get; set; } // a kernel parameter
    2628    IDistance Distance { get; set; } // the distance function to use
     29
     30    event EventHandler BetaChanged;
     31    event EventHandler DistanceChanged;
    2732  }
    2833}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/KernelBase.cs

    r15156 r15157  
    3434    private const string DistanceParameterName = "Distance";
    3535
    36     public ValueParameter<IDistance> DistanceParameter {
    37       get { return Parameters[DistanceParameterName] as ValueParameter<IDistance>; }
     36    public IValueParameter<IDistance> DistanceParameter {
     37      get { return (IValueParameter<IDistance>)Parameters[DistanceParameterName]; }
    3838    }
    3939
    4040    [Storable]
    41     public double? Beta { get; set; }
     41    private double? beta;
     42    public double? Beta {
     43      get { return beta; }
     44      set {
     45        if (value != beta) {
     46          beta = value;
     47          RaiseBetaChanged();
     48        }
     49      }
     50    }
    4251
    4352    public IDistance Distance {
    4453      get { return DistanceParameter.Value; }
    45       set { DistanceParameter.Value = value; }
     54      set {
     55        if (DistanceParameter.Value != value) {
     56          DistanceParameter.Value = value;
     57        }
     58      }
    4659    }
    4760
     
    5164    protected KernelBase(KernelBase original, Cloner cloner)
    5265      : base(original, cloner) {
    53       Beta = original.Beta;
     66      beta = original.beta;
     67      RegisterEvents();
    5468    }
    5569
     
    5771      Parameters.Add(new ValueParameter<IDistance>(DistanceParameterName, "The distance function used for kernel calculation"));
    5872      DistanceParameter.Value = new EuclideanDistance();
     73      RegisterEvents();
     74    }
     75
     76    [StorableHook(HookType.AfterDeserialization)]
     77    private void AfterDeserialization() {
     78      RegisterEvents();
     79    }
     80
     81    private void RegisterEvents() {
     82      DistanceParameter.ValueChanged += (sender, args) => RaiseDistanceChanged();
    5983    }
    6084
     
    94118      return dist.Get(r1, r2);
    95119    }
     120
     121    #region events
     122    public event EventHandler BetaChanged;
     123    public event EventHandler DistanceChanged;
     124
     125    protected void RaiseBetaChanged() {
     126      var handler = BetaChanged;
     127      if (handler != null) handler(this, EventArgs.Empty);
     128    }
     129
     130    protected void RaiseDistanceChanged() {
     131      var handler = DistanceChanged;
     132      if (handler != null) handler(this, EventArgs.Empty);
     133    }
     134    #endregion
    96135  }
    97136}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/PolysplineKernel.cs

    r15156 r15157  
    3636
    3737    public IFixedValueParameter<DoubleValue> DegreeParameter {
    38       get { return Parameters[DegreeParameterName] as IFixedValueParameter<DoubleValue>; }
     38      get { return (IFixedValueParameter<DoubleValue>)Parameters[DegreeParameterName]; }
    3939    }
    4040
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/ThinPlatePolysplineKernel.cs

    r15156 r15157  
    3636
    3737    public IFixedValueParameter<DoubleValue> DegreeParameter {
    38       get { return Parameters[DegreeParameterName] as IFixedValueParameter<DoubleValue>; }
     38      get { return (IFixedValueParameter<DoubleValue>)Parameters[DegreeParameterName]; }
    3939    }
    4040    public DoubleValue Degree {
Note: See TracChangeset for help on using the changeset viewer.