예제 #1
0
 def GM_Lag_Regimes_Multi(self, y, x, w_i, regi_ids, cores=None,\
              yend=None, q=None, w_lags=1, lag_q=True,\
              robust=None, gwk=None, sig2n_k=False,cols2regi='all',\
              spat_diag=False, vm=False, name_y=None, name_x=None,\
              name_yend=None, name_q=None, name_regimes=None,\
              name_w=None, name_gwk=None, name_ds=None):
     pool = mp.Pool(cores)
     self.name_ds = USER.set_name_ds(name_ds)
     name_x = USER.set_name_x(name_x, x)
     name_yend.append(USER.set_name_yend_sp(name_y))
     self.name_w = USER.set_name_w(name_w, w_i)
     self.name_gwk = USER.set_name_w(name_gwk, gwk)
     results_p = {}
     for r in self.regimes_set:
         w_r = w_i[r].sparse
         results_p[r] = pool.apply_async(_work,args=(y,x,regi_ids,r,yend,q,w_r,w_lags,lag_q,robust,sig2n_k,self.name_ds,name_y,name_x,name_yend,name_q,self.name_w,name_regimes, ))
     self.kryd = 0
     self.kr = len(cols2regi) + 1
     self.kf = 0
     self.nr = len(self.regimes_set)
     self.name_x_r = name_x + name_yend
     self.name_regimes = name_regimes
     self.vm = np.zeros((self.nr*self.kr,self.nr*self.kr),float)
     self.betas = np.zeros((self.nr*self.kr,1),float)
     self.u = np.zeros((self.n,1),float)
     self.predy = np.zeros((self.n,1),float)
     self.predy_e = np.zeros((self.n,1),float)
     self.e_pred = np.zeros((self.n,1),float)
     pool.close()
     pool.join()
     results = {}
     self.name_y, self.name_x, self.name_yend, self.name_q, self.name_z, self.name_h = [],[],[],[],[],[]
     counter = 0
     for r in self.regimes_set:
         results[r] = results_p[r].get()
         results[r].predy_e, results[r].e_pred = sp_att(w_i[r],results[r].y,results[r].predy, results[r].yend[:,-1].reshape(results[r].n,1),results[r].betas[-1])
         results[r].w = w_i[r]
         self.vm[(counter*self.kr):((counter+1)*self.kr),(counter*self.kr):((counter+1)*self.kr)] = results[r].vm
         self.betas[(counter*self.kr):((counter+1)*self.kr),] = results[r].betas
         self.u[regi_ids[r],]=results[r].u
         self.predy[regi_ids[r],]=results[r].predy
         self.predy_e[regi_ids[r],]=results[r].predy_e
         self.e_pred[regi_ids[r],]=results[r].e_pred
         self.name_y += results[r].name_y
         self.name_x += results[r].name_x
         self.name_yend += results[r].name_yend
         self.name_q += results[r].name_q
         self.name_z += results[r].name_z
         self.name_h += results[r].name_h
         if r == self.regimes_set[0]:
             self.hac_var = np.zeros((self.n,results[r].h.shape[1]),float)
         self.hac_var[regi_ids[r],] = results[r].h                
         counter += 1
     self.multi = results
     if robust == 'hac':
         hac_multi(self,gwk,constant=True)
     self.chow = REGI.Chow(self)
     SUMMARY.GM_Lag_multi(reg=self, multireg=self.multi, vm=vm, spat_diag=spat_diag, regimes=True)
