comments to code
This commit is contained in:
parent
7723b52935
commit
4ee3bf5ec8
@ -15,14 +15,6 @@ def gauss_exp(ker_x, xi, h):
|
|||||||
den = h*h
|
den = h*h
|
||||||
return num/den
|
return num/den
|
||||||
|
|
||||||
def gauss_exp(ker_x, xi, h):
|
|
||||||
"""
|
|
||||||
Returns the gaussian function exponent term
|
|
||||||
"""
|
|
||||||
num = - 0.5*np.square((xi- ker_x))
|
|
||||||
den = h*h
|
|
||||||
return num/den
|
|
||||||
|
|
||||||
def kernel_function(h, ker_x, xi):
|
def kernel_function(h, ker_x, xi):
|
||||||
"""
|
"""
|
||||||
Returns the gaussian function value. Combines the gauss_const and
|
Returns the gaussian function value. Combines the gauss_const and
|
||||||
@ -48,7 +40,7 @@ def single_y_pred_gauss(bw_manual, input_x, iks, igrek):
|
|||||||
|
|
||||||
def epanechnikov_one(h, ker_x, xi):
|
def epanechnikov_one(h, ker_x, xi):
|
||||||
"""
|
"""
|
||||||
Returns the epanechnikov function value.
|
Returns the epanechnikov function value for one element.
|
||||||
"""
|
"""
|
||||||
value = 0.75*(1-np.square((xi-ker_x)/h))
|
value = 0.75*(1-np.square((xi-ker_x)/h))
|
||||||
if (value < 0):
|
if (value < 0):
|
||||||
@ -57,7 +49,7 @@ def epanechnikov_one(h, ker_x, xi):
|
|||||||
|
|
||||||
def epanechnikov_list(h, ker_x, xi):
|
def epanechnikov_list(h, ker_x, xi):
|
||||||
"""
|
"""
|
||||||
Returns the epanechnikov function value.
|
Returns the epanechnikov function value for list of elements.
|
||||||
"""
|
"""
|
||||||
value = 0.75*(1-np.square((xi-ker_x)/h))
|
value = 0.75*(1-np.square((xi-ker_x)/h))
|
||||||
value = [0 if i < 0 else i for i in value]
|
value = [0 if i < 0 else i for i in value]
|
||||||
@ -78,19 +70,19 @@ def single_y_pred_epanechnikov(bw_manual, input_x, x_values, y_values):
|
|||||||
return y_single
|
return y_single
|
||||||
|
|
||||||
def ker_reg(x_values, y_values, bw = 1, ker_fun = 'gauss'):
|
def ker_reg(x_values, y_values, bw = 1, ker_fun = 'gauss'):
|
||||||
|
"""
|
||||||
ker_x = np.arange(0,40,0.1)
|
x_values, y_values, bw = 1, ker_fun = 'gauss'
|
||||||
|
ker_fun = 'gauss' or 'epanechnikov'
|
||||||
|
returns Y_pred
|
||||||
|
"""
|
||||||
if (ker_fun == 'gauss'):
|
if (ker_fun == 'gauss'):
|
||||||
Y_pred = []
|
Y_pred = []
|
||||||
for input_x in x_values:
|
for input_x in x_values:
|
||||||
w = []
|
|
||||||
Y_single = single_y_pred_epanechnikov(bw, input_x, x_values, y_values)
|
Y_single = single_y_pred_epanechnikov(bw, input_x, x_values, y_values)
|
||||||
Y_pred.append(Y_single)
|
Y_pred.append(Y_single)
|
||||||
elif (ker_fun == 'epanechnikov'):
|
elif (ker_fun == 'epanechnikov'):
|
||||||
Y_pred = []
|
Y_pred = []
|
||||||
for input_x in x_values:
|
for input_x in x_values:
|
||||||
w = []
|
|
||||||
Y_single = single_y_pred_gauss(bw, input_x, x_values, y_values)
|
Y_single = single_y_pred_gauss(bw, input_x, x_values, y_values)
|
||||||
Y_pred.append(Y_single)
|
Y_pred.append(Y_single)
|
||||||
else:
|
else:
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user