<jupyter_start><jupyter_text>Weighted GM<jupyter_code>from func_tools import *
from gen import *
from plot import *
from GM import *<jupyter_output><empty_output><jupyter_text>自测数据<jupyter_code>centroids, points, N = gen_data() 
lbd = 0.05
delta = 1e-3
func = lambda X,B,nw: loss_func_weighted(X,points,lbd,B,nw)
grad = lambda X,B,W: weight_grad(X,points,B,W,lbd)
tol = 0.03
ans2, GM_loss = GM_Weighted(points,func,grad,tol,k=10,ctt=0.5)
groups = auto_group(ans2,5)
plt.figure(figsize=(10,10))
plot_res_data(points,ans2,groups)
plt.figure(figsize=(10,7))
plt.plot(GM_loss)
plt.title(f'Weighted GM norm grad on naive figure with tol {tol}')<jupyter_output><empty_output><jupyter_text>OPT 测试<jupyter_code>centroids, points, N = gen_data(distribution='OPT') 
lbd = 0.05
delta = 1e-3
func = lambda X,B,nw: loss_func_weighted(X,points,lbd,B,nw)
grad = lambda X,B,W: weight_grad(X,points,B,W,lbd)
ans2, GM_loss = GM_Weighted(points,func,grad,0.2,k=5,ctt=0.5,watch=True)
# 开头算D矩阵很慢，但是一劳永逸
groups = auto_group(ans2,5)
plt.figure(figsize=(15,10))
plot_res_data(points,ans2,groups)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15349682107175294, 'fraction_numerical': 0.03723887375113533, 'mean_word_length': 9.203703703703704, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '342687', 'license': 'Apache-2.0', 'n_tokens_mistral': 527, 'n_tokens_neox': 504, 'n_words': 74, 'path': 'Weighted_GM.ipynb', 'repo_name': 'QSCTech-Sange/Optimization_Project', 'size': '1101'}