예제 #2
0
 def _ols_regimes_multi(self, x, w, regi_ids, cores,
                        gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran, white_test):
     results_p = {}
     for r in self.regimes_set:
         if system() == 'Windows':
             is_win = True
             results_p[r] = _work(
                 *(self.y, x, w, regi_ids, r, robust, sig2n_k,
                   self.name_ds, self.name_y, name_x, self.name_w, self.name_regimes))
         else:
             pool = mp.Pool(cores)
             results_p[r] = pool.apply_async(_work, args=(
                 self.y, x, w, regi_ids, r, robust, sig2n_k, self.name_ds, self.name_y, name_x, self.name_w, self.name_regimes))
             is_win = False
     self.kryd = 0
     self.kr = x.shape[1] + 1
     self.kf = 0
     self.nr = len(self.regimes_set)
     self.vm = np.zeros((self.nr * self.kr, self.nr * self.kr), float)
     self.betas = np.zeros((self.nr * self.kr, 1), float)
     self.u = np.zeros((self.n, 1), float)
     self.predy = np.zeros((self.n, 1), float)
     if not is_win:
         pool.close()
         pool.join()
     results = {}
     self.name_y, self.name_x = [], []
     counter = 0
     for r in self.regimes_set:
         if is_win:
             results[r] = results_p[r]
         else:
             results[r] = results_p[r].get()
         self.vm[(counter * self.kr):((counter + 1) * self.kr),
                 (counter * self.kr):((counter + 1) * self.kr)] = results[r].vm
         self.betas[(counter * self.kr):((counter + 1) * self.kr),
                    ] = results[r].betas
         self.u[regi_ids[r], ] = results[r].u
         self.predy[regi_ids[r], ] = results[r].predy
         self.name_y += results[r].name_y
         self.name_x += results[r].name_x
         counter += 1
     self.multi = results
     self.hac_var = x
     if robust == 'hac':
         hac_multi(self, gwk)
     self.chow = REGI.Chow(self)
     if spat_diag:
         self._get_spat_diag_props(x, sig2n_k)
     SUMMARY.OLS_multi(
         reg=self, multireg=self.multi, vm=vm, nonspat_diag=nonspat_diag,
         spat_diag=spat_diag, moran=moran, white_test=white_test, regimes=True, w=w)
예제 #3
0
 def _tsls_regimes_multi(self, x, yend, q, w_i, regi_ids, cores,\
              gwk, sig2n_k, robust, spat_diag, vm, name_x, name_yend, name_q):
     pool = mp.Pool(cores)
     results_p = {}
     for r in self.regimes_set:
         if system() == 'Windows':
             is_win = True
             results_p[r] = _work(*(self.y,x,regi_ids,r,yend,q,robust,sig2n_k,self.name_ds,self.name_y,name_x,name_yend,name_q,self.name_w,self.name_regimes))
         else:
             results_p[r] = pool.apply_async(_work,args=(self.y,x,regi_ids,r,yend,q,robust,sig2n_k,self.name_ds,self.name_y,name_x,name_yend,name_q,self.name_w,self.name_regimes))
             is_win = False
     self.kryd = 0
     self.kr = x.shape[1]+yend.shape[1]+1
     self.kf = 0
     self.nr = len(self.regimes_set)
     self.vm = np.zeros((self.nr*self.kr,self.nr*self.kr),float)
     self.betas = np.zeros((self.nr*self.kr,1),float)
     self.u = np.zeros((self.n,1),float)
     self.predy = np.zeros((self.n,1),float)
     if not is_win:
         pool.close()
         pool.join()
     results = {}
     self.name_y, self.name_x, self.name_yend, self.name_q, self.name_z, self.name_h = [],[],[],[],[],[]
     counter = 0
     for r in self.regimes_set:
         if is_win:
             results[r] = results_p[r]
         else:
             results[r] = results_p[r].get()
         if w_i:
             results[r].w = w_i[r]
         else:
             results[r].w = None
         self.vm[(counter*self.kr):((counter+1)*self.kr),(counter*self.kr):((counter+1)*self.kr)] = results[r].vm
         self.betas[(counter*self.kr):((counter+1)*self.kr),] = results[r].betas
         self.u[regi_ids[r],]=results[r].u
         self.predy[regi_ids[r],]=results[r].predy
         self.name_y += results[r].name_y
         self.name_x += results[r].name_x
         self.name_yend += results[r].name_yend
         self.name_q += results[r].name_q
         self.name_z += results[r].name_z
         self.name_h += results[r].name_h
         counter += 1
     self.multi = results
     self.hac_var = sphstack(x,q)
     if robust == 'hac':
         hac_multi(self,gwk)
     self.chow = REGI.Chow(self)
     SUMMARY.TSLS_multi(reg=self, multireg=self.multi, vm=vm, spat_diag=spat_diag, regimes=True)
