Skip to content

kth out of bounds #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zlh1998ecnu opened this issue Jun 4, 2021 · 3 comments
Closed

kth out of bounds #96

zlh1998ecnu opened this issue Jun 4, 2021 · 3 comments

Comments

@zlh1998ecnu
Copy link

zlh1998ecnu commented Jun 4, 2021

hello guys. does anyone know how to do it? I've tried every kernel but it didn't work. I would appreciate it if you'd love to help me.
this is my first use of github so i don't know how to upload my code except copy. Sorry about that.
here is my code:

import numpy as np
import pysal as ps
from mgwr.gwr import GWR, MGWR
from mgwr.sel_bw import Sel_BW
import pandas as pd
georgia_data = pd.read_csv('C:/Users/DELL/Desktop/georgia/GData_utm.csv')                             
g_y = georgia_data['17s'].values
g_X = georgia_data[['17sr', '17gas_proportion', '17energy_intensity', '17structure', '17per_gdp', '17population']].values
u = georgia_data['X']
v = georgia_data['Y']
g_coords=list(zip(u,v))
bw=Sel_BW(g_coords, g_y, g_X, kernel='gaussian').search(criterion='AIC')
print(bw)

ValueError Traceback (most recent call last)
in
10 v = georgia_data['Y']
11 g_coords=list(zip(u,v))
---> 12 bw=Sel_BW(g_coords, g_y, g_X, kernel='gaussian').search(criterion='AIC')
13 print(bw)

F:\anaconda\lib\site-packages\mgwr\sel_bw.py in search(self, search_method, criterion, bw_min, bw_max, interval, tol, max_iter, init_multi, tol_multi, rss_score, max_iter_multi, multi_bw_min, multi_bw_max, bws_same_times, pool, verbose)
317 -1] #scalar, optimal bw from initial gwr model
318 else:
--> 319 self._bw()
320 self.sel_hist = self.bw[-1]
321

F:\anaconda\lib\site-packages\mgwr\sel_bw.py in _bw(self)
335 self.constant)
336 delta = 0.38197 #1 - (np.sqrt(5.0)-1.0)/2.0
--> 337 self.bw = golden_section(a, c, delta, gwr_func, self.tol,
338 self.max_iter, self.int_score,
339 self.verbose)

F:\anaconda\lib\site-packages\mgwr\search.py in golden_section(a, c, delta, function, tol, max_iter, int_score, verbose)
60 score_b = dict[b]
61 else:
---> 62 score_b = function(b)
63 dict[b] = score_b
64 if verbose:

F:\anaconda\lib\site-packages\mgwr\sel_bw.py in (bw)
324
325 def _bw(self):
--> 326 gwr_func = lambda bw: getDiag[self.criterion](GWR(
327 self.coords, self.y, self.X_loc, bw, family=self.family, kernel=
328 self.kernel, fixed=self.fixed, constant=self.constant, offset=self.

F:\anaconda\lib\site-packages\mgwr\gwr.py in fit(self, ini_params, tol, max_iter, solve, lite, pool)
333 rslt = map(self._local_fit, range(m)) #sequential
334
--> 335 rslt_list = list(zip(*rslt))
336 influ = np.array(rslt_list[0]).reshape(-1, 1)
337 resid = np.array(rslt_list[1]).reshape(-1, 1)

F:\anaconda\lib\site-packages\mgwr\gwr.py in _local_fit(self, i)
246 Local fitting at location i.
247 """
--> 248 wi = self._build_wi(i, self.bw).reshape(-1, 1) #local spatial weights
249
250 if isinstance(self.family, Gaussian):

F:\anaconda\lib\site-packages\mgwr\gwr.py in _build_wi(self, i, bw)
234
235 try:
--> 236 wi = Kernel(i, self.coords, bw, fixed=self.fixed,
237 function=self.kernel, points=self.points,
238 spherical=self.spherical).kernel

F:\anaconda\lib\site-packages\mgwr\kernels.py in init(self, i, data, bw, fixed, function, eps, ids, points, spherical)
54 self.bandwidth = float(bw)
55 else:
---> 56 self.bandwidth = np.partition(
57 self.dvec,
58 int(bw) - 1)[int(bw) - 1] * eps #partial sort in O(n) Time

<array_function internals> in partition(*args, **kwargs)

F:\anaconda\lib\site-packages\numpy\core\fromnumeric.py in partition(a, kth, axis, kind, order)
746 else:
747 a = asanyarray(a).copy(order="K")
--> 748 a.partition(kth, axis=axis, kind=kind, order=order)
749 return a
750

ValueError: kth(=62) out of bounds (30)

@Ziqi-Li
Copy link
Member

Ziqi-Li commented Jun 4, 2021

Hello @zlh1998ecnu, this may relate to issue #88. Also, feel free to attach a copy of the data, so we could have a closer look.

@zlh1998ecnu
Copy link
Author

zlh1998ecnu commented Jun 4, 2021 via email

@Ziqi-Li
Copy link
Member

Ziqi-Li commented Jun 4, 2021

@zlh1998ecnu Sounds good, feel free to re-open this if anything else pops up.

@Ziqi-Li Ziqi-Li closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants