Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, y, x, w,
max_iter=1, epsilon=0.00001, step1c=False,
vm=False, name_y=None, name_x=None,
name_w=None, name_ds=None):
n = USER.check_arrays(y, x)
USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Error_Het.__init__(
self, y, x_constant, w.sparse, max_iter=max_iter,
step1c=step1c, epsilon=epsilon)
self.title = "SPATIALLY WEIGHTED LEAST SQUARES (HET)"
self.name_ds = USER.set_name_ds(name_ds)
self.name_y = USER.set_name_y(name_y)
self.name_x = USER.set_name_x(name_x, x)
self.name_x.append('lambda')
self.name_w = USER.set_name_w(name_w, w)
SUMMARY.GM_Error_Het(reg=self, w=w, vm=vm)
cols2regi='all', method='full', epsilon=0.0000001,
regime_lag_sep=False, regime_err_sep=False, cores=False, spat_diag=False,
vm=False, name_y=None, name_x=None,
name_w=None, name_ds=None, name_regimes=None):
n = USER.check_arrays(y, x)
USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
USER.check_spat_diag(spat_diag, w)
name_y = USER.set_name_y(name_y)
self.name_y = name_y
self.name_x_r = USER.set_name_x(
name_x, x) + [USER.set_name_yend_sp(name_y)]
self.method = method
self.epsilon = epsilon
self.name_regimes = USER.set_name_ds(name_regimes)
self.constant_regi = constant_regi
self.n = n
cols2regi = REGI.check_cols2regi(
constant_regi, cols2regi, x, add_cons=False)
self.cols2regi = cols2regi
self.regimes_set = REGI._get_regimes_set(regimes)
self.regimes = regimes
self.regime_lag_sep = regime_lag_sep
self._cache = {}
self.name_ds = USER.set_name_ds(name_ds)
self.name_w = USER.set_name_w(name_w, w)
USER.check_regimes(self.regimes_set, self.n, x.shape[1])
# regime_err_sep is ignored, always False
if regime_lag_sep == True:
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:
def __init__(self,bigy,bigX,w,regimes=None,nonspat_diag=True,spat_diag=False,\
vm=False, epsilon=0.0000001,\
name_bigy=None,name_bigX=None,name_ds=None,name_w=None,name_regimes=None):
#need checks on match between bigy, bigX dimensions
# check on variable names for listing results
self.name_ds = USER.set_name_ds(name_ds)
self.name_w = USER.set_name_w(name_w, w)
self.n_eq = len(bigy.keys())
#initialize names - should be generated by sur_stack
if name_bigy:
self.name_bigy = name_bigy
else: # need to construct y names
self.name_bigy = {}
for r in range(self.n_eq):
yn = 'dep_var_' + str(r)
self.name_bigy[r] = yn
if name_bigX is None:
name_bigX = {}
for r in range(self.n_eq):
k = bigX[r].shape[1] - 1
name_x = ['var_' + str(i + 1) + "_" + str(r+1) for i in range(k)]
ct = 'Constant_' + str(r+1) # NOTE: constant always included in X
name_x.insert(0, ct)
def __init__(self, y, x, regimes, yend=None, q=None,
w=None, w_lags=1, lag_q=True,
robust=None, gwk=None, sig2n_k=False,
spat_diag=False, constant_regi='many',
cols2regi='all', regime_lag_sep=False, regime_err_sep=True,
cores=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):
n = USER.check_arrays(y, x)
USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
USER.check_robust(robust, gwk)
USER.check_spat_diag(spat_diag, w)
name_x = USER.set_name_x(name_x, x, constant=True)
name_y = USER.set_name_y(name_y)
name_yend = USER.set_name_yend(name_yend, yend)
name_q = USER.set_name_q(name_q, q)
name_q.extend(
USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
self.name_regimes = USER.set_name_ds(name_regimes)
self.constant_regi = constant_regi
self.n = n
cols2regi = REGI.check_cols2regi(
constant_regi, cols2regi, x, yend=yend, add_cons=False)
self.cols2regi = cols2regi
def __init__(self, flows, cost, cost_func='pow', o_vars=None, d_vars=None,
origins=None, destinations=None, constant=True, framework='GLM',
SF=None, CD=None, Lag=None, Quasi=False):
n = User.check_arrays(flows, cost)
#User.check_y(flows, n)
self.n = n
self.f = flows
self.c = cost
self.ov = o_vars
self.dv = d_vars
if type(cost_func) == str:
if cost_func.lower() == 'pow':
self.cf = np.log
if (self.c==0).any():
raise ValueError("Zero values detected: cost function 'pow'"
"requires the logarithm of the cost variable which"
"is undefined at 0")
elif cost_func.lower() == 'exp':
self.cf = lambda x: x*1.0
elif (type(cost_func) == FunctionType) | (type(cost_func) == np.ufunc):
def __init__(self, y, x, w, method='full', epsilon=0.0000001,
spat_diag=False, vm=False, name_y=None, name_x=None,
name_w=None, name_ds=None):
n = USER.check_arrays(y, x)
USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
method = method.upper()
BaseML_Lag.__init__(
self, y=y, x=x_constant, w=w, method=method, epsilon=epsilon)
# increase by 1 to have correct aic and sc, include rho in count
self.k += 1
self.title = "MAXIMUM LIKELIHOOD SPATIAL LAG" + \
" (METHOD = " + method + ")"
self.name_ds = USER.set_name_ds(name_ds)
self.name_y = USER.set_name_y(name_y)
self.name_x = USER.set_name_x(name_x, x)
name_ylag = USER.set_name_yend_sp(self.name_y)
self.name_x.append(name_ylag) # rho changed to last position
self.name_w = USER.set_name_w(name_w, w)
max_iter=1, epsilon=0.00001, step1c=False,
cores=False, inv_method='power_exp',
constant_regi='many', cols2regi='all',
regime_err_sep=False, regime_lag_sep=False,
vm=False, name_y=None, name_x=None,
name_yend=None, name_q=None,
name_w=None, name_ds=None, name_regimes=None):
n = USER.check_arrays(y, x)
self.step1c = step1c
USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
name_x = USER.set_name_x(name_x, x, constant=True)
self.name_y = USER.set_name_y(name_y)
name_yend = USER.set_name_yend(name_yend, yend)
name_q = USER.set_name_q(name_q, q)
name_q.extend(
USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
cols2regi = REGI.check_cols2regi(
constant_regi, cols2regi, x, yend=yend, add_cons=False)
self.regimes_set = REGI._get_regimes_set(regimes)
self.regimes = regimes
USER.check_regimes(self.regimes_set, n, x.shape[1])
self.regime_err_sep = regime_err_sep
self.regime_lag_sep = regime_lag_sep
if regime_lag_sep == True:
if regime_err_sep == False:
raise Exception("For spatial combo models, if spatial lag is set by regimes (regime_lag_sep=True), spatial error must also be set by regimes (regime_err_sep=True).")
add_lag = [w_lags, lag_q]
else:
self.name_w = USER.set_name_w(name_w, w)
self.n = n
self.y = y
name_x = USER.set_name_x(name_x, x)
if summ:
name_yend = USER.set_name_yend(name_yend, yend)
self.name_y = USER.set_name_y(name_y)
name_q = USER.set_name_q(name_q, q)
self.name_x_r = name_x + name_yend
cols2regi = REGI.check_cols2regi(
constant_regi, cols2regi, x, yend=yend)
self.regimes_set = REGI._get_regimes_set(regimes)
self.regimes = regimes
USER.check_regimes(self.regimes_set, self.n, x.shape[1])
self.regime_err_sep = regime_err_sep
if regime_err_sep == True:
if set(cols2regi) == set([True]):
self._endog_error_regimes_multi(y, x, regimes, w, yend, q, cores,
max_iter, epsilon, A1, cols2regi, vm,
name_x, name_yend, name_q, add_lag)
else:
raise Exception("All coefficients must vary accross regimes if regime_err_sep = True.")
else:
x_constant = USER.check_constant(x)
q, name_q = REGI.Regimes_Frame.__init__(self, q,
regimes, constant_regi=None, cols2regi='all', names=name_q)
x, name_x = REGI.Regimes_Frame.__init__(self, x_constant,
regimes, constant_regi=None, cols2regi=cols2regi,
names=name_x)
def _work(y, x, w, regi_ids, r, robust, sig2n_k, name_ds, name_y, name_x, name_w, name_regimes):
y_r = y[regi_ids[r]]
x_r = x[regi_ids[r]]
x_constant = USER.check_constant(x_r)
if robust == 'hac':
robust = None
model = BaseOLS(y_r, x_constant, robust=robust, sig2n_k=sig2n_k)
model.title = "ORDINARY LEAST SQUARES ESTIMATION - REGIME %s" % r
model.robust = USER.set_robust(robust)
model.name_ds = name_ds
model.name_y = '%s_%s' % (str(r), name_y)
model.name_x = ['%s_%s' % (str(r), i) for i in name_x]
model.name_w = name_w
model.name_regimes = name_regimes
if w:
w_r, warn = REGI.w_regime(w, regi_ids[r], r, transform=True)
set_warn(model, warn)
model.w = w_r
return model