예제 #4
0
 def _ols_regimes_multi(self, x, w_i, regi_ids, cores,\
              gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran):
     pool = mp.Pool(cores)
     results_p = {}
     for r in self.regimes_set:
         results_p[r] = pool.apply_async(_work,args=(self.y,x,regi_ids,r,robust,sig2n_k,self.name_ds,self.name_y,name_x,self.name_w,self.name_regimes))
     self.kryd = 0
     self.kr = x.shape[1]+1
     self.kf = 0
     self.nr = len(self.regimes_set)
     self.vm = np.zeros((self.nr*self.kr,self.nr*self.kr),float)
     self.betas = np.zeros((self.nr*self.kr,1),float)
     self.u = np.zeros((self.n,1),float)
     self.predy = np.zeros((self.n,1),float)
     pool.close()
     pool.join()
     results = {}
     self.name_y, self.name_x = [],[]
     counter = 0
     for r in self.regimes_set:
         results[r] = results_p[r].get()
         if w_i:
             results[r].w = w_i[r]
         else:
             results[r].w = None
         self.vm[(counter*self.kr):((counter+1)*self.kr),(counter*self.kr):((counter+1)*self.kr)] = results[r].vm
         self.betas[(counter*self.kr):((counter+1)*self.kr),] = results[r].betas
         self.u[regi_ids[r],]=results[r].u
         self.predy[regi_ids[r],]=results[r].predy
         self.name_y += results[r].name_y
         self.name_x += results[r].name_x
         counter += 1
     self.multi = results
     self.hac_var = x
     if robust == 'hac':
         hac_multi(self,gwk)
     self.chow = REGI.Chow(self)            
     SUMMARY.OLS_multi(reg=self, multireg=self.multi, vm=vm, nonspat_diag=nonspat_diag, spat_diag=spat_diag, moran=moran, regimes=True)
예제 #5
0
    def GM_Lag_Regimes_Multi(
        self,
        y,
        x,
        w_i,
        w,
        regi_ids,
        cores=False,
        yend=None,
        q=None,
        w_lags=1,
        lag_q=True,
        robust=None,
        gwk=None,
        sig2n_k=False,
        cols2regi="all",
        spat_diag=False,
        vm=False,
        name_y=None,
        name_x=None,
        name_yend=None,
        name_q=None,
        name_regimes=None,
        name_w=None,
        name_gwk=None,
        name_ds=None,
    ):
        #        pool = mp.Pool(cores)
        self.name_ds = USER.set_name_ds(name_ds)
        name_x = USER.set_name_x(name_x, x)
        name_yend.append(USER.set_name_yend_sp(name_y))
        self.name_w = USER.set_name_w(name_w, w_i)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        results_p = {}
        """
        for r in self.regimes_set:
            w_r = w_i[r].sparse
            if system() == 'Windows':
                is_win = True
                results_p[r] = _work(*(y,x,regi_ids,r,yend,q,w_r,w_lags,lag_q,robust,sig2n_k,self.name_ds,name_y,name_x,name_yend,name_q,self.name_w,name_regimes))
            else:                
                results_p[r] = pool.apply_async(_work,args=(y,x,regi_ids,r,yend,q,w_r,w_lags,lag_q,robust,sig2n_k,self.name_ds,name_y,name_x,name_yend,name_q,self.name_w,name_regimes, ))
                is_win = False
        """
        for r in self.regimes_set:
            w_r = w_i[r].sparse
            if cores:
                pool = mp.Pool(None)
                results_p[r] = pool.apply_async(
                    _work,
                    args=(
                        y,
                        x,
                        regi_ids,
                        r,
                        yend,
                        q,
                        w_r,
                        w_lags,
                        lag_q,
                        robust,
                        sig2n_k,
                        self.name_ds,
                        name_y,
                        name_x,
                        name_yend,
                        name_q,
                        self.name_w,
                        name_regimes,
                    ),
                )
            else:
                results_p[r] = _work(
                    *(
                        y,
                        x,
                        regi_ids,
                        r,
                        yend,
                        q,
                        w_r,
                        w_lags,
                        lag_q,
                        robust,
                        sig2n_k,
                        self.name_ds,
                        name_y,
                        name_x,
                        name_yend,
                        name_q,
                        self.name_w,
                        name_regimes,
                    )
                )

        self.kryd = 0
        self.kr = len(cols2regi) + 1
        self.kf = 0
        self.nr = len(self.regimes_set)
        self.name_x_r = name_x + name_yend
        self.name_regimes = name_regimes
        self.vm = np.zeros((self.nr * self.kr, self.nr * self.kr), float)
        self.betas = np.zeros((self.nr * self.kr, 1), float)
        self.u = np.zeros((self.n, 1), float)
        self.predy = np.zeros((self.n, 1), float)
        self.predy_e = np.zeros((self.n, 1), float)
        self.e_pred = np.zeros((self.n, 1), float)
        """
        if not is_win:
            pool.close()
            pool.join()
        """
        if cores:
            pool.close()
            pool.join()
        results = {}
        self.name_y, self.name_x, self.name_yend, self.name_q, self.name_z, self.name_h = [], [], [], [], [], []
        counter = 0
        for r in self.regimes_set:
            """
            if is_win:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            """
            if not cores:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            results[r].predy_e, results[r].e_pred, warn = sp_att(
                w_i[r], results[r].y, results[r].predy, results[r].yend[:, -1].reshape(results[r].n, 1), results[r].rho
            )
            set_warn(results[r], warn)
            results[r].w = w_i[r]
            self.vm[
                (counter * self.kr) : ((counter + 1) * self.kr), (counter * self.kr) : ((counter + 1) * self.kr)
            ] = results[r].vm
            self.betas[(counter * self.kr) : ((counter + 1) * self.kr),] = results[r].betas
            self.u[regi_ids[r],] = results[r].u
            self.predy[regi_ids[r],] = results[r].predy
            self.predy_e[regi_ids[r],] = results[r].predy_e
            self.e_pred[regi_ids[r],] = results[r].e_pred
            self.name_y += results[r].name_y
            self.name_x += results[r].name_x
            self.name_yend += results[r].name_yend
            self.name_q += results[r].name_q
            self.name_z += results[r].name_z
            self.name_h += results[r].name_h
            if r == self.regimes_set[0]:
                self.hac_var = np.zeros((self.n, results[r].h.shape[1]), float)
            self.hac_var[regi_ids[r],] = results[r].h
            counter += 1
        self.multi = results
        if robust == "hac":
            hac_multi(self, gwk, constant=True)
        if robust == "ogmm":
            set_warn(self, "Residuals treated as homoskedastic for the purpose of diagnostics.")
        self.chow = REGI.Chow(self)
        if spat_diag:
            pass
            # self._get_spat_diag_props(y, x, w, yend, q, w_lags, lag_q)
        SUMMARY.GM_Lag_multi(reg=self, multireg=self.multi, vm=vm, spat_diag=spat_diag, regimes=True, w=w)
