Beispiel #1
0
 def __init__(self,
              coords,
              y,
              X,
              bw,
              family=Gaussian(),
              offset=None,
              sigma2_v1=False,
              kernel='bisquare',
              fixed=False,
              constant=True):
     """
     Initialize class
     """
     GLM.__init__(self, y, X, family, constant=constant)
     self.constant = constant
     self.sigma2_v1 = sigma2_v1
     self.coords = coords
     self.bw = bw
     self.kernel = kernel
     self.fixed = fixed
     if offset is None:
         self.offset = np.ones((self.n, 1))
     else:
         self.offset = offset * 1.0
     self.fit_params = {}
     self.W = self._build_W(fixed, kernel, coords, bw)
     self.points = None
     self.exog_scale = None
     self.exog_resid = None
     self.P = None
Beispiel #2
0
 def __init__(self,
              coords,
              y,
              X_loc,
              X_glob=None,
              family=Gaussian(),
              offset=None,
              kernel='bisquare',
              fixed=False,
              multi=False,
              constant=True,
              spherical=False):
     self.coords = coords
     self.y = y
     self.X_loc = X_loc
     if X_glob is not None:
         self.X_glob = X_glob
     else:
         self.X_glob = []
     self.family = family
     self.fixed = fixed
     self.kernel = kernel
     if offset is None:
         self.offset = np.ones((len(y), 1))
     else:
         self.offset = offset * 1.0
     self.multi = multi
     self._functions = []
     self.constant = constant
     self.spherical = spherical
     self._build_dMat()
     self.search_params = {}
Beispiel #3
0
 def __init__(self,
              coords,
              y,
              X_loc,
              X_glob=None,
              family=Gaussian(),
              offset=None,
              kernel='bisquare',
              fixed=False,
              constant=True):
     self.coords = coords
     self.y = y
     self.X_loc = X_loc
     if X_glob is not None:
         self.X_glob = X_glob
     else:
         self.X_glob = []
     self.family = family
     self.fixed = fixed
     self.kernel = kernel
     if offset is None:
         self.offset = np.ones((len(y), 1))
     else:
         self.offset = offset * 1.0
     self.constant = constant
Beispiel #4
0
 def __init__(self,
              coordslist,
              y_list,
              X_list,
              tick_times_intervel,
              dspal_mat_list=None,
              sorted_dspal_list=None,
              d_tmp_list=None,
              dspmat=None,
              dtmat=None,
              family=Gaussian(),
              offset=None,
              kernel='spt_bisquare',
              fixed=False,
              multi=False,
              eps=1.0000001,
              max_cal_tol=100000000,
              constant=True,
              spherical=False):
     self.n_tick_nums = len(coordslist)
     self.coordslist = coordslist
     self.tick_timesIntls = tick_times_intervel
     self.y_list = y_list
     self.X_list = X_list
     self.dspal_mat_list = dspal_mat_list
     self.sorted_dspal_list = sorted_dspal_list
     self.d_tmp_list = d_tmp_list
     self.dspmat = dspmat
     self.dtmat = dtmat
     self.eps = eps
     self.lg_bw_sch_iter = 10
     self.alpha_sch_times = 25
     self.family = family
     self.fixed = fixed
     self.kernel = kernel
     self._functions = []
     self.constant = constant
     self.spherical = spherical
     self.max_cal_tol = max_cal_tol
     self.cur_len = len(coordslist[-1])
     self.mlist = [self.cur_len]
     self.cal_len_tol = len(coordslist[-1])
     self.separts = None
