Beispiel #1
0
 def _mbw(self):
     y = self.y
     if self.constant:
         X = USER.check_constant(self.X_loc)
     else:
         X = self.X_loc
     n, k = X.shape
     family = self.family
     offset = self.offset
     kernel = self.kernel
     fixed = self.fixed
     coords = self.coords
     search_method = self.search_method
     criterion = self.criterion
     bw_min = self.bw_min
     bw_max = self.bw_max
     multi_bw_min = self.multi_bw_min
     multi_bw_max = self.multi_bw_max
     interval = self.interval
     tol = self.tol
     max_iter = self.max_iter
     def gwr_func(y,X,bw):
         return GWR(coords, y,X,bw,family=family, kernel=kernel, fixed=fixed,
                 offset=offset, constant=False).fit()
     def bw_func(y,X):
         return Sel_BW(coords, y,X,X_glob=[], family=family, kernel=kernel,
                 fixed=fixed, offset=offset, constant=False)
     def sel_func(bw_func, bw_min=None, bw_max=None):
         return bw_func.search(search_method=search_method, criterion=criterion,
                 bw_min=bw_min, bw_max=bw_max, interval=interval, tol=tol, max_iter=max_iter)
     self.bw = multi_bw(self.init_multi, y, X, n, k, family,
             self.tol_multi, self.max_iter_multi, self.rss_score, gwr_func,
             bw_func, sel_func, multi_bw_min, multi_bw_max)
Beispiel #2
0
 def __init__(self,
              y,
              X,
              family=family.Gaussian(),
              offset=None,
              y_fix=None,
              constant=True):
     """
     Initialize class
     """
     self.n = USER.check_arrays(y, X)
     USER.check_y(y, self.n)
     self.y = y
     if constant:
         self.X, _, _ = USER.check_constant(X)
     else:
         self.X = X
     self.family = family
     self.k = self.X.shape[1]
     if offset is None:
         self.offset = np.ones(shape=(self.n, 1))
     else:
         self.offset = offset * 1.0
     if y_fix is None:
         self.y_fix = np.zeros(shape=(self.n, 1))
     else:
         self.y_fix = y_fix
     self.fit_params = {}
Beispiel #3
0
    def _mbw(self):
        y = self.y
        if self.constant:
            X = USER.check_constant(self.X_loc)
        else:
            X = self.X_loc
        n, k = X.shape
        family = self.family
        offset = self.offset
        kernel = self.kernel
        fixed = self.fixed
        spherical = self.spherical
        coords = self.coords
        search_method = self.search_method
        criterion = self.criterion
        bw_min = self.bw_min
        bw_max = self.bw_max
        multi_bw_min = self.multi_bw_min
        multi_bw_max = self.multi_bw_max
        interval = self.interval
        tol = self.tol
        max_iter = self.max_iter
        bws_same_times = self.bws_same_times

        def gwr_func(y, X, bw):
            return GWR(coords,
                       y,
                       X,
                       bw,
                       family=family,
                       kernel=kernel,
                       fixed=fixed,
                       offset=offset,
                       constant=False,
                       spherical=self.spherical,
                       hat_matrix=False).fit(lite=True, pool=self.pool)

        def bw_func(y, X):
            selector = Sel_BW(coords,
                              y,
                              X,
                              X_glob=[],
                              family=family,
                              kernel=kernel,
                              fixed=fixed,
                              offset=offset,
                              constant=False,
                              spherical=self.spherical)
            return selector

        def sel_func(bw_func, bw_min=None, bw_max=None):
            return bw_func.search(search_method=search_method,
                                  criterion=criterion,
                                  bw_min=bw_min,
                                  bw_max=bw_max,
                                  interval=interval,
                                  tol=tol,
                                  max_iter=max_iter,
                                  pool=self.pool,
                                  verbose=False)

        self.bw = multi_bw(self.init_multi,
                           y,
                           X,
                           n,
                           k,
                           family,
                           self.tol_multi,
                           self.max_iter_multi,
                           self.rss_score,
                           gwr_func,
                           bw_func,
                           sel_func,
                           multi_bw_min,
                           multi_bw_max,
                           bws_same_times,
                           verbose=self.verbose)