예제 #6
0
    def GM_Lag_Regimes_Multi(self,
                             y,
                             x,
                             w_i,
                             w,
                             regi_ids,
                             cores=False,
                             yend=None,
                             q=None,
                             w_lags=1,
                             lag_q=True,
                             robust=None,
                             gwk=None,
                             sig2n_k=False,
                             cols2regi='all',
                             spat_diag=False,
                             vm=False,
                             name_y=None,
                             name_x=None,
                             name_yend=None,
                             name_q=None,
                             name_regimes=None,
                             name_w=None,
                             name_gwk=None,
                             name_ds=None):
        #        pool = mp.Pool(cores)
        self.name_ds = USER.set_name_ds(name_ds)
        name_x = USER.set_name_x(name_x, x)
        name_yend.append(USER.set_name_yend_sp(name_y))
        self.name_w = USER.set_name_w(name_w, w_i)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        results_p = {}
        """
        for r in self.regimes_set:
            w_r = w_i[r].sparse
            if system() == 'Windows':
                is_win = True
                results_p[r] = _work(*(y,x,regi_ids,r,yend,q,w_r,w_lags,lag_q,robust,sig2n_k,self.name_ds,name_y,name_x,name_yend,name_q,self.name_w,name_regimes))
            else:                
                results_p[r] = pool.apply_async(_work,args=(y,x,regi_ids,r,yend,q,w_r,w_lags,lag_q,robust,sig2n_k,self.name_ds,name_y,name_x,name_yend,name_q,self.name_w,name_regimes, ))
                is_win = False
        """
        for r in self.regimes_set:
            w_r = w_i[r].sparse
            if cores:
                pool = mp.Pool(None)
                results_p[r] = pool.apply_async(_work,
                                                args=(
                                                    y,
                                                    x,
                                                    regi_ids,
                                                    r,
                                                    yend,
                                                    q,
                                                    w_r,
                                                    w_lags,
                                                    lag_q,
                                                    robust,
                                                    sig2n_k,
                                                    self.name_ds,
                                                    name_y,
                                                    name_x,
                                                    name_yend,
                                                    name_q,
                                                    self.name_w,
                                                    name_regimes,
                                                ))
            else:
                results_p[r] = _work(*(y, x, regi_ids, r, yend, q, w_r, w_lags,
                                       lag_q, robust, sig2n_k, self.name_ds,
                                       name_y, name_x, name_yend, name_q,
                                       self.name_w, name_regimes))

        self.kryd = 0
        self.kr = len(cols2regi) + 1
        self.kf = 0
        self.nr = len(self.regimes_set)
        self.name_x_r = name_x + name_yend
        self.name_regimes = name_regimes
        self.vm = np.zeros((self.nr * self.kr, self.nr * self.kr), float)
        self.betas = np.zeros((self.nr * self.kr, 1), float)
        self.u = np.zeros((self.n, 1), float)
        self.predy = np.zeros((self.n, 1), float)
        self.predy_e = np.zeros((self.n, 1), float)
        self.e_pred = np.zeros((self.n, 1), float)
        """
        if not is_win:
            pool.close()
            pool.join()
        """
        if cores:
            pool.close()
            pool.join()
        results = {}
        self.name_y, self.name_x, self.name_yend, self.name_q, self.name_z, self.name_h = [
        ], [], [], [], [], []
        counter = 0
        for r in self.regimes_set:
            """
            if is_win:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            """
            if not cores:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            results[r].predy_e, results[r].e_pred, warn = sp_att(
                w_i[r], results[r].y, results[r].predy,
                results[r].yend[:, -1].reshape(results[r].n,
                                               1), results[r].rho)
            set_warn(results[r], warn)
            results[r].w = w_i[r]
            self.vm[(counter * self.kr):((counter + 1) * self.kr),
                    (counter * self.kr):((counter + 1) *
                                         self.kr)] = results[r].vm
            self.betas[(counter * self.kr):((counter + 1) *
                                            self.kr), ] = results[r].betas
            self.u[regi_ids[r], ] = results[r].u
            self.predy[regi_ids[r], ] = results[r].predy
            self.predy_e[regi_ids[r], ] = results[r].predy_e
            self.e_pred[regi_ids[r], ] = results[r].e_pred
            self.name_y += results[r].name_y
            self.name_x += results[r].name_x
            self.name_yend += results[r].name_yend
            self.name_q += results[r].name_q
            self.name_z += results[r].name_z
            self.name_h += results[r].name_h
            if r == self.regimes_set[0]:
                self.hac_var = np.zeros((self.n, results[r].h.shape[1]), float)
            self.hac_var[regi_ids[r], ] = results[r].h
            counter += 1
        self.multi = results
        if robust == 'hac':
            hac_multi(self, gwk, constant=True)
        if robust == 'ogmm':
            set_warn(
                self,
                "Residuals treated as homoskedastic for the purpose of diagnostics."
            )
        self.chow = REGI.Chow(self)
        if spat_diag:
            pass
            #self._get_spat_diag_props(y, x, w, yend, q, w_lags, lag_q)
        SUMMARY.GM_Lag_multi(reg=self,
                             multireg=self.multi,
                             vm=vm,
                             spat_diag=spat_diag,
                             regimes=True,
                             w=w)