Beispiel #5
0
    def __init__(self,
                 coordslist,
                 y_list,
                 X_list,
                 tick_times_intervel,
                 dspal_mat_list=None,
                 sorted_dspal_list=None,
                 d_tmp_list=None,
                 dspmat=None,
                 dtmat=None,
                 family=Gaussian(),
                 offset=None,
                 kernel='spt_bisquare',
                 fixed=False,
                 multi=False,
                 eps=1.0000001,
                 constant=True,
                 spherical=False):
        self.n_tick_nums = len(coordslist)
        self.coordslist = coordslist
        self.tick_timesIntls = tick_times_intervel
        self.y_list = y_list
        self.X_list = X_list
        self.dspal_mat_list = dspal_mat_list
        self.sorted_dspal_list = sorted_dspal_list
        self.d_tmp_list = d_tmp_list
        self.dspmat = dspmat
        self.dtmat = dtmat
        self.eps = eps

        self.family = family
        self.fixed = fixed
        self.kernel = kernel
        self._functions = []
        self.constant = constant
        self.spherical = spherical
        self._build_dMatlist()
        self.search_params = {}
Beispiel #6
0
    def test_Prediction(self):
        coords = np.array(self.coords)
        index = np.arange(len(self.y))
        test = index[-10:]

        X_test = self.X[test]
        coords_test = list(coords[test])

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    93,
                    family=Gaussian(),
                    fixed=False,
                    kernel='bisquare')
        results = model.predict(coords_test, X_test)

        params = np.array([
            22.77198, -0.10254, -0.215093, -0.01405, 19.10531, -0.094177,
            -0.232529, 0.071913, 19.743421, -0.080447, -0.30893, 0.083206,
            17.505759, -0.078919, -0.187955, 0.051719, 27.747402, -0.165335,
            -0.208553, 0.004067, 26.210627, -0.138398, -0.360514, 0.072199,
            18.034833, -0.077047, -0.260556, 0.084319, 28.452802, -0.163408,
            -0.14097, -0.063076, 22.353095, -0.103046, -0.226654, 0.002992,
            18.220508, -0.074034, -0.309812, 0.108636
        ]).reshape((10, 4))
        np.testing.assert_allclose(params, results.params, rtol=1e-03)

        bse = np.array([
            2.080166, 0.021462, 0.102954, 0.049627, 2.536355, 0.022111,
            0.123857, 0.051917, 1.967813, 0.019716, 0.102562, 0.054918,
            2.463219, 0.021745, 0.110297, 0.044189, 1.556056, 0.019513,
            0.12764, 0.040315, 1.664108, 0.020114, 0.131208, 0.041613, 2.5835,
            0.021481, 0.113158, 0.047243, 1.709483, 0.019752, 0.116944,
            0.043636, 1.958233, 0.020947, 0.09974, 0.049821, 2.276849,
            0.020122, 0.107867, 0.047842
        ]).reshape((10, 4))
        np.testing.assert_allclose(bse, results.bse, rtol=1e-03)

        tvalues = np.array([
            10.947193, -4.777659, -2.089223, -0.283103, 7.532584, -4.259179,
            -1.877395, 1.385161, 10.033179, -4.080362, -3.012133, 1.515096,
            7.106862, -3.629311, -1.704079, 1.17042, 17.831878, -8.473156,
            -1.633924, 0.100891, 15.750552, -6.880725, -2.74765, 1.734978,
            6.980774, -3.586757, -2.302575, 1.784818, 16.644095, -8.273001,
            -1.205451, -1.445501, 11.414933, -4.919384, -2.272458, 0.060064,
            8.00251, -3.679274, -2.872176, 2.270738
        ]).reshape((10, 4))
        np.testing.assert_allclose(tvalues, results.tvalues, rtol=1e-03)

        localR2 = np.array([[0.53068693], [0.59582647], [0.59700925],
                            [0.45769954], [0.54634509], [0.5494828],
                            [0.55159604], [0.55634237], [0.53903842],
                            [0.55884954]])
        np.testing.assert_allclose(localR2, results.localR2, rtol=1e-05)

        predictions = np.array([[10.51695514], [9.93321992], [8.92473026],
                                [5.47350219], [8.61756585], [12.8141851],
                                [5.55619405], [12.63004172], [8.70638418],
                                [8.17582599]])
        np.testing.assert_allclose(predictions,
                                   results.predictions,
                                   rtol=1e-05)