Changeset 15249 for stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions
- Timestamp:
- 07/15/17 10:29:40 (7 years ago)
- Location:
- stable
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14862-14863,14911,14936,15156-15158,15164,15169,15207-15209,15225,15227,15234,15248
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis merged: 14862-14863,14911,14936,15156-15158,15164,15169,15207-15209,15225,15227,15234,15248
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/CicularKernel.cs
r14892 r15249 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{27 namespace HeuristicLab.Algorithms.DataAnalysis { 28 28 [StorableClass] 29 29 [Item("CircularKernel", "A circular kernel function 2*pi*(acos(-d)-d*(1-d²)^(0.5)) where n = ||x-c|| and d = n/beta \n As described in http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/")] 30 30 public class CircularKernel : KernelBase { 31 32 #region HLConstructors & Boilerplate33 31 [StorableConstructor] 34 32 protected CircularKernel(bool deserializing) : base(deserializing) { } 35 [StorableHook(HookType.AfterDeserialization)] 36 private void AfterDeserialization() { } 33 37 34 protected CircularKernel(CircularKernel original, Cloner cloner) : base(original, cloner) { } 38 public CircularKernel() { 39 } 35 36 public CircularKernel() { } 37 40 38 public override IDeepCloneable Clone(Cloner cloner) { 41 39 return new CircularKernel(this, cloner); 42 40 } 43 #endregion44 41 45 42 protected override double Get(double norm) { 43 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance while Beta is null"); 46 44 var beta = Beta.Value; 47 45 if (Math.Abs(beta) < double.Epsilon) return double.NaN; … … 53 51 // 4*pi*n^3 / (beta^4 * sqrt(1-n^2/beta^2) 54 52 protected override double GetGradient(double norm) { 53 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 55 54 var beta = Beta.Value; 56 55 if (Math.Abs(beta) < double.Epsilon) return double.NaN; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/GaussianKernel.cs
r14891 r15249 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{29 namespace HeuristicLab.Algorithms.DataAnalysis { 30 30 [StorableClass] 31 31 [Item("GaussianKernel", "A kernel function that uses Gaussian function exp(-n²/beta²). As described in http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/")] 32 32 public class GaussianKernel : KernelBase { 33 34 #region HLConstructors & Boilerplate35 33 [StorableConstructor] 36 34 protected GaussianKernel(bool deserializing) : base(deserializing) { } 37 [StorableHook(HookType.AfterDeserialization)] 38 private void AfterDeserialization() { } 35 39 36 protected GaussianKernel(GaussianKernel original, Cloner cloner) : base(original, cloner) { } 37 40 38 public GaussianKernel() { 41 39 } 40 42 41 public override IDeepCloneable Clone(Cloner cloner) { 43 42 return new GaussianKernel(this, cloner); 44 43 } 45 #endregion46 44 47 45 protected override double Get(double norm) { 46 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance while Beta is null"); 48 47 var beta = Beta.Value; 49 48 if (Math.Abs(beta) < double.Epsilon) return double.NaN; … … 54 53 //2 * n²/b²* 1/b * exp(-n²/b²) 55 54 protected override double GetGradient(double norm) { 55 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 56 56 var beta = Beta.Value; 57 57 if (Math.Abs(beta) < double.Epsilon) return double.NaN; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/IKernel.cs
r14887 r15249 21 21 22 22 23 namespace HeuristicLab.Algorithms.DataAnalysis.KernelRidgeRegression { 23 using System; 24 25 namespace HeuristicLab.Algorithms.DataAnalysis { 24 26 public interface IKernel : ICovarianceFunction { 25 27 double? Beta { get; set; } // a kernel parameter 26 28 IDistance Distance { get; set; } // the distance function to use 29 30 event EventHandler BetaChanged; 31 event EventHandler DistanceChanged; 27 32 } 28 33 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/InverseMultiquadraticKernel.cs
r14891 r15249 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{27 namespace HeuristicLab.Algorithms.DataAnalysis { 28 28 [StorableClass] 29 29 [Item("InverseMultiquadraticKernel", "A kernel function that uses the inverse multi-quadratic function 1 / sqrt(1+||x-c||²/beta²). Similar to http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/ with beta as a scaling factor.")] 30 30 public class InverseMultiquadraticKernel : KernelBase { 31 private const double C = 1.0; 31 32 32 private const double C = 1.0;33 #region HLConstructors & Boilerplate34 33 [StorableConstructor] 35 34 protected InverseMultiquadraticKernel(bool deserializing) : base(deserializing) { } 36 [StorableHook(HookType.AfterDeserialization)] 37 private void AfterDeserialization() { } 35 38 36 protected InverseMultiquadraticKernel(InverseMultiquadraticKernel original, Cloner cloner) : base(original, cloner) { } 37 39 38 public InverseMultiquadraticKernel() { } 39 40 40 public override IDeepCloneable Clone(Cloner cloner) { 41 41 return new InverseMultiquadraticKernel(this, cloner); 42 42 } 43 #endregion44 43 45 44 protected override double Get(double norm) { 45 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance while Beta is null"); 46 46 var beta = Beta.Value; 47 47 if (Math.Abs(beta) < double.Epsilon) return double.NaN; … … 52 52 //n²/(b³(n²/b² + C)^1.5) 53 53 protected override double GetGradient(double norm) { 54 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 54 55 var beta = Beta.Value; 55 56 if (Math.Abs(beta) < double.Epsilon) return double.NaN; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/KernelBase.cs
r14887 r15249 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{30 namespace HeuristicLab.Algorithms.DataAnalysis { 31 31 [StorableClass] 32 32 public abstract class KernelBase : ParameterizedNamedItem, IKernel { 33 33 34 #region Parameternames35 34 private const string DistanceParameterName = "Distance"; 36 #endregion 37 #region Parameterproperties 38 public ValueParameter<IDistance> DistanceParameter { 39 get { return Parameters[DistanceParameterName] as ValueParameter<IDistance>; } 35 36 public IValueParameter<IDistance> DistanceParameter { 37 get { return (IValueParameter<IDistance>)Parameters[DistanceParameterName]; } 40 38 } 41 39 42 40 [Storable] 43 public double? Beta { get; set; } 44 #endregion 45 #region Properties 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 } 51 46 52 public IDistance Distance { 47 53 get { return DistanceParameter.Value; } 48 set { DistanceParameter.Value = value; } 54 set { 55 if (DistanceParameter.Value != value) { 56 DistanceParameter.Value = value; 57 } 58 } 49 59 } 50 51 #endregion52 60 53 61 [StorableConstructor] 54 62 protected KernelBase(bool deserializing) : base(deserializing) { } 55 [StorableHook(HookType.AfterDeserialization)]56 private void AfterDeserialization() { }57 63 58 64 protected KernelBase(KernelBase original, Cloner cloner) 59 65 : base(original, cloner) { 60 Beta = original.Beta; 66 beta = original.beta; 67 RegisterEvents(); 61 68 } 62 69 … … 64 71 Parameters.Add(new ValueParameter<IDistance>(DistanceParameterName, "The distance function used for kernel calculation")); 65 72 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(); 66 83 } 67 84 … … 82 99 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 83 100 if (p.Length != GetNumberOfParameters(columnIndices.Length)) throw new ArgumentException("Illegal parametrization"); 84 var myClone = (KernelBase)Clone( new Cloner());101 var myClone = (KernelBase)Clone(); 85 102 myClone.SetParameter(p); 86 103 var cov = new ParameterizedCovarianceFunction { … … 101 118 return dist.Get(r1, r2); 102 119 } 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 103 135 } 104 136 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/MultiquadraticKernel.cs
r14891 r15249 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{27 namespace HeuristicLab.Algorithms.DataAnalysis { 28 28 [StorableClass] 29 29 // conditionally positive definite. (need to add polynomials) see http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf … … 32 32 33 33 private const double C = 1.0; 34 #region HLConstructors & Boilerplate 34 35 35 [StorableConstructor] 36 36 protected MultiquadraticKernel(bool deserializing) : base(deserializing) { } 37 [StorableHook(HookType.AfterDeserialization)]38 private void AfterDeserialization() { }39 protected MultiquadraticKernel(MultiquadraticKernel original, Cloner cloner)40 : base(original, cloner) { }41 37 42 public MultiquadraticKernel() { 43 } 38 protected MultiquadraticKernel(MultiquadraticKernel original, Cloner cloner) : base(original, cloner) { } 39 40 public MultiquadraticKernel() { } 41 44 42 public override IDeepCloneable Clone(Cloner cloner) { 45 43 return new MultiquadraticKernel(this, cloner); 46 44 } 47 #endregion 45 48 46 protected override double Get(double norm) { 47 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance while Beta is null"); 49 48 var beta = Beta.Value; 50 49 if (Math.Abs(beta) < double.Epsilon) return double.NaN; … … 55 54 //-n²/(d³*sqrt(C+n²/d²)) 56 55 protected override double GetGradient(double norm) { 56 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 57 57 var beta = Beta.Value; 58 58 if (Math.Abs(beta) < double.Epsilon) return double.NaN; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/PolysplineKernel.cs
r14892 r15249 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{29 namespace HeuristicLab.Algorithms.DataAnalysis { 30 30 [StorableClass] 31 31 // conditionally positive definite. (need to add polynomials) see http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf … … 33 33 public class PolysplineKernel : KernelBase { 34 34 35 #region Parameternames36 35 private const string DegreeParameterName = "Degree"; 37 #endregion 38 #region Parameterproperties 36 39 37 public IFixedValueParameter<DoubleValue> DegreeParameter { 40 get { return Parameters[DegreeParameterName] as IFixedValueParameter<DoubleValue>; }38 get { return (IFixedValueParameter<DoubleValue>)Parameters[DegreeParameterName]; } 41 39 } 42 #endregion 43 #region Properties 40 44 41 public DoubleValue Degree { 45 42 get { return DegreeParameter.Value; } 46 43 } 47 #endregion48 44 49 #region HLConstructors & Boilerplate50 45 [StorableConstructor] 51 46 protected PolysplineKernel(bool deserializing) : base(deserializing) { } 52 [StorableHook(HookType.AfterDeserialization)] 53 private void AfterDeserialization() { } 47 54 48 protected PolysplineKernel(PolysplineKernel original, Cloner cloner) : base(original, cloner) { } 49 55 50 public PolysplineKernel() { 56 51 Parameters.Add(new FixedValueParameter<DoubleValue>(DegreeParameterName, "The degree of the kernel. Needs to be greater than zero.", new DoubleValue(1.0))); 57 52 } 53 58 54 public override IDeepCloneable Clone(Cloner cloner) { 59 55 return new PolysplineKernel(this, cloner); 60 56 } 61 #endregion62 57 63 58 protected override double Get(double norm) { 59 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 64 60 var beta = Beta.Value; 65 61 if (Math.Abs(beta) < double.Epsilon) return double.NaN; … … 70 66 //-degree/beta * (norm/beta)^degree 71 67 protected override double GetGradient(double norm) { 68 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 72 69 var beta = Beta.Value; 73 70 if (Math.Abs(beta) < double.Epsilon) return double.NaN; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/ThinPlatePolysplineKernel.cs
r14892 r15249 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Algorithms.DataAnalysis .KernelRidgeRegression{29 namespace HeuristicLab.Algorithms.DataAnalysis { 30 30 [StorableClass] 31 31 // conditionally positive definite. (need to add polynomials) see http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf … … 33 33 public class ThinPlatePolysplineKernel : KernelBase { 34 34 35 #region Parameternames36 35 private const string DegreeParameterName = "Degree"; 37 #endregion 38 #region Parameterproperties 36 39 37 public IFixedValueParameter<DoubleValue> DegreeParameter { 40 get { return Parameters[DegreeParameterName] as IFixedValueParameter<DoubleValue>; }38 get { return (IFixedValueParameter<DoubleValue>)Parameters[DegreeParameterName]; } 41 39 } 42 #endregion43 #region Properties44 40 public DoubleValue Degree { 45 41 get { return DegreeParameter.Value; } 46 42 } 47 #endregion48 43 49 #region HLConstructors & Boilerplate50 44 [StorableConstructor] 51 45 protected ThinPlatePolysplineKernel(bool deserializing) : base(deserializing) { } 52 [StorableHook(HookType.AfterDeserialization)] 53 private void AfterDeserialization() { } 46 54 47 protected ThinPlatePolysplineKernel(ThinPlatePolysplineKernel original, Cloner cloner) : base(original, cloner) { } 48 55 49 public ThinPlatePolysplineKernel() { 56 50 Parameters.Add(new FixedValueParameter<DoubleValue>(DegreeParameterName, "The degree of the kernel. Needs to be greater than zero.", new DoubleValue(2.0))); 57 51 } 52 58 53 public override IDeepCloneable Clone(Cloner cloner) { 59 54 return new ThinPlatePolysplineKernel(this, cloner); 60 55 } 61 #endregion62 56 63 57 protected override double Get(double norm) { 58 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance while Beta is null"); 64 59 var beta = Beta.Value; 65 60 if (Math.Abs(beta) < double.Epsilon) return double.NaN; … … 71 66 // (Degree/beta) * (norm/beta)^Degree * log(norm/beta) 72 67 protected override double GetGradient(double norm) { 68 if (Beta == null) throw new InvalidOperationException("Can not calculate kernel distance gradient while Beta is null"); 73 69 var beta = Beta.Value; 74 70 if (Math.Abs(beta) < double.Epsilon) return double.NaN;
Note: See TracChangeset
for help on using the changeset viewer.