So when I try to run the following code for arrays with more than 10k elements, it takes hours and I don’t know how to make it in the most efficient way. Any ideas?
from scipy.stats import entropy as KL import numpy as np def dis(di,dj): di = np.asanyarray(di) dj = np.asanyarray(dj) m = 0.5 * (di+dj) kl1 = KL(di,m) kl2 = KL(dj,m) return 0.5*(kl1+kl2) def Intra_Cluster_dist(C): C = np.asanyarray(C) K = float(C.shape) factor1 = 1.0/float(K) total_sum = 0.0 for cluster in C: cluster = np.asanyarray(cluster) below1 = float(cluster.shape) below2 = float(below1 - 1) sub_sum = 0.0 for di in cluster: #others = cluster[:] #others.remove(di) others = cluster[np.logical_not((cluster == np.array(di)).all(axis=1))] #for dj in others: # sub_sum = sub_sum + (2*float(dis(di,dj)))/(float(below1)*float(below2)) sub_sum = sub_sum + np.fromiter((((2*float(dis(di,dj)))/(float(below1)*float(below2))) for dj in others), dtype=float).sum() total_sum = total_sum + sub_sum return float(factor1 * total_sum) def Inter_Cluster_dist(C): K = float(len(C)) factor1 = float((1/(K*(K-1)))) total_sum = 0.0 for cluster in C: sub_sum = 0.0 other_clusters = C[:] other_clusters.remove(cluster) below1= float(len(cluster)) for other in other_clusters: below2= float(len(other)) for di in cluster: for dj in other: sub_sum = sub_sum + (float((dis(di, dj)))/float((below1*below2))) total_sum = total_sum + sub_sum return float(factor1 * total_sum ) def H_score(C): return float(Intra_Cluster_dist(C))/float(Inter_Cluster_dist(C))
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!