<jupyter_start><jupyter_text>IWLS convergence loop<jupyter_code>data_p = pd.read_csv("C:/Users/msachde1/Downloads/logistic_mgwr_data/landslides.csv") 
coords = list(zip(data_p['X'],data_p['Y']))
y = np.array(data_p['Landslid']).reshape((-1,1)) 
elev = np.array(data_p['Elev']).reshape((-1,1))
slope = np.array(data_p['Slope']).reshape((-1,1))
SinAspct = np.array(data_p['SinAspct']).reshape(-1,1)
CosAspct = np.array(data_p['CosAspct']).reshape(-1,1)
X = np.hstack([elev,slope,SinAspct,CosAspct])
x = CosAspct

X_std = (X-X.mean(axis=0))/X.std(axis=0)
x_std = (x-x.mean(axis=0))/x.std(axis=0)
y_std = (y-y.mean(axis=0))/y.std(axis=0)<jupyter_output><empty_output><jupyter_text>Initialization with GWPR<jupyter_code>sel=Sel_BW(coords,y,x,family=Binomial(),constant=False)
bw_in=sel.search()
def gwr_func(y,X,bw):
    return GWR(coords,y,X,bw,family=Binomial(),fixed=False,kernel='bisquare',constant=False).fit()
optim_model = gwr_func(y=y,X=x,bw=bw_in)
om_p=optim_model.params
bw_in<jupyter_output><empty_output><jupyter_text>Starting values<jupyter_code>n_iter=0
n=x.shape[0]
diff = 1.0e+06
tol = 1.0e-06
max_iter=200
betas=om_p
XB =np.sum( np.multiply(optim_model.params,optim_model.X),axis=1)
mu = 1 / ( 1 + np.exp (-1 * XB))
ni_old = np.log((mu)/(1-mu))
while diff> tol and n_iter < max_iter:
    n_iter +=1
    w = mu*(1-mu)
    z = (ni_old + ((optim_model.y - mu)/mu*(1-mu))).reshape(-1,1)

    wx = spmultiply(x.reshape(-1),w.reshape(-1),array_out=False)
    
    x_std=((wx-wx.mean(axis=0))/wx.std(axis=0)).reshape(-1,1)
    print(x_std.shape)
    
    selector=Sel_BW(coords,z,x_std,multi=True,constant=False)
    selector.search(pool=pool)
    print(selector.bw[0])
    mgwr_model=MGWR(coords,z,x_std,selector,family=Gaussian(),constant=False).fit()
    
    n_betas=mgwr_model.params 

    XB =np.sum( np.multiply(n_betas,mgwr_model.X),axis=1)
    mu = 1 / ( 1 + np.exp (-1 * XB))
    ni_old = np.log((mu)/(1-mu))

    
    diff=min(min(abs(betas-n_betas).reshape(1,-1).tolist()))
    print("diff = "+str(diff))
    betas = n_betas

#print (betas, w, z, n_iter)
bw=Sel_BW(coords,y,x_std,family=Binomial(),constant=False)
bw=bw.search()
bw
gwr_mod = GWR(coords,y,x_std,bw,family=Binomial(),constant=False).fit()
gwr_mod.aic
sns.distplot(z)
sns.distplot(x_std)
mgwr_model.aic
optim_model.aic<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20223271790468011, 'fraction_numerical': 0.023185916702447403, 'mean_word_length': 5.852941176470588, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '8639', 'license': 'MIT-0', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1068, 'n_words': 110, 'path': 'Notebooks/Binomial_MGWR_module_GAM.ipynb', 'repo_name': 'mehak-sachdeva/MGWR_book', 'size': '2329'}