예제 #7
0
    def _tsls_regimes_multi(self, x, yend, q, w, regi_ids, cores,
                            gwk, sig2n_k, robust, spat_diag, vm, name_x, name_yend, name_q):
        results_p = {}
        """
        for r in self.regimes_set:
            if system() != 'Windows':
                is_win = True
                results_p[r] = _work(*(self.y,x,w,regi_ids,r,yend,q,robust,sig2n_k,self.name_ds,self.name_y,name_x,name_yend,name_q,self.name_w,self.name_regimes))
            else:
                pool = mp.Pool(cores)
                results_p[r] = pool.apply_async(_work,args=(self.y,x,w,regi_ids,r,yend,q,robust,sig2n_k,self.name_ds,self.name_y,name_x,name_yend,name_q,self.name_w,self.name_regimes))
                is_win = False
        """
        for r in self.regimes_set:
            if cores:
                pool = mp.Pool(None)
                results_p[r] = pool.apply_async(_work, args=(
                    self.y, x, w, regi_ids, r, yend, q, robust, sig2n_k, self.name_ds, self.name_y, name_x, name_yend, name_q, self.name_w, self.name_regimes))
            else:
                results_p[r] = _work(*(self.y, x, w, regi_ids, r, yend, q, robust, sig2n_k,
                                       self.name_ds, self.name_y, name_x, name_yend, name_q, self.name_w, self.name_regimes))

        self.kryd = 0
        self.kr = x.shape[1] + yend.shape[1] + 1
        self.kf = 0
        self.nr = len(self.regimes_set)
        self.vm = np.zeros((self.nr * self.kr, self.nr * self.kr), float)
        self.betas = np.zeros((self.nr * self.kr, 1), float)
        self.u = np.zeros((self.n, 1), float)
        self.predy = np.zeros((self.n, 1), float)
        """
        if not is_win:
            pool.close()
            pool.join()
        """
        if cores:
            pool.close()
            pool.join()

        results = {}
        self.name_y, self.name_x, self.name_yend, self.name_q, self.name_z, self.name_h = [
        ], [], [], [], [], []
        counter = 0
        for r in self.regimes_set:
            """
            if is_win:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            """
            if not cores:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()

            self.vm[(counter * self.kr):((counter + 1) * self.kr),
                    (counter * self.kr):((counter + 1) * self.kr)] = results[r].vm
            self.betas[
                (counter * self.kr):((counter + 1) * self.kr), ] = results[r].betas
            self.u[regi_ids[r], ] = results[r].u
            self.predy[regi_ids[r], ] = results[r].predy
            self.name_y += results[r].name_y
            self.name_x += results[r].name_x
            self.name_yend += results[r].name_yend
            self.name_q += results[r].name_q
            self.name_z += results[r].name_z
            self.name_h += results[r].name_h
            counter += 1
        self.multi = results
        self.hac_var = sphstack(x, q)
        if robust == 'hac':
            hac_multi(self, gwk)
        if robust == 'ogmm':
            set_warn(
                self, "Residuals treated as homoskedastic for the purpose of diagnostics.")
        self.chow = REGI.Chow(self)
        if spat_diag:
            self._get_spat_diag_props(results, regi_ids, x, yend, q)
        SUMMARY.TSLS_multi(
            reg=self, multireg=self.multi, vm=vm, spat_diag=spat_diag, regimes=True, w=w)
