Changeset 14891 for branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions
- Timestamp:
- 04/26/17 11:06:51 (8 years ago)
- Location:
- branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/CicularKernel.cs
r14887 r14891 27 27 namespace HeuristicLab.Algorithms.DataAnalysis.KernelRidgeRegression { 28 28 [StorableClass] 29 [Item("CircularKernel", "A circular kernel function 2*pi*(acos(-d)-d*(1- n²)^(0.5)) where n = ||x-c|| and d = n/beta")]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 31 … … 45 45 protected override double Get(double norm) { 46 46 var beta = Beta.Value; 47 if (Math.Abs( beta) < double.Epsilon) return double.NaN;48 if (norm >= beta) return 0;47 if (Math.Abs(Beta.Value) < double.Epsilon) return double.NaN; 48 if (norm >= Beta.Value) return 0; 49 49 var d = norm / beta; 50 return Math.Acos(-d) - d * Math.Sqrt(1 - d * d) - Math.PI / 2;50 return 2 * Math.PI * (Math.Acos(-d) - d * Math.Sqrt(1 - d * d)); 51 51 } 52 52 53 // 4*pi*n^3 / (beta^4 * sqrt(1-n^2/beta^2) 53 54 protected override double GetGradient(double norm) { 54 55 var beta = Beta.Value; 55 56 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 56 57 if (beta < norm) return 0; 57 return -2 * Math.Pow(norm, 3) / (Math.Pow(beta, 4) * Math.Sqrt(1 - norm * norm / (beta * beta))); 58 var d = norm / beta; 59 return -4 * Math.PI * d * d * d / beta * Math.Sqrt(1 - d * d); 58 60 } 59 61 } -
branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/GaussianKernel.cs
r14887 r14891 29 29 namespace HeuristicLab.Algorithms.DataAnalysis.KernelRidgeRegression { 30 30 [StorableClass] 31 [Item("GaussianKernel", "A kernel function that uses Gaussian function exp(- ||x-c||/beta²). Positive definite beta > 0")]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 33 … … 48 48 var beta = Beta.Value; 49 49 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 50 return Math.Exp(-norm * norm / (beta * beta)); 50 var d = norm / beta; 51 return Math.Exp(-d * d); 51 52 } 52 53 54 //2 * n²/b²* 1/b * exp(-n²/b²) 53 55 protected override double GetGradient(double norm) { 54 56 var beta = Beta.Value; 55 57 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 56 return 2 * norm * norm / Math.Pow(beta, 3) * Math.Exp(-norm * norm / (beta * beta)); 58 var d = norm / beta; 59 return 2 * d * d / beta * Math.Exp(-d * d); 57 60 } 58 61 } -
branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/InverseMultiquadraticKernel.cs
r14887 r14891 22 22 using System; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 27 namespace HeuristicLab.Algorithms.DataAnalysis.KernelRidgeRegression { 28 28 [StorableClass] 29 [Item("InverseMultiquadraticKernel", "A kernel function that uses the inverse multi-quadratic function 1 / sqrt(1+||x-c|| ^2/beta). Positive definite: beta > 0")]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 32 private const double C = 1.0; 31 33 #region HLConstructors & Boilerplate 32 34 [StorableConstructor] … … 35 37 private void AfterDeserialization() { } 36 38 protected InverseMultiquadraticKernel(InverseMultiquadraticKernel original, Cloner cloner) : base(original, cloner) { } 37 public InverseMultiquadraticKernel() { 38 } 39 public InverseMultiquadraticKernel() { } 39 40 public override IDeepCloneable Clone(Cloner cloner) { 40 41 return new InverseMultiquadraticKernel(this, cloner); … … 45 46 var beta = Beta.Value; 46 47 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 47 return 1 / Math.Sqrt(1 + norm * norm / beta); 48 var d = norm / beta; 49 return 1 / Math.Sqrt(C + d * d); 48 50 } 49 51 52 //n²/(b³(n²/b² + C)^1.5) 50 53 protected override double GetGradient(double norm) { 51 54 var beta = Beta.Value; 52 55 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 53 return norm * norm / (2 * beta * beta * Math.Pow((norm * norm + beta) / beta, 1.5)); 56 var d = norm / beta; 57 return d * d / (beta * Math.Pow(d * d + C, 1.5)); 54 58 } 55 59 } -
branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/MultiquadraticKernel.cs
r14887 r14891 22 22 using System; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 … … 28 28 [StorableClass] 29 29 // conditionally positive definite. (need to add polynomials) see http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf 30 [Item("MultiquadraticKernel", "A kernel function that uses the multi-quadratic function (sqrt(1+||x-c||²/β).")]30 [Item("MultiquadraticKernel", "A kernel function that uses the multi-quadratic function 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.")] 31 31 public class MultiquadraticKernel : KernelBase { 32 32 33 private const double C = 1.0; 33 34 #region HLConstructors & Boilerplate 34 35 [StorableConstructor] … … 48 49 var beta = Beta.Value; 49 50 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 50 return Math.Sqrt(1 + norm * norm / beta); 51 var d = norm / beta; 52 return Math.Sqrt(C + d * d); 51 53 } 52 54 55 //-n²/(d³*sqrt(C+n²/d²)) 53 56 protected override double GetGradient(double norm) { 54 57 var beta = Beta.Value; 55 58 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 56 var d ividend = 2 * beta * beta * Math.Sqrt((beta + norm * norm) / beta);57 return - norm * norm / dividend;59 var d = norm / beta; 60 return -d * d / (beta * Math.Sqrt(C + d * d)); 58 61 } 59 62 } -
branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/PolysplineKernel.cs
r14887 r14891 22 22 using System; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 26 using HeuristicLab.Parameters; 25 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 28 … … 28 30 [StorableClass] 29 31 // conditionally positive definite. (need to add polynomials) see http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf 30 [Item("PolysplineKernel", "A kernel function that uses the poly -spline function ||x-c||^Beta.")]32 [Item("PolysplineKernel", "A kernel function that uses the polyharmonic function (||x-c||/Beta)^Degree as given in http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf with beta as a scaling parameters.")] 31 33 public class PolysplineKernel : KernelBase { 34 35 #region Parameternames 36 private const string DegreeParameterName = "Degree"; 37 #endregion 38 #region Parameterproperties 39 public IFixedValueParameter<DoubleValue> DegreeParameter 40 { 41 get { return Parameters[DegreeParameterName] as IFixedValueParameter<DoubleValue>; } 42 } 43 #endregion 44 #region Properties 45 public DoubleValue Degree 46 { 47 get { return DegreeParameter.Value; } 48 } 49 #endregion 32 50 33 51 #region HLConstructors & Boilerplate … … 36 54 [StorableHook(HookType.AfterDeserialization)] 37 55 private void AfterDeserialization() { } 38 protected PolysplineKernel(PolysplineKernel original, Cloner cloner) 39 : base(original, cloner) { } 56 protected PolysplineKernel(PolysplineKernel original, Cloner cloner) : base(original, cloner) { } 40 57 public PolysplineKernel() { 58 Parameters.Add(new FixedValueParameter<DoubleValue>(DegreeParameterName, "The degree of the kernel. Needs to be greater than zero.", new DoubleValue(1.0))); 41 59 } 42 60 public override IDeepCloneable Clone(Cloner cloner) { … … 46 64 47 65 protected override double Get(double norm) { 48 return Math.Pow(norm, Beta.Value); 66 var beta = Beta.Value; 67 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 68 var d = norm / beta; 69 return Math.Pow(d, Degree.Value); 49 70 } 50 71 72 //-degree/beta * (norm/beta)^degree 51 73 protected override double GetGradient(double norm) { 52 return Math.Pow(norm, Beta.Value) * Math.Log(norm); 74 var beta = Beta.Value; 75 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 76 var d = norm / beta; 77 return -Degree.Value / beta * Math.Pow(d, Degree.Value); 53 78 } 54 79 } -
branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelFunctions/ThinPlatePolysplineKernel.cs
r14887 r14891 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 26 using HeuristicLab.Parameters; 25 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 28 … … 28 30 [StorableClass] 29 31 // conditionally positive definite. (need to add polynomials) see http://num.math.uni-goettingen.de/schaback/teaching/sc.pdf 30 [Item("ThinPlatePolysplineKernel", "A kernel function that uses the ThinPlatePolyspline function ||x-c||^(2*Beta)*log(||x-c||^Beta)")]32 [Item("ThinPlatePolysplineKernel", "A kernel function that uses the ThinPlatePolyspline function (||x-c||/Beta)^(Degree)*log(||x-c||/Beta) as described in \"Thin-Plate Spline Radial Basis Function Scheme for Advection-Diffusion Problems\" with beta as a scaling parameter.")] 31 33 public class ThinPlatePolysplineKernel : KernelBase { 34 35 #region Parameternames 36 private const string DegreeParameterName = "Degree"; 37 #endregion 38 #region Parameterproperties 39 public IFixedValueParameter<DoubleValue> DegreeParameter 40 { 41 get { return Parameters[DegreeParameterName] as IFixedValueParameter<DoubleValue>; } 42 } 43 #endregion 44 #region Properties 45 public DoubleValue Degree 46 { 47 get { return DegreeParameter.Value; } 48 } 49 #endregion 50 32 51 #region HLConstructors & Boilerplate 33 52 [StorableConstructor] … … 37 56 protected ThinPlatePolysplineKernel(ThinPlatePolysplineKernel original, Cloner cloner) : base(original, cloner) { } 38 57 public ThinPlatePolysplineKernel() { 58 Parameters.Add(new FixedValueParameter<DoubleValue>(DegreeParameterName, "The degree of the kernel. Needs to be greater than zero.", new DoubleValue(2.0))); 39 59 } 40 60 public override IDeepCloneable Clone(Cloner cloner) { … … 45 65 protected override double Get(double norm) { 46 66 var beta = Beta.Value; 47 if (Math.Pow(norm, beta) < 0) return double.NaN; 48 return Math.Pow(norm, 2 * beta) * Math.Log(1 + Math.Pow(norm, beta)); 67 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 68 var d = norm / beta; 69 if (Math.Abs(d) < double.Epsilon) return 0; 70 return Math.Pow(d, Degree.Value) * Math.Log(d); 49 71 } 50 72 73 // (Degree/beta) * (norm/beta)^Degree * log(norm/beta) 51 74 protected override double GetGradient(double norm) { 52 75 var beta = Beta.Value; 53 if (Math.Pow(norm, beta) <= 0) return double.NaN; 54 return 2 * Math.Log(norm) * Math.Pow(norm, 2 * beta) * Math.Log(1 + Math.Pow(norm, beta)) + Math.Pow(norm, 3 * beta) * Math.Log(norm) / (Math.Pow(norm, beta) + 1); 76 if (Math.Abs(beta) < double.Epsilon) return double.NaN; 77 var d = norm / beta; 78 if (Math.Abs(d) < double.Epsilon) return 0; 79 return Degree.Value / beta * Math.Pow(d, Degree.Value) * Math.Log(d); 55 80 } 56 81 }
Note: See TracChangeset
for help on using the changeset viewer.