File indexing completed on 2024-05-12 15:27:09
0001 /*************************************************************************** 0002 File : nsl_sf_kernel.c 0003 Project : LabPlot 0004 Description : NSL special kernel functions 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2016 by Stefan Gerlach (stefan.gerlach@uni.kn) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #include "nsl_sf_kernel.h" 0030 #include <stdlib.h> 0031 #include <math.h> 0032 #include <gsl/gsl_math.h> 0033 #include <gsl/gsl_randist.h> /* Gaussian and Cauchy */ 0034 0035 /* kernel on [-1,1] */ 0036 0037 double nsl_sf_kernel_uniform(double u) { 0038 if(fabs(u) <= 1.0) 0039 return 0.5; 0040 return 0.0; 0041 } 0042 0043 double nsl_sf_kernel_triangular(double u) { 0044 if(fabs(u) <= 1.0) 0045 return 1.0-fabs(u); 0046 return 0.0; 0047 } 0048 0049 double nsl_sf_kernel_parabolic(double u) { 0050 if(fabs(u) <= 1.0) 0051 return 3./4.*(1.0-gsl_pow_2(u)); 0052 return 0.0; 0053 } 0054 0055 double nsl_sf_kernel_quartic(double u) { 0056 if(fabs(u) <= 1.0) 0057 return 15./16.*gsl_pow_2(1.0-gsl_pow_2(u)); 0058 return 0.0; 0059 } 0060 0061 double nsl_sf_kernel_triweight(double u) { 0062 if(fabs(u) <= 1.0) 0063 return 35./32.*gsl_pow_3(1.0-gsl_pow_2(u)); 0064 return 0.0; 0065 } 0066 0067 double nsl_sf_kernel_tricube(double u) { 0068 if(fabs(u) <= 1.0) 0069 return 70./81.*gsl_pow_3(1.0-gsl_pow_3(fabs(u))); 0070 return 0.0; 0071 } 0072 0073 double nsl_sf_kernel_cosine(double u) { 0074 if(fabs(u) <= 1.0) 0075 return M_PI_4*cos(M_PI_2*u); 0076 return 0.0; 0077 } 0078 0079 double nsl_sf_kernel_semicircle(double u) { 0080 if(fabs(u) < 1.0) 0081 return M_2_PI*sqrt(1-gsl_pow_2(u)); 0082 return 0.0; 0083 } 0084 0085 /* kernel on (-inf,inf) */ 0086 double nsl_sf_kernel_gaussian(double u) { 0087 return gsl_ran_gaussian_pdf(u, 1.0); 0088 } 0089 0090 double nsl_sf_kernel_cauchy(double u) { 0091 return gsl_ran_cauchy_pdf(u, 1.0); 0092 } 0093 0094 double nsl_sf_kernel_logistic(double u) { 0095 return gsl_ran_logistic_pdf(u, 1.0); 0096 } 0097 0098 double nsl_sf_kernel_picard(double u) { 0099 return 0.5*exp(-fabs(u)); 0100 } 0101 0102 double nsl_sf_kernel_sigmoid(double u) { 0103 return M_1_PI/cosh(u); 0104 } 0105 0106 double nsl_sf_kernel_silverman(double u) { 0107 return 1.0/2.0*exp(-fabs(u)/M_SQRT2)*sin(fabs(u)/M_SQRT2+M_PI_4); 0108 }