예제 #8
0
    def _ols_regimes_multi(self, x, w, regi_ids, cores,
                           gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran, white_test):
        results_p = {}
        """
        for r in self.regimes_set:
            if system() == 'Windows':
                is_win = True
                results_p[r] = _work(*(self.y,x,w,regi_ids,r,robust,sig2n_k,self.name_ds,self.name_y,name_x,self.name_w,self.name_regimes))
            else:
                pool = mp.Pool(cores)
                results_p[r] = pool.apply_async(_work,args=(self.y,x,w,regi_ids,r,robust,sig2n_k,self.name_ds,self.name_y,name_x,self.name_w,self.name_regimes))
                is_win = False
        """
        for r in self.regimes_set:
            if cores:
                pool = mp.Pool(None)
                results_p[r] = pool.apply_async(_work, args=(
                    self.y, x, w, regi_ids, r, robust, sig2n_k, self.name_ds, self.name_y, name_x, self.name_w, self.name_regimes))
            else:
                results_p[r] = _work(*(self.y, x, w, regi_ids, r, robust, sig2n_k,
                                       self.name_ds, self.name_y, name_x, self.name_w, self.name_regimes))

        self.kryd = 0
        self.kr = x.shape[1] + 1
        self.kf = 0
        self.nr = len(self.regimes_set)
        self.vm = np.zeros((self.nr * self.kr, self.nr * self.kr), float)
        self.betas = np.zeros((self.nr * self.kr, 1), float)
        self.u = np.zeros((self.n, 1), float)
        self.predy = np.zeros((self.n, 1), float)
        """
        if not is_win:
            pool.close()
            pool.join()
        """
        if cores:
            pool.close()
            pool.join()

        results = {}
        self.name_y, self.name_x = [], []
        counter = 0
        for r in self.regimes_set:
            """
            if is_win:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            """
            if not cores:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()

            self.vm[(counter * self.kr):((counter + 1) * self.kr),
                    (counter * self.kr):((counter + 1) * self.kr)] = results[r].vm
            self.betas[
                (counter * self.kr):((counter + 1) * self.kr), ] = results[r].betas
            self.u[regi_ids[r], ] = results[r].u
            self.predy[regi_ids[r], ] = results[r].predy
            self.name_y += results[r].name_y
            self.name_x += results[r].name_x
            counter += 1
        self.multi = results
        self.hac_var = x
        if robust == 'hac':
            hac_multi(self, gwk)
        self.chow = REGI.Chow(self)
        if spat_diag:
            self._get_spat_diag_props(x, sig2n_k)
        SUMMARY.OLS_multi(reg=self, multireg=self.multi, vm=vm, nonspat_diag=nonspat_diag,
                          spat_diag=spat_diag, moran=moran, white_test=white_test, regimes=True, w=w)
