예제 #1
0
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,
예제 #2
0
# -*- 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)
예제 #3
0
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)