#""" #BEST 2 - with Swarm2-WOW - WOOOOOOOOOOWWWW n = 100 #50 r = 19 lamda = 100 f = tf.gaussian_diff_multimodal4_positive dim = 2 sigma_share = 1 #1.5 #1 Good #0.2 Good #0.6 NOT WORKING d_min = 1 #0.2 #1 d_max = 3 clust_alpha = 2 step_size = 0.1 #alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v4(n, f, -r, r, dim, 100, 16, 2, 8, 12, step_size, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'none' '''adaptive1 also''', 'swarm2', 'false', sigma_share,d_min, d_max, clust_alpha) alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v4_chi( n, f, -r, r, dim, 100, 16, 2, 8, 12, step_size, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'none' '''adaptive1 also''', 'swarm2', 'false', sigma_share, d_min, d_max, clust_alpha) trained_centers = alh._get_cluster_centroids() trained_centers_fit = alh._get_cluster_centroids_fit() #Chi Test alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v4_chi_test( n, f, -r, r, dim, 100, 16, 2, 8, 12, step_size, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'none' '''adaptive1 also''', 'swarm2', 'false', sigma_share, d_min, d_max, clust_alpha, 'true', trained_centers, trained_centers_fit) #""" #LAST TESTED '''rastrigin Working , Change last Visualize, LAST one is the BEST, This is EXTRA, Only Change is n=100 not 500
N = 400 #D = 20 #Divisions M = 2 R = 2 lrm = 4 # for all r,m, Prmk T = 19 T = T + 1 Nr = [75, 20] r = max(Nr) D = 800 Dimention = M * T dim = Dimention revf = SwarmPackagePy.revenue_optimization_function(M, R, lrm, T) #filename = '../../data/data1.csv' filename = '/home/mahesh/paraqum/repos/SwarmPackagePy/data/data2.csv' #ALl numbers #revf.read_paramemeters_file(filename) #read_paramemeters_file(self, filename, Nr, M_=3, R_=2, lrm_=3, T_=2, D = 20 ): revf.read_paramemeters_file(filename, Nr, 2, 2, 4, 20, 800) #TTotal print("self.N", revf.N) print('Press ENTER to continue!') input() #No Need #Set Parameter Commented #revf.set_parameters(N, M, R , lrm ,T) #raw_input("Press Enter to continue ...") #pause()
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #alh = SwarmPackagePy.abfoa2(20, tf.easom_function, -10, 10, 2, 20, 16, 4, 2, 12, 0.9, 0.25, 0.1) #animation(alh.get_agents(), tf.easom_function, -10, 10) #animation3D(alh.get_agents(), tf.easom_function, -10, 10) #alh = SwarmPackagePy.abfoa2(20, tf.gaussian_function, -10, 10, 2, 20, 16, 4, 2, 12, 0.9, 0.25, 0.1) #animation(alh.get_agents(), tf.gaussian_function, -10, 10) #animation3D(alh.get_agents(), tf.gaussian_function, -10, 10) alh = SwarmPackagePy.abfoa2(100, tf.thriple_gaussian_function_positive, -10, 10, 50, 20, 16, 4, 2, 12, 0.9, 0.25, 1) steps = alh._get_csteps() print(steps) plt.plot(steps) plt.ylabel('Step Size') #plt.show() jlist = alh._get_jlist() print(jlist) #plt.plot(jlist,'r') plt.show() animation(alh.get_agents(), tf.thriple_gaussian_function_positive, -10, 10) animation3D(alh.get_agents(), tf.thriple_gaussian_function_positive, -10, 10) """ alh = SwarmPackagePy.abfoa2(100, tf.thriple_wide_gaussian_function, -50, 50, 2, 20, 16, 4, 2, 12, 0.9, 0.25, 0.1)
#alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'false') #BEST #alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 400, 0.03, 'adaptive1', 'swarm1', 'false') #HARSHA BEST1 DEMO1 Org alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 400, 0.03, 'adaptive1', 'swarm1', 'false') #GOOD 1 alh = SwarmPackagePy.z_bfoa(50, f, -r, r, 30, 100, 16, 4, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'false') #NOT GOOD alh = SwarmPackagePy.z_bfoa(50, f, -r, r, 30, 100, 16, 4, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'true') #TEST FOR MULTI-NICHE SHARING 2 With testcase Best-2 n = 100 #50 r = 20 lamda = 100 f = tf.gaussian_diff_multimodal_positive dim = 2 alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm2', 'false') #TEST CASES ######################################################################## #DAMN WORSE - Lets change SOme Parametr Nc = 4 ''' n =100 #50 r = 20 lamda = 100 f = tf.gaussian_diff_multimodal_positive dim =2 alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 2, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm1', 'false') ''' #########################################################################
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D #alh = SwarmPackagePy.pso(50, tf.easom_function, -10, 10, 2, 20,w=0.5, c1=1, c2=1) #alh = SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped) alh = SwarmPackagePy.bfo(50, tf.easom_function, -10, 10, 2, 20, 2, 12, 0.2, 1.15) animation(alh.get_agents(), tf.easom_function, -10, 10) animation3D(alh.get_agents(), tf.easom_function, -10, 10) #SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D eval_function = [ tf.ackley_function, ] """ tf.ackley_function, tf.bukin_function, tf.cross_in_tray_function, tf.sphere_function, tf.bohachevsky_function, tf.sum_squares_function, tf.sum_of_different_powers_function, tf.booth_function, tf.matyas_function, tf.mccormick_function, tf.dixon_price_function, tf.six_hump_camel_function, tf.three_hump_camel_function, tf.easom_function, tf.michalewicz_function, tf.beale_function, tf.drop_wave_function ] """ for func in eval_function: alh = SwarmPackagePy.aba(50, func, -10, 10, 2, 20) animation(alh.get_agents(), func, -10, 10) animation3D(alh.get_agents(), func, -10, 10)
import matplotlib.pyplot as plt import numpy as np from math import * #(self, n, function, lb, ub, dimension, iteration, Nre=16, Ned=4, Nc=2, Ns=12, C=0.1, Ped=0.25, Da=0.1, Wa=0.2, Hr=0.1, Wr=10, lamda=400, L=0.03, arga='none', argj='none', arged='false'): #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f1_sphere_function, -100, 100, 3, 100, 8, 4, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,10 ) #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f5_griewank_function, -10, 10, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #VERYGOOD alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) r = 1 #lamda = 100 #FOR MULTINICHE GOOD lamda = 10 f = tf.F1 alh = SwarmPackagePy.z_bfoa_multiniche_sharing(50, f, -r, r, 1, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, lamda, 0.03, 'adaptive1', 'none', 'false') fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist, 'r', label='J-cc') jarlist = alh._get_jarlist() plt.plot(jarlist, 'g', label='J-ar') jlist = alh._get_jlist() plt.plot(jlist, 'y', label='J') jblist = alh._get_jblist()
from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f1_sphere_function, -100, 100, 3, 100, 8, 4, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,10 ) #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f5_griewank_function, -10, 10, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #VERYGOOD alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) r = 20 f = tf.gaussian_multimodal3_positive #32 #lamda=50 #f = tf.f3_ackley_function #lamda=100 #f = tf.f2_rosenbrock_function #lamda=400 not enough. #ACKLEY #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) #alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) # SO FAR BEST alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 8, 8, 16, 4, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.03) #alh = SwarmPackagePy.z_ibfoa_jun_li_2(200, f, -r, r, 30, 100, 8, 8, 16, 4, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.02) alh = SwarmPackagePy.z_ibfoa_jun_li_2(100, f, -r, r, 30, 100, 8, 8, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.02) fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist, 'r', label='J-cc') jarlist = alh._get_jarlist() plt.plot(jarlist, 'r', label='J-ar') jlist = alh._get_jlist() plt.plot(jlist, 'y', label='J') jblist = alh._get_jblist() plt.plot(jblist, 'g', label='J-best')
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #alh = SwarmPackagePy.abfoa1_swarm1(100, tf.easom_function, -10, 10, 2, 20, 16, 4, 2, 12, 0.9, 0.25, 400 ) #animation(alh.get_agents(), tf.easom_function, -10, 10) #animation3D(alh.get_agents(), tf.easom_function, -10, 10) #alh = SwarmPackagePy.abfoa2_swarm1(100, tf.thriple_gaussian_function, -10, 10, 50, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #alh = SwarmPackagePy.abfoa2_swarm1(100, tf.f2_rosenbrock_function, -32, 32, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #alh = SwarmPackagePy.abfoa1_swarm1(100, tf.f2_rosenbrock_function, -32, 32, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) # OKalh = SwarmPackagePy.abfoa1_swarm1(100, tf.f3_ackley_function, -32, 32, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) alh = SwarmPackagePy.abfoa1_swarm1(100, tf.f3_ackley_function, -32, 32, 30, 100, 8, 8, 8, 12, 0.1, 0.25, 0.01, 0.2, 0.01, 10,400 ) fits = alh._get_jfits() print('Fit Val') #print(fits) plt.plot(fits, 'b', label='J-fit') #plt.ylabel('J values') #plt.show() jcclist = alh._get_jcclist() #print('jcclist') #print(jcclist) plt.plot(jcclist,'r', label='J-cc') #plt.show() steps = alh._get_csteps() #print('steps') #print(steps)
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D alh = SwarmPackagePy.swarm(50, tf.ackley_function, -5, 5, 3, 30) animation(alh.get_agents(), tf.ackley_function, -5, 5) animation3D(alh.get_agents(), tf.ackley_function, -5, 5)
import SwarmPackagePy as sw from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D import numpy as np sw._version_ swarm_strength = np.random.random_integers(25, 55) print("Swarm strength =", swarm_strength) firefly = sw.fa(n=swarm_strength, function=tf.sum_squares_function, lb=-10, ub=10, dimension=2, psi=2, iteration=50) animation(firefly.get_agents(), tf.sum_squares_function, -10, 10) animation3D(firefly.get_agents(), tf.sum_squares_function, -10, 10)
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #alh = SwarmPackagePy.abfoa1_swarm1(100, tf.easom_function, -10, 10, 2, 20, 16, 4, 2, 12, 0.9, 0.25, 400 ) #animation(alh.get_agents(), tf.easom_function, -10, 10) #animation3D(alh.get_agents(), tf.easom_function, -10, 10) """ alh = SwarmPackagePy.abfoa1_swarm2(100, tf.gaussian_function, -50, 50, 50, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) animation(alh.get_agents(), tf.gaussian_function, -50, 50) animation3D(alh.get_agents(), tf.gaussian_function, -50, 50) """ alh = SwarmPackagePy.abfoa2_swarm2(100, tf.thriple_gaussian_function, -10, 10, 50, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 400) fits = alh._get_jfits() print('Fit Val') print(fits) plt.plot(fits, 'b', label='J-fit') #plt.ylabel('J values') #plt.show() jcclist = alh._get_jcclist() print('jcclist') print(jcclist) plt.plot(jcclist, 'r', label='J-cc') #plt.show()
Yd_train = distance_to_erbs(Y_train, erbs) X_test = testmatrix[:,2:8] Y_test = testmatrix[:,0:2] Yd_test = distance_to_erbs(Y_test, erbs) tup = X_test.shape inter_step = numpy.zeros(X_test.shape[1]) results = numpy.zeros(Y_test.shape) nbrs = NearestNeighbors(n_neighbors=k, algorithm='kd_tree', leaf_size=60).fit(X_train) for i in range(0, tup[0]): distances, indices = nbrs.kneighbors(X_test[i,:].reshape(1,6)) inter_step = kNN_estimator(indices, distances, Y_train, erbs) # print(inter_step) # results[i,:] = SwarmPackagePy.aba(200, fitness, [min_lat, min_long], [max_lat, max_long], 2, 50).get_Gbest() results[i,:] = SwarmPackagePy.pso(100, fitness, [min_lat, min_long], [max_lat, max_long], 2, 50, 0.1, 1, 1).get_Gbest() err = distance_to_reference(Y_test, results) # for i in range(0, err.size): # err[i] = vincenty((Y_test[i,0], Y_test[i,1]), (results[i,0], results[i,1])).meters k_measures = [sqrt((err**2).mean()), err.std(), err.max(), err.min()] print(err) print(k_measures) f = open('fichier-test.csv', 'w+') f.write("lat,lon\n") for i in range(0,results.shape[0]): f.write("%.6f, %.6f\n" % (results[i,0], results[i,1])) # print(results) # d = distance_to_reference(results, Y_test)
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D alh = SwarmPackagePy.classic_bfo(100, tf.easom_function, -10, 10, 2, 20, 16, 4, 2, 12, 0.1, 0.25, 1 / 16) animation(alh.get_agents(), tf.easom_function, -10, 10) animation3D(alh.get_agents(), tf.easom_function, -10, 10) #SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)
#FINAL DEMO alh = SwarmPackagePy.z_bfoa_multiniche(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'true') #4 alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.9, 0.25, 0.1, 0.2, 0.1, 10, 400, 0.03, 'adaptive1', 'swarm1', 'true') #HARSHA BEST2 : Without Improvment to Elimintion-Dispersal #alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'false') #BEST #alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 400, 0.03, 'adaptive1', 'swarm1', 'false') #HARSHA BEST1 DEMO1 Org alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 400, 0.03, 'adaptive1', 'swarm1', 'false') #GOOD 1 alh = SwarmPackagePy.z_bfoa(50, f, -r, r, 30, 100, 16, 4, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'false') #NOT GOOD alh = SwarmPackagePy.z_bfoa(50, f, -r, r, 30, 100, 16, 4, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'true') alh = SwarmPackagePy.z_bfoa_multiniche(200, f, -r, r, 2, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, lamda, 0.03, 'none', 'swarm1', 'false') fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist, 'r', label='J-cc') jarlist = alh._get_jarlist() plt.plot(jarlist, 'g', label='J-ar') jlist = alh._get_jlist() plt.plot(jlist, 'y', label='J') jblist = alh._get_jblist()
#alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f5_griewank_function, -10, 10, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #VERYGOOD alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) r = 20 lamda = 400 f = tf.gaussian_multimodal_positive #f = tf.gaussian_multimodal_positive #32 #lamda=50 #f = tf.f3_ackley_function #lamda=100 #f = tf.f2_rosenbrock_function #lamda=400 not enough. #ACKLEY #alh = SwarmPackagePy.z_ibfoa_jun_li(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.01 ) #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) #alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) # SO FAR BEST alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 8, 8, 16, 4, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.03) #HARSHA alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.03) alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 2, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03) #alh = SwarmPackagePy.bfoa_swarm1(100, f, -r, r, 30, 100, 5, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100) #alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100) #alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,lamda,0.03) fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist, 'r', label='J-cc') jarlist = alh._get_jarlist() jlist = alh._get_jlist() plt.plot(jlist, 'y', label='J')
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f1_sphere_function, -100, 100, 3, 100, 8, 4, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,10 ) #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f5_griewank_function, -10, 10, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #VERYGOOD alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) r = 32 f = tf.f3_ackley_function #lamda=100 #f = tf.f2_rosenbrock_function #lamda=400 not enough. #ACKLEY #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100) fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist, 'r', label='J-cc') jarlist = alh._get_jarlist() jlist = alh._get_jlist() plt.plot(jlist, 'y', label='J') jblist = alh._get_jblist() plt.plot(jblist, 'g', label='J-best')
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D #alh = SwarmPackagePy.pso(50, tf.easom_function, -10, 10, 2, 20,w=0.5, c1=1, c2=1) #alh = SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped) #alh = SwarmPackagePy.bfo_with_swarm(20, tf.easom_function, -30, 30, 2, 10, 2, 12, 0.2, 1.15, 0.1, 0.2, 0.1, 10) alh = SwarmPackagePy.bfo_with_swarm(4, tf.easom_function, -30, 30, 2, 30, 100, 4, 0.1, 0.25, 0.1, 0.2, 0.1, 10) animation(alh.get_agents(), tf.easom_function, -50, 50) animation3D(alh.get_agents(), tf.easom_function, -50, 50) #SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D #alh = SwarmPackagePy.pso(50, tf.easom_function, -10, 10, 2, 20,w=0.5, c1=1, c2=1) #alh = SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped) #alh = SwarmPackagePy.bfo_with_swarm(20, tf.easom_function, -30, 30, 2, 10, 2, 12, 0.2, 1.15, 0.1, 0.2, 0.1, 10) alh = SwarmPackagePy.bfo_with_env_swarm(50, tf.easom_function, -30, 30, 3, 30, 100, 4, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 0) animation3D(alh.get_agents(), tf.easom_function, -50, 50) animation3D(alh.get_agents(), tf.easom_function, -50, 50) #SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)
#f = tf.f2_rosenbrock_function #lamda=400 not enough. #ACKLEY #alh = SwarmPackagePy.z_ibfoa_jun_li(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.01 ) #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) #alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) # SO FAR BEST alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 8, 8, 16, 4, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.03) #HARSHA alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.03) #alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 2, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,0.03) #alh = SwarmPackagePy.bfoa_swarm1(100, f, -r, r, 30, 100, 5, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100) #alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100) #alh = SwarmPackagePy.z_ibfoa_jun_li(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,lamda,0.03) #BEST alh = SwarmPackagePy.z_bfoa_multipop(100, f, -r, r, 30, 100, 6, 8, 10, 5, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100,seg, 15) #2D alh = SwarmPackagePy.z_bfoa_multipop(100, f, -r, r, 3, 100, 4, 8, 4, 8, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, seg, 15) fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist,'r', label='J-cc') jarlist = alh._get_jarlist() jlist = alh._get_jlist() plt.plot(jlist,'y', label='J') jblist = alh._get_jblist() plt.plot(jblist,'g', label='J-best')
#HARSHA BEST1 DEMO1 Org alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 30, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 400, 0.03, 'adaptive1', 'swarm1', 'false') #GOOD 1 alh = SwarmPackagePy.z_bfoa(50, f, -r, r, 30, 100, 16, 4, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'false') #NOT GOOD alh = SwarmPackagePy.z_bfoa(50, f, -r, r, 30, 100, 16, 4, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm1', 'true') #Different Heuristics for the Reproductions, chem, jcc, jdelta, and weighted_jdelta n = 100 #50 r = 20 lamda = 100 f = tf.gaussian_diff_multimodal_positive dim = 2 #alh = SwarmPackagePy.z_bfoa_extended(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.05, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false','std','jcc') #alh = SwarmPackagePy.z_bfoa_extended(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.05, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm3', 'false','std','jdelta') #alh = SwarmPackagePy.z_bfoa_extended(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.1, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false','none','chem') alh = SwarmPackagePy.z_bfoa_extended(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.1, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false', 'std', 'chem') #TEST CASES ################################################# #7- SUS only model is quite working for the F2 as well - Whaaaaat? """ n =100 #50 r = 1 lamda = 500 #500 is BEST argrep = 'susonly' f = tf.F2_var1 dim =1 alh = SwarmPackagePy.z_bfoa_extended(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.05, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false','susonly') """
from SwarmPackagePy import multiniche_benchmark as mbtf from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #BEST 2 - with Swarm2-WOW - WOOOOOOOOOOWWWW n = 100 #50 r = 19 lamda = 100 f = tf.gaussian_diff_multimodal_positive dim = 2 sigma_share = 0.2 #0.6 NOT WORKING d_min = 0.2 #1 d_max = 3 clust_alpha = 1 alh = SwarmPackagePy.z_bfoa_multiniche_clustering_v2( n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.1, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false', sigma_share, d_min, d_max, clust_alpha) #TEST CASES ###################################################### '''NOT GOOD WITH DIFF 2 n =100 #50 r = 19 lamda = 100 f = tf.gaussian_diff_multimodal_positive dim =2 sigma_share = 0.2 #0.6 NOT WORKING alh = SwarmPackagePy.z_bfoa_multiniche_clustering_v1(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.05, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false', sigma_share) '''
#""" #BEST 2 - with Swarm2-WOW - WOOOOOOOOOOWWWW n = 100 #50 r = 19 lamda = 100 f = tf.gaussian_diff_multimodal4_positive dim = 2 sigma_share = 0.2 #0.6 NOT WORKING d_min = 1 #0.2 #1 d_max = 3 clust_alpha = 2 step_size = 0.1 alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v4( n, f, -r, r, dim, 100, 16, 2, 8, 12, step_size, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'none' '''adaptive1 also''', 'swarm2', 'false', sigma_share, d_min, d_max, clust_alpha) #alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v4_raw_for_debug(n, f, -r, r, dim, 100, 16, 2, 8, 12, step_size, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'none' '''adaptive1 also''', 'swarm2', 'false', sigma_share,d_min, d_max, clust_alpha) #""" #LAST TESTED '''rastrigin Working , Change last Visualize, LAST one is the BEST, This is EXTRA, Only Change is n=100 not 500 n =100 #50 r = 5 #lb =-1 ub=5 lamda = 100 #f = tf.f5_griewank_function f = tf.f4_rastrigin_function_var1 dim =2
list_exec_time = [] list_functions = [(testFunctions.ackley_function, (0.0, 0.0)), (testFunctions.easom_function, (math.pi, math.pi)), (testFunctions.sphere_function, (0.0 , 0.0)), (testFunctions.bohachevsky_function, (0.0 , 0.0)), (testFunctions.sum_squares_function, (0.0 , 0.0))] for l in range(len(list_functions)): # gets the function function = list_functions[l][0] #print("Function: " + ", " + str(function)) #print("Run, Mean Error, Execution Time") avg_error = 0 avg_delta = 0 for i in range(num_runs): start = datetime.datetime.now() alh = SwarmPackagePy.fa(num_agents, function, -10, 10, 2, num_iterations) end = datetime.datetime.now() delta = end - start last_list_pos = alh.get_agents()[-1] # gets the global optima of the function global_optima = list_functions[l][1] error = 0 for j in range(num_agents): last_pos = last_list_pos[j] ind_error = ((last_pos[0] - global_optima[0]) ** 2 + (last_pos[1] - global_optima[1]) ** 2) ** 0.5 error += ind_error error /= num_agents list_error.append(error) list_exec_time.append(delta.microseconds) #print("average error for run " + str(i + 1) + ": " + str(error)) #print("exec time for run " + str(i + 1) + ": " + str(delta,microseconds))
#r = 20 #lamda = 400 #f = tf.F1_var1 #f = tf.F2_var1 n = 100 #50 r = 20 lamda = 1 f = tf.F3_test #tf.F2_var1 #tf.F2_var1 dim = 2 sigma_share = 0.2 #0.6 NOT WORKING alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v2(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.05, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false', sigma_share) """ n =100 #50 r = 20 lamda = 100 f = tf.gaussian_diff_multimodal4_positive dim =2 sigma_share = 0.2 #0.6 NOT WORKING alh = SwarmPackagePy.z_bfoa_multiniche_sharing_v2(n, f, -r, r, dim, 100, 16, 2, 8, 12, 0.05, 0.25, 0.05, 0.2, 0.05, 10, lamda, 0.03, 'adaptive1', 'swarm2', 'false', sigma_share) """ """ n =100 #50 r = 20 lamda = 1 #NOT OWRKING
#NICE WOW #alh = SwarmPackagePy.z_bfoa_general_v1(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm2', 'false', search_type='discrete') #WOW BEST SO FAR - CELLULAR AUTOMATUM #alh = SwarmPackagePy.z_bfoa_general_v1(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'none', 'false', search_type='discrete') #GOOD BUT NOT VERY MUCH. BEST VALUE VARY #alh = SwarmPackagePy.z_bfoa_general_v1(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm1', 'false', search_type='discrete') #alh = SwarmPackagePy.z_bfoa_general_v1(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm2', 'false', search_type='discrete') #alh = SwarmPackagePy.z_bfoa_general_v1_max(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm1', 'false', 'discrete','max') #alh = SwarmPackagePy.z_bfoa_general_v1_max(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'none', 'false', 'discrete','max') alh = SwarmPackagePy.z_bfoa_general_v1_max(100, f, lb, ub, 2, 100, 8, 8, 4, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'adaptive1', 'swarm2', 'false', 'continuous', 'min') #TEST CASES ######################################################################## #DAMN WORSE - Lets change SOme Parametr Nc = 4 ''' n =100 #50 r = 20 lamda = 100 f = tf.gaussian_diff_multimodal_positive dim =2 alh = SwarmPackagePy.z_bfoa(100, f, -r, r, 2, 100, 8, 8, 12, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10, 100, 0.03, 'none', 'swarm1', 'false') '''
# -*- coding: utf-8 -*- """ Created on Mon Nov 27 10:12:26 2017 @author: MichelMacSDD """ import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D alh = SwarmPackagePy.pso(50, tf.easom_function, -10, 10, 2, 20, w=0.5, c1=1, c2=1) animation(alh.get_agents(), tf.easom_function, -10, 10) animation3D(alh.get_agents(), tf.easom_function, -10, 10)
print("1. Three-hump camel function.") print("2. Booth function.") print("3. Beale function.") print("4. Exit") chooseFunction = int(input("Choose: ")) while chooseFunction != 4: if chooseFunction == 1: print("=== Three-hump camel function ===") alh = SwarmPackagePy.pso(50, tf.three_hump_camel_function, -5, 5, 20, 100, w=0.5, c1=1, c2=1) print(alh.get_Gbest()) animation3D(alh.get_agents(), tf.three_hump_camel_function, -5, 5) elif chooseFunction == 2: print("=== Booth function ===") alh = SwarmPackagePy.pso(50, tf.booth_function, -10, 10, 20, 100,
import SwarmPackagePy from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D alh = SwarmPackagePy.abfo1(100, tf.easom_function, -10, 10, 2, 20, 16, 4, 2, 12, 0.1, 0.25, 400) animation(alh.get_agents(), tf.easom_function, -10, 10) animation3D(alh.get_agents(), tf.easom_function, -10, 10) #SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)
from SwarmPackagePy import testFunctions as tf from SwarmPackagePy import animation, animation3D import matplotlib.pyplot as plt #z_ibfoa_jun_li #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f1_sphere_function, -100, 100, 3, 100, 8, 4, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,10 ) #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f5_griewank_function, -10, 10, 30, 100, 16, 4, 2, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,400 ) #VERYGOOD alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) r = 20 f = tf.gaussian_multimodal3_positive #32 #lamda=50 #f = tf.f3_ackley_function #lamda=100 #f = tf.f2_rosenbrock_function #lamda=400 not enough. #ACKLEY #alh = SwarmPackagePy.bfoa_swarm1_dev1_rep(100, tf.f2_rosenbrock_function, -r, r, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) #alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, tf.f3_ackley_function, -32, 32, 30, 100, 24, 8, 8, 12, 0.1, 0.25, 0.1, 0.2, 0.1, 10,100 ) alh = SwarmPackagePy.z_bfoa_swarm1_dev1(100, f, -r, r, 30, 100, 8, 8, 12, 8, 0.1, 0.25, 0.1, 0.2, 0.1, 10,50) fits = alh._get_jfits() plt.plot(fits, 'b', label='J-fit') jcclist = alh._get_jcclist() plt.plot(jcclist,'r', label='J-cc') jarlist = alh._get_jarlist() jlist = alh._get_jlist() plt.plot(jlist,'y', label='J') jblist = alh._get_jblist() plt.plot(jblist,'g', label='J-best')