예제 #9
0
    def _tsls_regimes_multi(self, x, yend, q, w, regi_ids, cores, gwk, sig2n_k,
                            robust, spat_diag, vm, name_x, name_yend, name_q):
        results_p = {}
        """
        for r in self.regimes_set:
            if system() != 'Windows':
                is_win = True
                results_p[r] = _work(*(self.y,x,w,regi_ids,r,yend,q,robust,sig2n_k,self.name_ds,self.name_y,name_x,name_yend,name_q,self.name_w,self.name_regimes))
            else:
                pool = mp.Pool(cores)
                results_p[r] = pool.apply_async(_work,args=(self.y,x,w,regi_ids,r,yend,q,robust,sig2n_k,self.name_ds,self.name_y,name_x,name_yend,name_q,self.name_w,self.name_regimes))
                is_win = False
        """
        for r in self.regimes_set:
            if cores:
                pool = mp.Pool(None)
                results_p[r] = pool.apply_async(
                    _work,
                    args=(self.y, x, w, regi_ids, r, yend, q, robust, sig2n_k,
                          self.name_ds, self.name_y, name_x, name_yend, name_q,
                          self.name_w, self.name_regimes))
            else:
                results_p[r] = _work(*(self.y, x, w, regi_ids, r, yend, q,
                                       robust, sig2n_k, self.name_ds,
                                       self.name_y, name_x, name_yend, name_q,
                                       self.name_w, self.name_regimes))

        self.kryd = 0
        self.kr = x.shape[1] + yend.shape[1] + 1
        self.kf = 0
        self.nr = len(self.regimes_set)
        self.vm = np.zeros((self.nr * self.kr, self.nr * self.kr), float)
        self.betas = np.zeros((self.nr * self.kr, 1), float)
        self.u = np.zeros((self.n, 1), float)
        self.predy = np.zeros((self.n, 1), float)
        """
        if not is_win:
            pool.close()
            pool.join()
        """
        if cores:
            pool.close()
            pool.join()

        results = {}
        self.name_y, self.name_x, self.name_yend, self.name_q, self.name_z, self.name_h = [
        ], [], [], [], [], []
        counter = 0
        for r in self.regimes_set:
            """
            if is_win:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()
            """
            if not cores:
                results[r] = results_p[r]
            else:
                results[r] = results_p[r].get()

            self.vm[(counter * self.kr):((counter + 1) * self.kr),
                    (counter * self.kr):((counter + 1) *
                                         self.kr)] = results[r].vm
            self.betas[(counter * self.kr):((counter + 1) *
                                            self.kr), ] = results[r].betas
            self.u[regi_ids[r], ] = results[r].u
            self.predy[regi_ids[r], ] = results[r].predy
            self.name_y += results[r].name_y
            self.name_x += results[r].name_x
            self.name_yend += results[r].name_yend
            self.name_q += results[r].name_q
            self.name_z += results[r].name_z
            self.name_h += results[r].name_h
            counter += 1
        self.multi = results
        self.hac_var = sphstack(x, q)
        if robust == 'hac':
            hac_multi(self, gwk)
        if robust == 'ogmm':
            set_warn(
                self,
                "Residuals treated as homoskedastic for the purpose of diagnostics."
            )
        self.chow = REGI.Chow(self)
        if spat_diag:
            self._get_spat_diag_props(results, regi_ids, x, yend, q)
        SUMMARY.TSLS_multi(reg=self,
                           multireg=self.multi,
                           vm=vm,
                           spat_diag=spat_diag,
                           regimes=True,
                           w=w)